Assessment Item-1 Report Table of Contents
Abstract …………………………………………………………………………………………………………….. 1 Step-1: Load input image ……………………………………………………………………………………….. 1 Step-2: Conversion of input image to greyscale ……………………………………………………………… 2 Step-3: Noise removal ……………………………………………………………………………………………. 3 Step-4: Enhance the image if necessary ………………………………………………………………………. 4 Step-5: Segment the image into foreground and background ………………………………………………. 4 Step-6: Using Morphological Processing to remove pixels of no interest ………………………………… 5 Step-7: Recognition of starfishes ……………………………………………………………………………….. 6
Abstract
In this project, I use median filter to remove salt and pepper noise, thresholding method to segment the image, morphological processing open operation to remove small objects, and finally use objects area and roundness value to recognize the starfish.
Step-1: Load input image
Use imread to read the image
close all;
% read the image
I = imread(‘AssignmentInput.jpg’);
figure;
imshow(I);
title(‘Step-1: Load input image’);
1
Assessment Item-1 Report
Step-2: Conversion of input image to greyscale
Use rgb2gray to converts the truecolor image to grayscale intensity image
% convert to gray image
I = rgb2gray(I);
figure;
imshow(I);
title(‘Step-2: Greyscale Conversion’);
2
Assessment Item-1 Report
Step-3: Noise removal
The noise in the image is salt and pepper noise, and I use medfilt2 function to do the median filtering using default 3-by-3 neighborhood on the image. Median filter is to set a pixel value as the median value of its neighborhood, so for salt and pepper noise, if a pixel is 1, but its neighbor hood has more 1s than 0s, then it will be set to 0. The resulting image shows that the noise removal is successful.
% do median filter to remove noise
I = medfilt2(I);
figure;
imshow(I);
title(‘Step-3: Noise removal’);
3
Assessment Item-1 Report
Step-4: Enhance the image if necessary
It is not necessary to enhance the image in this step. It doesn’t have much effect on the final starfish extraction result.
Step-5: Segment the image into foreground and background
I use the thresholding method to do the segmentation. Take the pixel whose intensity level is less than 0.9 as foreground and others as background. This method is simple and effective on the image got from step 3. I use im2bw to do the segmentation, and use 1 – I to flip the pixel.
% do segmentation using threshold of 0.9
I = 1 – im2bw (I, 0.9);
figure;
imshow(I);
title(‘Step-5: Image Segmentation’);
4
Assessment Item-1 Report
Step-6: Using Morphological Processing to re- move pixels of no interest
In this step, I use morphology operation open which is erosion followed by dilation to remove pixels which doesn’t belong to starfish. Becasue open can remove small objects which are not starfish.
I = bwmorph(I,’open’,Inf);
figure;
imshow(I);
title(‘Step-6: Morphological Processing’);
5
Assessment Item-1 Report
Step-7: Recognition of starfishes
First, I use bwboundaries to find all the foreground objects.
Then, I use regionprops to compute each object’s area and perimeter value and compute the object’s round- ness value according to formulae metric = 4*pi*area/perimeter^2.
At last, I use the roundness and area value to filter out the starfish. My filter condition is that roundness less than 0.25 and area value between 1000 and 2000. Because under this condition, we can remvoe objects that are too round and objects that are eigher too small or too big to be starfish.
% find all the objects, L is labeled matrix
[B,L] = bwboundaries(I,’noholes’);
% compute the objects’ area and perimeter value.
STATS = regionprops(L, ‘area’, ‘perimeter’);
[numObjects, ~] = size(STATS);
roundness = zeros(size(STATS));
% compute the objects’ roundness value
for i=1:numObjects
roundness(i) = 4*pi*STATS(i).Area / (STATS(i).Perimeter * STATS(i).Perimeter);
end
[rows, cols] = size(I);
6
figure;
imshow(I);
title(‘Step-7: Automatic Recognition’);
Assessment Item-1 Report
% only keep objects whose roundness is less than 0.25 and area value
% between 1000 and 2000.
keep = [];
for i=1:numObjects
if(roundness(i) < 0.25 && STATS(i).Area < 2000 && STATS(i).Area > 1000)
keep = [keep;i];
end end
% set pixel value of kept objects to 1 and others to 0
for i=1:rows
for j=1:cols
if any(keep == L(i, j))
I(i, j) = 1;
else
end end
end
I(i,j)=0;
Published with MATLAB® R2014b
7