0% found this document useful (0 votes)
38 views10 pages

DIP Assignment 4

This document is an assignment submission for a digital image processing course. It contains the names and student IDs of 3 students submitting the assignment. The assignment contains code and output for performing various morphological operations, edge detection, image enhancement, and component labeling on images. Tasks include closing, erosion, dilation, local adaptive filtering, connected component analysis, and logical operations.

Uploaded by

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

DIP Assignment 4

This document is an assignment submission for a digital image processing course. It contains the names and student IDs of 3 students submitting the assignment. The assignment contains code and output for performing various morphological operations, edge detection, image enhancement, and component labeling on images. Tasks include closing, erosion, dilation, local adaptive filtering, connected component analysis, and logical operations.

Uploaded by

Saad Ali Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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