0% found this document useful (0 votes)
75 views9 pages

(EE440) Lab1Report Kien Cuong Hung

This document summarizes experiments performed on two images, 3_1.jpg and 3_2.jpg, using three image enhancement techniques: linear stretching, histogram equalization, and histogram matching. For each image and technique, the code is provided and results are described. It is noted that linear stretching has little effect on 3_2.jpg as its histogram already spans the full range, while histogram matching is identified as the best technique overall as it allows controlling the desired histogram shape.

Uploaded by

vophucluan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views9 pages

(EE440) Lab1Report Kien Cuong Hung

This document summarizes experiments performed on two images, 3_1.jpg and 3_2.jpg, using three image enhancement techniques: linear stretching, histogram equalization, and histogram matching. For each image and technique, the code is provided and results are described. It is noted that linear stretching has little effect on 3_2.jpg as its histogram already spans the full range, while histogram matching is identified as the best technique overall as it allows controlling the desired histogram shape.

Uploaded by

vophucluan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

EE440 Lab 1

Report
Names:
- Huynh Nhu Kien
- Ha Xuan Cuong
- Nguyen Phuc Bao Hung
Class: 10ECE

1/ Linear stretching:
Code:
%-----------linear stretching---------im = imread('3_1.jpg'); % Read image
% im=imread('3_2.jpg');
subplot(221);
imshow(im),title('Original Image'); % Display the image
hsv= rgb2hsv(im);
% Convert the image from RGB colormap to HSV colormap
V= hsv(:,:,3);
% Assign the intensity of the HSV image to V
subplot(222),imhist(V),title('Histogram of the Intensity');
V= uint8(255*(V-min(V(:)))/(max(V(:))-min(V(:)))); % Algorithm and scale
% the Intensity from [0 1] to [0 255]
V=double(V)/255; % Rescale the Intensity back to [0 1]
hsv(:,:,3)=V;
% Reassign V into
newIm= hsv2rgb(hsv); % Convert the image back to RGB colormap
subplot(223);
imshow(newIm),title('Stretched Image');
subplot(224),imhist(V),title('Histogram of new Image Intensity');

2/ Histogram Equalization:
Code:
%------------ Histogram equalization--------------im=imread('3_1.jpg');
% im=imread('3_2.jpg');
hsv=rgb2hsv(im); % Convert the image to HSV colormap
V=hsv(:,:,3);
% Assign the Intensity of the image to V
V=uint8(255*V); % Scale the intensity from [0 1] to [0 255]
[nk,x]=imhist(V);
subplot(221);imhist(V),title('Histogram of the intensity');
subplot(222);imshow(im),title('Original Image');
MN=numel(V); % number of elements in V
sk=round(255/MN*(cumsum(nk))); % Calculate the cdf of V
for i=1:MN
for j=1:256
if(V(i)==j)
V(i)=sk(j); % Replace each Intensity value with a new one after
% taking cumulative sum algorithm
break
end
end
end
subplot(223);imhist(V),title('Histogram of new Image Intensity');
V=double(V)/255; % Convert the Intensity back to scale [0 1]
hsv(:,:,3)=V; % Reassign the Intensity to the HSV image
NewIm=hsv2rgb(hsv); % Convert the HSV image to RGB image
subplot(224);imshow(NewIm),title('Equalized Image');

3/ Histogram Matching:

Code:
clc; clear;
%----------------choose an image to enhance-------------------------input=imread('3_1.jpg');
% input=imread('3_2.jpg');
%----------------histogram specification---------------------------hsv=rgb2hsv(input);
V=hsv(:,:,3);
NV=uint8(255*V);
V=uint8(255*V);
[nk,x]=imhist(V);
MN=numel(V);
sk=round(255/MN*(cumsum(nk)));
z=0:1:255;
d=normpdf(z,100,60);
gz=round(255*(cumsum(d)));

% original histogram
% number of values in V
% transformation function sk
% desired histogram
% transformation function G(z)

% r to s
for i=1:MN
for j=1:256
if(V(i)==(j-1))
V(i)=sk(j);
break
end
end
end
% s to z
for i=1:MN
j=1;
if(V(i)<=gz(j))
V(i)=j-1;
else
while(V(i)>gz(j)&&j<256)
j=j+1;
end
if (abs(V(i)-gz(j-1))<abs(V(i)-gz(j)))
% find gz closest to sk
V(i)=j-2;
else V(i)=j-1;
end
end
end
hsv(:,:,3)=double(V)/255;
NewIm=hsv2rgb(hsv);
figure(1);
subplot(311);imhist(NV);title('Original histogram');axis tight;
subplot(312); stem(d*MN); title('Desire histogram');axis tight;
subplot(313); imhist(V); title('New histogram');axis tight;
figure(2);
subplot(211);imshow(input);title('Original image');
subplot(212);imshow(NewIm);title('New image');

Image 3_1.jpg
1/ Linear stretching:

Result:

2/ Histogram equalization:
Result:

3/ Histogram Matching:
Result:

Image 3_2.jpg

1/ Linear stretching:
Result:

2/ Histogram equalization:
Result:

3/ Histogram Matching:

Result:

Comments:

The first method doesnt affect to image 3_2.jpg because the aim of this
method is stretch the histogram range of the image from certain range to
[0 255], and its histogram range is yet belonged to [0 255]
In 3 methods, the third one ( Histogram Matching) is the best enhancement
method ( for both images) because we can control the desired histogram,
then if we choose a suitable histogram, we will get the best result for
enhancement.

You might also like