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
0 个评论
采纳的回答
Image Analyst
2015-4-3
Try this:
[rows, columns, numberOfColorChannels] = size(yourImage);
theClass = class(yourImage);
更多回答(1 个)
tina jain
2015-4-4
5 个评论
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 Center 和 File Exchange 中查找有关 Read, Write, and Modify Image 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!