Separating overlapping edges in an image to get an accurate count

조회 수: 13 (최근 30일)
I am trying to count the big cells in the sample image below.
I was able to reach a point where I was able to delete most of the smaller cells and highlight the big cells as seen below.
However, when I count the objects (using bwlabel and bweuler) it's giving me 6. It is probably because of the overlapping edges of the objects on the leftmost side?
How can I separate these overlaps so I can get an accurate count of 7?
Thank you!

채택된 답변

Arturo Jr. Ongkeko
Arturo Jr. Ongkeko 2021년 5월 4일
I was able to figure it out after some time. Here's the code.
%convert image to black and white
%background will be black and object will be white
%use imfill function to fill the holes in the object
%remove small objects containing fewer than 1000 pixels in the binary image
%using bwareaopen
%use bwmorph erode function to further enhance the objects
%conduct another removal of small objects containing fewer than 500 pixels
%in a binary image
%use the bwlabel function to count the objects
[labeledImage,numberofObject]=bwlabel(img5); %count: 7

추가 답변 (1개)

DGM 2021년 5월 3일
This works, but I had trouble trying to get watershed() to work without a little tweaking.
inpict = im2double(imread('cells.jpg'));
% try to extract the more bluish purple part
tol = [0.15 0.2]; % box width
clim = 0.615+[-1 1]*tol(1); % selected color point in C,H
hlim = 0.863+[-1 1]*tol(2);
cmap = mono(inpict,'clch');
hmap = mono(inpict,'hlch');
interior = cmap>clim(1) & cmap<clim(2) & hmap>hlim(1) & hmap<hlim(2);
% this is similar to bwareaopen(), but it does opening and/or closing
interior = despeckle(interior,20);
d = bwdist(~interior);
d(d<(max(d(:))/2)) = 0; % had to give watershed a little help
L = watershed(~d);
L(~interior) = 0; % this is the label array
max(L) % this is the number of labeled objects
This uses MIMT tools just because I'm lazy and can't be bothered to do it all in base/IPT tools
  댓글 수: 2
Arturo Jr. Ongkeko
Arturo Jr. Ongkeko 2021년 5월 4일
Thanks, DGM! Appreciate this! I am graduate student though and we are expected to use the IPT. Also we were not taught how to use image manipulation toolbox yet. I will defintely try your appoach for sure in the future. Thanks again very much!
DGM 2021년 5월 4일
Well it's not like MIMT is a thing anyone should be taught. It's good you solved it though.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by