DIP Assignment 3
DIP Assignment 3
Assignment 3
Submitted by:
Student Name: Syed Saad Ali Shah
Code:
img=getimage(handles.axes1);
ft=fft(img);
img2=getimage(handles.axes2);
ft2=fft(img2);
newft=ft+ft2; %sum of fourier transforms
inverseft=fft2(newft); %inverse of sum of fourier transform
axes(handles.axes1);
imshow(ft);
axes(handles.axes2);
imshow(ft2);
axes(handles.axes3);
imshow(newft);
title('sum of fourier transform');
axes(handles.axes4);
imshow(inverseft);
title('inverse of sum of fourier transform');
Output:
Code:
img=getimage(handles.axes1);
ft=fft(img);
img2=getimage(handles.axes2);
ft2=fft(img2);
newimg=img.*img2;%multiple of two images
newft=ft.*ft2; %multiple of fourier transform of two images
axes(handles.axes1);
imshow(ft);
axes(handles.axes2);
imshow(ft2);
axes(handles.axes3);
imshow(newimg);
title('multiple of two images');
axes(handles.axes4);
imshow(newft);
title('multiple of fourier transform of two images');
Output:
Code:
img=getimage(handles.axes1);
ft=fft(img);
i_ft=fft2(ft);
axes(handles.axes3);
imshow(ft);
title('fourier transform');
axes(handles.axes4);
imshow(i_ft);
title('inverse fourier transform');
Output:
Code:
img=getimage(handles.axes2);
[M N]=size(img);
h=fspecial('prewitt');
v=h';
h_trans=fft2(h);
v_trans=fft2(v);
h_result=real(h_inverse);
v_result=real(v_inverse);
added_sum=h_crop+v_crop;
axes(handles.axes2);
imshow(mat2gray(added_sum));
title('added sum');
axes(handles.axes3);
imshow(mat2gray(h_crop));
title('horizontal crop');
axes(handles.axes4);
imshow(mat2gray(v_crop));
title('vertical crop');
Output:
Code:
img=getimage(handles.axes1);
axes(handles.axes3);
imshow(result1);
title('result1');
axes(handles.axes4);
imshow(result2);
title('result2');
axes(handles.axes2);
imshow(result2);
title('resultant');
Output:
Code:
img=getimage(handles.axes1);
cc1 = bwconncomp(img);
before = cc1.NumObjects;
sel1 = strel('rectangle', [20 20]);
axes(handles.axes3);
imshow(img);
title(num2str(before));
axes(handles.axes4);
imshow(dil);
title(num2str(after));
Output:
Code:
img = getimage(handles.axes2);
axes(handles.axes3); imshow(vertical);
title('Vertical');
axes(handles.axes4); imshow(horizontal);
title('Horizontal');
Output:
Code:
img = imbinarize(mat2gray(getimage(handles.axes1)));
sel = strel('rectangle', [2 12]);
dil = imdilate(img, sel);
cc2 = bwconncomp(dil);
after = cc2.NumObjects;
axes(handles.axes3); imshow(img);
title('Image');
axes(handles.axes4); imshow(dil);
title("No. Words: "+num2str(after));
img = imbinarize(mat2gray(imread("Lines.png")));
Output:
Code:
function myMorphology(img)
bin = imbinarize(img);
% Apply closing
dilated = morph_op(bin, 6, 3, 'dilate');
closed = morph_op(dilated, 4, 4, 'erode');
% Eroded
eroded = morph_op(closed, 4, 4, 'erode');
% Difference
diff = closed - eroded;
imshow(diff);
Output: