You are on page 1of 10

Digital Image Processing

Assignment 4

Submitted by:
Student Name: Syed Saad Ali Shah

Enrolment No.: 01-134-171-075

Student Name: Abdul Hussain

Enrolment No.: 01-134-171-001

Student Name: Mubeen Ahmad

Enrolment No.: 01-134-171-090

Class and Section: BSCS-7A

Submitted to: Dr. Sumaira Kausar

Department of Computer Science


BAHRIA UNIVERSITY, ISLAMABAD
Morphological Operations
Code:
function closing_Callback(hObject, eventdata, handles)

img = getimage(handles.axes1);
img = rgb2gray(img);
img = imbinarize(img);
[H, W] = size(img);
se1 = strel('rectangle', [30 15]);
closed = imclose(img, se1);
cropped = imcrop(closed, [100, 0, W-150, H-50]);
cc = bwconncomp(cropped);

axes(handles.axes2); imshow(closed);
title('M Closed');
axes(handles.axes3); imshow(cropped);
title("Number of objects(cropped): "+cc.NumObjects);

Output:

Task2:
Code:
function erosionedges_Callback(hObject, eventdata, handles)

img = getimage(handles.axes2);
BW = bwperim(img)
axes(handles.axes3); imshow(BW);
title('Erosion Perim Outines');
Output:
Task3:
Code:
img = getimage(handles.axes1);
resized = imresize(img, 2);
sharp = locallapfilt(resized, 0.4, 0.5);
sharp = locallapfilt(sharp, 0.4, 0.5);
se = strel("rectangle", [3 2]);
dilated = imdilate(sharp, se);
sharp2 = locallapfilt(dilated, 0.4, 0.5);

axes(handles.axes2); imshow(sharp);
title('Sharp');
axes(handles.axes3); imshow(dilated);
title("Dilated");
axes(handles.axes4); imshow(sharp2);
title('Enhanced');

Output:

img = getimage(handles.axes1);

resized = imresize(img, 2);

sharp = locallapfilt(resized, 0.4, 0.5);

sharp = locallapfilt(sharp, 0.4, 0.5);


se = strel("rectangle", [3 2]);

dilated = imdilate(sharp, se);

sharp2 = locallapfilt(dilated, 0.4, 0.5);

axes(handles.axes4); imshow(resized);

title('Original');

axes(handles.axes1); imshow(sharp);

title('Sharp');

axes(handles.axes2); imshow(dilated);

title("Dilated");

axes(handles.axes3); imshow(sharp2);

title('Enhanced');
Task4:
Code:
img = getimage(handles.axes1)
gray = rgb2gray(img);
bin = imbinarize(gray);
lbComp = bwconncomp(bin, 8);
L = labelmatrix(lbComp);
[M, N] = size(L);
images = {};
for obj = 1:lbComp.NumObjects
thisObj = L;
for i = 1:M
for j = 1:N
if (L(i, j) ~= obj)
thisObj(i, j) = 0;
else
thisObj(i, j) = obj;
end
end
end
images{obj} = thisObj;
end
banana = images{2} + images{3};
bottom = images{4} + images{5} + images{6} + images{7} + images{8};
top = images{9} + images{10} + images{11};
pineapple = images{12};
for i = 13:20
pineapple = pineapple+images{i};
end
bin_banana = imbinarize(banana);
bin_pineapple = imbinarize(pineapple);
anded = bitand(bin_banana, bin_pineapple);
ored = bitor(bin_banana, bin_pineapple);

axes(handles.axes1); imshow(bin_banana);
title('Bananas');
axes(handles.axes2); imshow(bin_pineapple);
title("Pineapple");
axes(handles.axes3); imshow(anded);
title('Anded');
axes(handles.axes4); imshow(ored);
title('Ored');

Output:

Code:
img = getimage(handles.axes1)
se = strel('disk',2);
afterOpening = imopen(img,se);

axes(handles.axes2); imshow(afterOpening,[]);
title("after opening");
img2 = getimage(handles.axes2)
axes(handles.axes4); imhist(img2)

Output:

You might also like