Assignment 2

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

Assignment 2 (20%)

CSC566
Student Name: MUHAMMAD ZAKWAN ARIF BIN MUHAMMAD TAJUDDIN
Student Id: 2021106387
Group: M3CS2306A
Semester: PART 6
Submission Date 15th December 2023, Friday
Task 2.1
Morphological Given images as illustrated in Figure 1 and Figure 2.
operation

(10 marks)

Write a MATLAB program to:

a) Construct an image according to Figure 1.


b) Construct a Structuring Element (SE) as in Figure 2, and named
it SE.
c) Perform dilation on Figure 1 using SE
d) Perform erosion on Figure 1 using SE
e) Perform opening on Figure 1 using SE
f) Perform closing on Figure 1 using SE

Task 2.2 Write a MATLAB program to:


Segmentation
a) Extract the gradient parts from the input image.
(10 marks) b) Provide a reason for the selected technique and write a
conclusion based on the output obtained. The input image is
Q4_2

Task 2.3 Write a MATLAB program to:


Segmentation
a) Extract the rice objects from the input image.
(10 marks) b) Provide a reason for the selected technique and write a
conclusion based on the output obtained. The input image is
Q4_3

Task 2.4 Write a MATLAB program to:


Segmentation
a) Separate the two types of blobs in the input image.
(10 marks) b) Provide a reason for the selected technique and write a
conclusion based on the output obtained. The input image is

CSC566/ Image Processing


Faculty of Computer and Mathematical Sciences,
Universiti Teknologi MARA Cawangan Melaka Kampus Jasin
Q4_4

ANSWER
TASK 2.1
Item Output Image Source code/ fragment code

Dilation >> image1 = [


0 0 0 0 0 0 0;
0 0 0 1 0 0 0;
0 0 1 1 1 0 0;
0 1 1 1 1 1 0;
0 0 1 1 1 0 0;
0 0 0 1 0 0 0;
0000000
];
>> SE = [
0 1 0;
1 1 1;
010
];
>> dilatedImage =
imdilate(image1, SE);
figure;
imshow(dilatedImage);
title('Dilated Image');
Erosion >> erodedImage =
imerode(image1, SE);
>> figure;
>> imshow(erodedImage);
>> imshow(erodedImage);
>> title('Eroded Image');

Opening >> openedImage =


imopen(image1, SE);
>> figure;
>> imshow(openedImage);
>> title('Opened Image');

Closing >> closedImage = imclose(image1,


SE);
>>figure;
>>imshow(closedImage);
>>title('Closed Image');

Conclusion from Morphological operations, such as dilation and erosion, are essential in image

CSC566/ Image Processing


Faculty of Computer and Mathematical Sciences,
Universiti Teknologi MARA Cawangan Melaka Kampus Jasin
the morphological processing. Dilation makes objects larger for better visibility, while erosion
operation reduces noise by shrinking object boundaries. Opening removes small
structures, and closing fills gaps. These operations are vital for tasks like object
recognition. Picking the right parameters is key for success. In a nutshell,
morphological operations enhance images and simplify analysis.
ANSWER
TASK 2.2
Input
Image

Output
Image

Source >> otak = imread('Q4_2.tif');


Code >> imshow(otak)
>> [Gmag, Gdir] = imgradient(otak, 'prewitt');
>> imshowpair(Gmag, Gdir, 'montage');
>> title('Gradient Magnitude (left) and Direction (right)');
Justificatio Extract the gradient parts by calculating gradient magnitude and gradient direction
n of the using the prewitt gradient operator because it will compute an approximation of the
selected gradient of the image intensity function. Conclusion, the input of the image becomes
method & more clear with the details of the image in gdir(right) and gmag(left).
Conclusion

CSC566/ Image Processing


Faculty of Computer and Mathematical Sciences,
Universiti Teknologi MARA Cawangan Melaka Kampus Jasin
ANSWER
TASK 2.3
Input Image

Output Image

Source Code I1 = imread('Q4_3.tif');


BW = imbinarize(I1,'adaptive');
imshow(BW);
Justification of the Extract the rice image by creating the binary image from the input image
selected method & using a locally adaptive thresholding method because it will select an
Conclusion individual threshold for each pixel based on the range of intensity values
in its local neighborhood. Conclusion, the output of the rice image
becomes clear and turn to black and white.
ANSWER
TASK 2.4
Input Image

