Abdulla DIP File
Abdulla DIP File
Abdulla DIP File
UNIVERSITY
Page | 1
INDEX
Page | 2
Program No. 1
Original Image
Code:
MATLAB
clc;
close all;
clear all;
%I rgb2gray(RGB);
I1 = imtophat(I, strel('disk', 10));
figure, imshow(I1);
I2 = imadjust(I1);
figure,imshow(I2);
Page | 3
level = graythresh(I2);
BW = im2bw(I2,level);
figure,imshow(BW);
C=~BW;
figure,imshow(C);
D = ~bwdist(C);
D(C) = -Inf;
L = watershed(D);
Wi=label2rgb(L,'hot','w');
figure,imshow(Wi);
im=I;
Page | 4
Program No. 2
Original Image
Code:
MATLAB
clc;
close all;
clear all;
Page | 5
subplot(3,3,7);
imshow(lapedg,[]); title('Laplacian Filter');
Page | 6
Program No. 3
Approach:
Step 1: Input – Read an image
Step 2: Saving the size of the input image in pixels
Step 3: Get the Fourier Transform of the input_image
Step 4: Assign the Cut-off Frequency
Step 5: Designing filter: Ideal Low Pass Filter
Step 6: Convolution between the Fourier Transformed input image and the filtering mask
Step 7: Take Inverse Fourier Transform of the convoluted image
Step 8: Display the resultant image as output
Implementation in MATLAB:
Page | 7
% N : no of columns (width of the image)
[M, N] = size(input_image);
% Designing filter
u = 0:(M-1);
idx = find(u>M/2);
u(idx) = u(idx)-M;
v = 0:(N-1);
idy = find(v>N/2);
v(idy) = v(idy)-N;
Page | 8
D = sqrt(U.^2+V.^2);
Page | 9
Program No. 4
Program to Implement Edge Detection on an image(Edge detection)
.Approach:
Page | 10
% Gradient approximations
Gx = sum(sum(Mx.*input_image(i:i+2, j:j+2)));
Gy = sum(sum(My.*input_image(i:i+2, j:j+2)));
end
end
Input Image –
Page | 11
Filtered Image:
Advantages:
1. Good performance on detecting vertical and horizontal edges
2. Best operator to detect the orientation of an image
Limitations:
1. The magnitude of coefficient is fixed and cannot be changed
2. Diagonal direction points are not preserved always
Page | 12
Program No. 5
To display the Gray scale images
Approach :
Read the source image file into image matrix
Convert it to grayscale, if it is an RGB image
Iterate over image matrix and count the frequency of every possible value of intensity
plot the counted frequency
count = 0;
for i = 1 : 256
for j = 1 : x
for k = 1 : y
Page | 13
% if image pixel value at location (j, k)
is i-1
% then increment count
if img(j, k) == i-1
count = count + 1;
end
end
end
% update ith position of frequency array
with count
frequency(i) = count;
% reset count
count = 0;
end
n = 0 : 255;
% Display Histogram
stem(n, frequency);
grid on;
ylabel('Number of pixels with such intensity
levels -->');
xlabel('Intensity Levels -->');
title('HISTOGRAM OF THE IMAGE');
Input:
Page | 14
Output:
Page | 15