Thread Subject: Completing Missing Circle Edges

Subject: Completing Missing Circle Edges

From: Lee Borland

Date: 2 Mar, 2009 17:15:03

Message: 1 of 2

Hi all.

I posted here recently asking for advice on horn detection and diameter calculation in relation to SEM red blood cell images (See Here: http://www.mathworks.com/matlabcentral/newsreader/view_thread/244712)

To update, I am currently attempting to calculate diameters of some of the more overlapping cells.

For example:
http://i43.tinypic.com/oprdbq.jpg

I have applied a wavelet transform to this image and my goal is to calculate, for example the diameters of some of the heavily overlapping cells in the centre. I have applied bw = imfill(i,'holes'); to make the issue more apparent.MATLAB has filled what it sees as complete shapes white, to my understanding the remaining cells need to be "closed off"
If cell edges are complete, regionprops can be used.

Is my understanding correct? Can anyone help with completing the edge of an incomplete circle?

Subject: Completing Missing Circle Edges

From: Pete

Date: 6 Mar, 2009 22:56:01

Message: 2 of 2

Hi Lee,

imclose may get you a little nearer - it should close up the circles that are almost complete, but it won't help with the others.

You're right about complete edges and regionprops. If bw is your binary image containing outlines, you can use something like:
bw = imclose(bw, ones(3));
im_lab = bwlabel(~bw);
regionprops(im_lab, [whatever properties you need]);

Note that the background will also be given a label this way, which probably won't be very useful - so you'll need to find and disregard it. An alternative to imfill to see which complete cells have been found is to look at
imshow(label2rgb(im_lab, 'jet', 'w', 'shuffle'));

Sorry I don't have anything ingenious or sophisticated to suggest for the main problem of the circles with big gaps. To get something usable more quickly, you could perhaps allow the user to draw in extra lines to complete the cells. Some rather inglorious code for that might be:
bw = imclose(bw, ones(3));
% Loop until the user double clicks the same place rather than draws a line
while true
 % Show the detected cells
 im_lab = bwlabel(~bw, 4);
 imshow(label2rgb(im_lab, 'jet', 'w', 'shuffle'));
 % Get the end points of a line from the user
 % (should add some check to make sure the line is within the image bounds)
 [x, y] = getline;
 % Check for double click
 if numel(x) == 1
    break;
 end;
 % Only keep the first two points (this is cheating)
 x = x(1:2);
 y = y(1:2);
 % Calculate the line length
 len = ceil(hypot(diff(x), diff(y)));
 % Figure out the linear indices of the pixels in the edge image that need set to 1
 % (doubles length just to be very sure no gaps in the line... inefficiently)
 cols = round(linspace(x(1), x(2), len*2));
 rows = round(linspace(y(1), y(2), len*2));
 inds = sub2ind(size(bw), rows, cols);
 % Update the image
 bw(inds) = true;
end

There are, no doubt, many better ways to achieve that goal. I tested it briefly - while the code isn't great, the initial results seemed ok. It could be very much improved, for example, by allowing the user to add multiple line segments (not just one at a time), relating the line to image pixels more efficiently, and storing the coordinates of manually added line segments to allow for an 'undo' option.

Pete

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com