hello sir, I want to know the properties of the image , received after the particular operation in between the execution of the code....what will be the code

1 次查看(过去 30 天)
function DP2D(f,Qtype,B)%f='lena.bmp'
L = 2^B; % # levels in the quantizer
[Height,Width] = size(f);% get the image 'lena256.bmp'
%
% compute optimal predictor coefficients
[alfa,E] = LinearPredict_2D(f);%LinearPredict_2D('lena256.bmp');
%
% Design the uniform quantizer using 5*std dev as the limits
switch Qtype
case 'uniform'
dMin = mean2(E) - 5*std2(E);
dMax = mean2(E) + 5*std2(E);
q = 2*dMax/L; % step size
q2 = q/2;
dR = linspace(dMin,dMax,L+1); % decision intervals
rL = zeros(L,1); % reconstruction levels
for k = 1:L
rL(k) = dR(k)+q2;
end
case 'nonuniform'
[DR,C] = dpcmQuantizer(E,B);% design a B-bit
end
Mu = mean2(f);% mean value of the image
f = f - Mu;% remove mean value
% Implement the 2D DPCM
y = zeros(Height,Width);% array to store reconstructed image
pe = zeros(Height,Width);% array to store differential image
peq = zeros(Height,Width);% array to store quantizeddifferential image
x1 = zeros(Height+1,Width+2); % array to store reconstructed image
y(1,:) = f(1,:) + Mu;
y(:,1) = f(:,1) + Mu;
%
f = padarray(f,[1 2],'symmetric','pre');
% First row, first column no prediction
x1(1,:) = f(1,:);% store previously reconstructed pixels
x1(:,1) = f(:,1);
for r = 2:Height
for c = 2:Width
xhat = alfa(1)*x1(r,c-1) + alfa(2)*x1(r-1,c) + ...
alfa(3)*x1(r-1,c-1)+ alfa(4)*x1(r-1,c+1);
pe(r,c) = f(r,c) - xhat;
switch Qtype
case 'uniform'
for k = 1:L
if pe(r,c)>dR(k) && pe(r,c)<=dR(k+1)
peq(r,c) = rL(k);
elseif pe(r,c)<= dR(1)
peq(r,c) = rL(1);
elseif pe(r,c) > dR(L+1)
peq(r,c) = rL(L);
end
end
case 'nonuniform'
%{
for k = 1:L
if (pe(r,c)>DR(k) && pe(r,c)<=DR(k+1))
peq(r,c) = C(k);
end
end
%}
d1 = abs(pe(r,c)-C(1));
for k = 2:L
d2 = abs(pe(r,c)-C(k));
if d2<d1
d1 = d2;
J = k;
end
end
peq(r,c) = C(J);
end
x1(r,c) = peq(r,c) + xhat;% previously
y(r,c) = x1(r,c) + Mu;% mean added reconstructed pixel
end
end
% Display differential and reconstructed images
figure(4),imshow(pe,[]), title('Differential image');
pause(2);
figure(5);
imshow(y,[]), title('Compressed using DPCM');%
pause(2);
%PSNR = 0;
[peaksnr] = psnr(y,f);
fprintf('\n The Peak-SNR value is %0.4f', peaksnr);
[H,B] = hist(pe(:),512); % Histogram of differential image
H = H/sum(H);
[H1,B1] = hist(peq(:),512); % Histogram of quantized
H1 = H1/sum(H1);
%figure,subplot(2,1,1),plot(B,H,'k','LineWidth',2)
%title('Histogram of unquantized differential image')
%ylabel('relative count')
%subplot(2,1,2),plot(B1,H1,'k','LineWidth',2)
%title('Histogram of quantized differential image')
%xlabel('pixel value'),ylabel('relative count')
% Compute SNR
SigVar = (std2(f(1:Height,1:Width)))^2;
SNR = 10*log10(SigVar/(std2(f(1:Height,1:Width) - y)^2));
sprintf('SNR = %4.2f\n',SNR)
end
I WANT TO KNOW THE WIDTH, HEIGHT AND BIT DEPTH OF THE RECEIVED IMAGE

采纳的回答

Image Analyst
Image Analyst 2015-4-3
Try this:
[rows, columns, numberOfColorChannels] = size(yourImage);
theClass = class(yourImage);

更多回答(1 个)

tina jain
tina jain 2015-4-4
Is there any function to know about the bit depth? Actually I want to calculate the compression ratio. For this I have calculated no of bits in the original image. Now y (as in above code ) is my reconstructed image. For this I want to know the no of bits. I am using no_of_bits=Height * width* bitdepth/ 8 bytes
If there is any other way to calculate the compression ratio then tell me.
  5 个评论
Image Analyst
Image Analyst 2015-4-5
I'm not sure why you say that. It seems to work when I did it.
folder = fileparts(which('peppers.png')); % Determine where demo folder is (works with all versions).
filename = fullfile(folder, 'peppers.png')
fileInfo = dir(filename)
rgbImage = imread(filename);
[rows, columns, numberOfColorChannels] = size(rgbImage)
fileSizeInProgram = rows * columns * numberOfColorChannels
fprintf('File size on disk = %f bytes.\n', fileInfo.bytes);
fprintf('File size in program = %f bytes.\n', fileSizeInProgram);
fprintf('Compression Ratio = %f to 1.\n', fileSizeInProgram / fileInfo.bytes);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Import, Export, and Conversion 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by