0% found this document useful (0 votes)
52 views6 pages

Dip Lab 8 Muhammad Ali 18-Se-16: Example 1

The document contains examples and output of image processing tasks in MATLAB. Example 1 loads an image and displays it along with its histogram. Example 2 applies histogram equalization to the image and displays the equalized image and new histogram. Example 3 plots the transformation function used for histogram equalization. Example 4 performs linear contrast stretching on a single channel of an image. Task 1 applies histogram equalization to an image, displays the original and equalized images along with their histograms. It explains that histogram equalization improves contrast by distributing the grayscale values more evenly. Task 2 loads an image, applies histogram equalization and image adjustment, and displays the original, equalized, and adjusted images along with their histograms. It explains that image adjustment

Uploaded by

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

Dip Lab 8 Muhammad Ali 18-Se-16: Example 1

The document contains examples and output of image processing tasks in MATLAB. Example 1 loads an image and displays it along with its histogram. Example 2 applies histogram equalization to the image and displays the equalized image and new histogram. Example 3 plots the transformation function used for histogram equalization. Example 4 performs linear contrast stretching on a single channel of an image. Task 1 applies histogram equalization to an image, displays the original and equalized images along with their histograms. It explains that histogram equalization improves contrast by distributing the grayscale values more evenly. Task 2 loads an image, applies histogram equalization and image adjustment, and displays the original, equalized, and adjusted images along with their histograms. It explains that image adjustment

Uploaded by

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

DIP LAB 8

MUHAMMAD ALI 18-SE-16


Example 1 :
%Read an image into the workspace.
I = imread('pout.tif');
%Display the image and its histogram.
Figure,subplot(1,2,1),imshow(I)
subplot(1,2,2),imhist(I,64)

Output:

Example 2 :
I = imread('pout.tif');
J = histeq(I);
%Display the contrast-adjusted image and its new histogram.
figure,subplot(1,2,1),imshow(J);
subplot(1,2,2),imhist(J,64)
DIP LAB 8
MUHAMMAD ALI 18-SE-16
Output:

Example 3 :
I = imread('pout.tif');
[J,T] = histeq(I);
figure,plot((0:255)/255,T);

Output:
DIP LAB 8
MUHAMMAD ALI 18-SE-16
Example 4:
itemp = imread('pout.tif');
i = itemp(:,:,1);
rtemp = min(i); % find the min. value of pixels in all the columns(row
vector)
rmin = min(rtemp); % find the min. value of pixel in the image
rtemp = max(i); % find the max. value of pixels in all the columns (row
vector)
rmax = max(rtemp); % find the max. value of pixel in the image
m = 255/(rmax - rmin); % find the slope of line joining point (0,255) to
(rmin,rmax)
c = 255 - m*rmax; % find the intercept of the straight line with the axis
i_new = m*i + c; % transform the image according to new slope
figure,imshow(i); % display original image
figure,imshow(i_new); % display transformed image.

Output:

Task 1:
clear all;
close all;
%% loading image
Orignal_Image=imread('pout.tif');
[r,c]=size(Orignal_Image);

Image=Orignal_Image;
subplot(2,2,1)
imshow(Image)
title('Orignial Image')
subplot(2,2,2)
DIP LAB 8
MUHAMMAD ALI 18-SE-16
imhist(Image)
title('Histogram of Orignial Image')
h=imhist(Image);
pdf=h/(r*c);
%% Summing PDF
for i=1:256
if i==1
I(i)=pdf(i);
else
I(i)=I(i-1)+pdf(i);
end
end
%% Round
s=(255*(I));
s=round(s);
%% Image Creation after Equalization
for k=1:256
for i=1:r
for j=1:c
if Image(i,j)==k-1
Rec(i,j)=s(k);
else
Image(i,j)=Image(i,j);
end
end
end
end
%% Finall Image
subplot(2,2,3)
imshow(uint8(Rec))
title('Image after Histogram Equalization')
subplot(2,2,4)
imhist(uint8(Rec))
title('Histogram after Histogram Equalization')
DIP LAB 8
MUHAMMAD ALI 18-SE-16
Output:

Explaination:
The process evenly distributes the grey scale of the image and improves the contrast by
increasing the amount of light and dark shades of grey that exist on the ends of the grey scale
range. This also sharpens the image.

Task 2 :
clear;
close all;
image= imread('cameraman.tif');
title('original image')
subplot(3,2,1),imshow(image);
title('original histogram')
subplot(3,2,2),imhist(image);
equalized_image = histeq(image);
adjusted_image = imadjust(image);
title('histogram equalized image')
subplot(3,2,3),imshow(equalized_image);
title('equalized image histogram')
subplot(3,2,4),imhist(equalized_image);
title('adjusted image')
subplot(3,2,5),imshow(adjusted_image);
title('adjusted histogram')
subplot(3,2,6),imhist(adjusted_image);
DIP LAB 8
MUHAMMAD ALI 18-SE-16
Output:

Explanation:
The imadjust function is more effective than the histeq function in improving the contrast of an
image the output above shows that the imadjust image has a more smooth and yet a dispersed
graph as compared to the original image but histeq disperses the gray scale graph all over the
gray scale range which gives out a very weird output image.

You might also like