IIProblem 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

IIProblem 1: (Histogram matching):Take two images (and) by using your cell phone, load12them into

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 = [

'The resolution of original image is '

, num2str(m1),

'*'

num2str(n1)];

disp(Res1);

%store modified image

New = I1;

% Reference image

I2 = imread(

'landscape.jpg'

);
I2 = rgb2gray(I2);

[m2 n2]=size(I2);

Res2 = [

'The resolution of reference image is '

, num2str(m2),

'*'

num2str(n2)];

disp(Res2);

%Histogram with Specified Normalization of Original image

h1 = histogram(I1(:,:), 256,

'Normalization'

'probability'

);

pi1 = h1.Values;

%original intensity on histogram

%Histogram with Specified Normalization of Reference image

h2 = histogram(I2(:,:), 256,

'Normalization'

'probability'

);

pi2 = h2.Values;

%reference intensity on histogram


close;

% Compute Original Cumulative Distribution

Pi1 = zeros(1,256);

% store Original Cumulative Distribution

Pi1(1,1) = pi1(1,1);

for

k = 2:256

Pi1(1,k) = Pi1(1,k-1) + pi1(1,k);

end

% Compute Reference Cumulative Distribution

Pi2 = zeros(1,256);

% store Reference Cumulative Distribution

Pi2(1,1) = pi2(1,1);

for

k = 2:256

Pi2(1,k) = Pi2(1,k-1) + pi2(1,k);

end

%pixel mapping table


fhs = zeros(1,256);

for

a = 1:256

j = 256;

fhs(1,a) = j;

while

(j>0)

j = j-1;

if

(j>0 && Pi1(1,a) <= Pi2(1,j))

fhs(1,a) = j;

else

break

end

end

end

% Convert each pixel of the original image

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'

);

subplot(2,3,4), histogram(I1(:,:), 256);

title(

'Original histogram'

);

subplot(2,3,5), histogram(I2(:,:), 256);

title(

'Reference histogram'

);

subplot(2,3,6), histogram(New(:,:), 256);

title(

'Modified histogram'

);

You might also like