Professional Documents
Culture Documents
IIProblem 1
IIProblem 1
IIProblem 1
matlab, and covert them to grayscale.1.1 Check the resolution of the grayscale images.1.2 Use one of
these grayscale images as a reference image, and modify the other one using thehistogram matching
technique (see page 17 of Lecture 3). Display the two images, their histograms, andthe modified image,
together with the modified histogram.
Source code:
clc;
clear;
% Original image
I1 = imread(
'flower1.jpg'
);
I1 = rgb2gray(I1);
[m1 n1]=size(I1);
Res1 = [
, num2str(m1),
'*'
num2str(n1)];
disp(Res1);
New = I1;
% Reference image
I2 = imread(
'landscape.jpg'
);
I2 = rgb2gray(I2);
[m2 n2]=size(I2);
Res2 = [
, num2str(m2),
'*'
num2str(n2)];
disp(Res2);
h1 = histogram(I1(:,:), 256,
'Normalization'
'probability'
);
pi1 = h1.Values;
h2 = histogram(I2(:,:), 256,
'Normalization'
'probability'
);
pi2 = h2.Values;
Pi1 = zeros(1,256);
Pi1(1,1) = pi1(1,1);
for
k = 2:256
end
Pi2 = zeros(1,256);
Pi2(1,1) = pi2(1,1);
for
k = 2:256
end
for
a = 1:256
j = 256;
fhs(1,a) = j;
while
(j>0)
j = j-1;
if
fhs(1,a) = j;
else
break
end
end
end
for
x = 1:m1
for
y = 1:n1
Num = I1(x,y) + 1;
New(x,y) = fhs(1,Num) - 1;
end
end
figure, subplot(2,3,1), imshow(I1);
title(
'Original image'
);
subplot(2,3,2), imshow(I2);
title(
'Reference image'
);
subplot(2,3,3), imshow(New);
title(
'Modified image'
);
title(
'Original histogram'
);
title(
'Reference histogram'
);
title(
'Modified histogram'
);