CSC566/ Image Processing


Faculty of Computer and Mathematical Sciences,
Universiti Teknologi MARA Cawangan Melaka Kampus Jasin
Output Image

Source Code >> i = imread('Q4_4.tif');


>> binaryImage = ~imbinarize(i);
>> binaryImage = bwareaopen (binaryImage, 200);
>> subplot(2, 3, 1);
>> imshow(binaryImage);
>> title('Mask Image', 'Interpreter', 'None');
>> props = regionprops(binaryImage, 'Centroid', 'Area');
>> xy = vertcat(props.Centroid)

xy =

21.1508 10.4221
12.2393 80.9709
5.4955 184.8318
7.1667 334.9634
17.6782 406.9789
7.1829 470.9593
19.2874 587.4686
23.9588 250.9849
42.0399 528.0530
49.0371 339.0302
56.0440 119.9855
62.9657 209.0596
65.0179 478.0165
87.0398 32.0247
92.0603 267.0480
96.0878 595.9257
101.9144 410.0836
113.0454 170.0165
114.0075 527.9767
118.0628 96.9508
128.9815 327.9725
149.9684 446.0041
151.0124 571.9931
164.0116 255.9360
171.9685 165.9747
174.0124 63.9595
174.0620 5.9137
191.9759 387.0454
194.9876 513.0880
210.9966 451.9870

CSC566/ Image Processing


Faculty of Computer and Mathematical Sciences,
Universiti Teknologi MARA Cawangan Melaka Kampus Jasin
218.9822 106.0007
220.0543 306.9801
226.0240 176.9718
234.0233 559.0164
240.9367 410.0282
242.0062 23.9848
241.9924 236.0385
270.0082 470.0055
273.0497 79.0228
276.0274 339.9280
282.0336 145.0075
285.0582 590.6650
313.9637 525.9542
313.9889 212.0232
299.9807 291.9904
312.9636 35.9938
327.9985 408.0171
344.9626 112.9871
367.0227 329.0197
375.9661 580.4443
391.0630 14.9044
394.9934 496.0606
419.0346 241.9849
430.0402 381.9651
434.0295 75.0313
452.0033 155.9909
459.0147 556.0341
478.0260 305.0192
485.9722 472.9932
497.9508 5.0181
513.0388 69.0232
529.0280 392.0050
531.0174 190.0010
553.9601 272.0126
553.0391 586.1568
574.5797 124.9883
575.7310 515.9906
576.5914 25.4825
588.3305 367.9346

>> allAreas = [props.Area];


>> [labeledImage, numblobs] = bwlabel(binaryImage);
>> largeIndexes = find(allAreas >=2500);
>> smallIndexes = find(allAreas <2500);
>> subplot(2,3,2);
>> imshow(smallBlobs);
>> smallBlobs = ismember(labeledImage, smallIndexes);
>> imshow(smallBlobs);
>> title('Large Blobs', 'Interpreter', 'None');
>> title('Small Blobs', 'Interpreter', 'None');
>> largeBlobs = ismember(labeledImage, largeIndexes);
CSC566/ Image Processing
Faculty of Computer and Mathematical Sciences,
Universiti Teknologi MARA Cawangan Melaka Kampus Jasin
>> subplot(2,3,3);
>> imshow(largeBlobs);
>> title('Large Blobs', 'Interpreter', 'None');
Justification of the Separate the two types of blobs in input image using regionprops method
selected method & properties Area and Centroid to get blobs because it will give the actual
Conclusion number of pixels in the region, returned as a scalar and center of mass of
the region. CSC566/November2022 UiTM Cawangan Melaka Kampus
Jasin Extract the small blobs and larger blobs using ismember(A,B)
because conjunction with regionprops for selecting regions based on
certain criteria. Conclusion, the output of the image is smallBlobs and
largeBlobs and the regionprops method is useful to get blobs.

CSC566/ Image Processing


Faculty of Computer and Mathematical Sciences,
Universiti Teknologi MARA Cawangan Melaka Kampus Jasin

You might also like