MATLAB Answers

Image segmentation and counting.

15 views (last 30 days)
Xiaoquan on 25 Nov 2014
Answered: Sarah Salvino on 24 May 2019
Dear all, I am a BMEG student. I got a homework to count the cell of leaves by Matlab. The original figure is shown below.
And I used the following script to generate some result (I copied some code from examples).
rgb = imread('original.png'); %load image
rgb2 = rgb2gray(rgb); %change it to gray
rgb2 = imcomplement(rgb2); %invert the color
rgb2 = adapthisteq(rgb2, 'ClipLimit', 0.1); %enhance contract
BWdfill = imfill(im2bw(rgb2), 'holes'); %fill holes
BWnobord = imclearborder(BWdfill, 4); %remove the boundary cells
rgb_perim = bwperim(im2bw(BWnobord)); %find the boundary
overlay1 = imoverlay(rgb2gray(rgb),rgb_perim, [.3 1 .3]); %overlap figure with boundary
bw = BWnobord;
cc = bwconncomp(bw, 8);
graindata = regionprops(cc,'basic');
grain_areas = [graindata.Area];
s = regionprops(BWnobord, {'Centroid'});
hold on
numObj = numel(s) %show the total number of cell
label_num = 0;
for k = 1 : numObj
if (grain_areas(k)> 200) & ( grain_areas(k) < 4000) %set area range
plot(s(k).Centroid(1), s(k).Centroid(2), 'ro'); %label selected ones
label_num = label_num + 1; %count number
hold off
And I got the following figure.
But the two circled regions didn't have a good segmentation. Does anyone have solution for this condition?

Answers (2)

Ashutosh Kumar Upadhyay
Ashutosh Kumar Upadhyay on 10 Dec 2014
the size of those blobs may not fit into threshold range. try the code at with parameters as IsObjectLighter=1; NoOfScales_J=6; KernelBandwidth_h =1; NeighbourhoodDistance_RN = 0; ContrastThreshold_Th = 1; MorphSmoothRad=0; IsGelImage=1; smallRadiusofSpot=1; and apply area filtering operation on "seg" variable.

Sarah Salvino
Sarah Salvino on 24 May 2019
Hi, I was working in a similar project, could you please help me? My email adress is:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!