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

Task#01:

Implement histogram equalization function in matlab by using your own logic without using
histeq of matlab.

Solution:

Code:

close all;
clc;
gimg=imread('C:\Users\user\Desktop\MatlabImages\cameram
an.tif');
figure,imshow(gimg);
figure, histogram(gimg);
I = gimg;
[row,col] = size(I);
blank = uint8(zeros(row,col));
n = row*col;
freq = zeros(256,1);
pdf = zeros(256,1);
cdf = zeros(256,1);
out = zeros(256,1);
cum = zeros(256,1);
for i = 1:row
for j = 1:col
value = I(i,j);
freq(value+1) = freq(value+1)+1;
pdf(value+1) = freq(value+1)/n;
end
end
sum = 0;
L = 255;

for i = 1:size(pdf)
sum = sum + freq(i);
cum(i) = sum;
cdf(i) = cum(i)/n;
out(i) = round(cdf(i)*L);
end

for i = 1:row
for j = 1:col
blank(i,j) = out(I(i,j)+1);
end
end
figure,imshow(blank);
title('Original Image Histogram');
figure, histogram(blank);
title('Equalized Histogram');
Output:
Task#02:

For edge detectors/ first order derivatives, you can use matlab build-in functions but you
should be able to elobrate the differences between the outputs of Canny,Prewitt, Sobel,
Roberts.

Solution:

Code:

clear all;
close all;
I =
imread('C:\Users\user\Desktop\MatlabImages\cameraman.ti
f');
imshow(I)
BW1 = edge(I,'sobel');
BW2 = edge(I,'canny');
BW3 = edge(I,'prewitt');
BW4 = edge(I,'roberts');
figure;
imshowpair(BW1,BW2,'montage')
title('Sobel Filter
Canny Filter');
figure;
imshowpair(BW3,BW4,'montage')
title('prewitt Filter
roberts Filter');
Output:

You might also like