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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Image Analyst
le 3 Avr 2015
Try this:
[rows, columns, numberOfColorChannels] = size(yourImage);
theClass = class(yourImage);
Plus de réponses (1)
tina jain
le 4 Avr 2015
5 commentaires
Image Analyst
le 5 Avr 2015
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);
Voir également
Catégories
En savoir plus sur Import, Export, and Conversion dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!