<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/245713</link>
    <title>MATLAB Central Newsreader - Completing Missing Circle Edges</title>
    <description>Feed for thread: Completing Missing Circle Edges</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 02 Mar 2009 17:15:03 -0500</pubDate>
      <title>Completing Missing Circle Edges</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/245713#631939</link>
      <author>Lee Borland</author>
      <description>Hi all.&lt;br&gt;
&lt;br&gt;
I posted here recently asking for advice on horn detection and diameter calculation in relation to SEM red blood cell images (See Here: &lt;a href=&quot;http://www.mathworks.com/matlabcentral/newsreader/view_thread/244712)&quot;&gt;http://www.mathworks.com/matlabcentral/newsreader/view_thread/244712)&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
To update, I am currently attempting to calculate diameters of some of the more overlapping cells.&lt;br&gt;
&lt;br&gt;
For example:&lt;br&gt;
&lt;a href=&quot;http://i43.tinypic.com/oprdbq.jpg&quot;&gt;http://i43.tinypic.com/oprdbq.jpg&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
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 &quot;closed off&quot;&lt;br&gt;
If cell edges are complete, regionprops can be used.&lt;br&gt;
&lt;br&gt;
Is my understanding correct? Can anyone help with completing the edge of an incomplete circle?</description>
    </item>
    <item>
      <pubDate>Fri, 06 Mar 2009 22:56:01 -0500</pubDate>
      <title>Re: Completing Missing Circle Edges</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/245713#633168</link>
      <author>Pete </author>
      <description>Hi Lee,&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
You're right about complete edges and regionprops.  If bw is your binary image containing outlines, you can use something like:&lt;br&gt;
bw = imclose(bw, ones(3));&lt;br&gt;
im_lab = bwlabel(~bw);&lt;br&gt;
regionprops(im_lab, [whatever properties you need]);&lt;br&gt;
&lt;br&gt;
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&lt;br&gt;
imshow(label2rgb(im_lab, 'jet', 'w', 'shuffle'));&lt;br&gt;
&lt;br&gt;
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:&lt;br&gt;
bw = imclose(bw, ones(3));&lt;br&gt;
% Loop until the user double clicks the same place rather than draws a line&lt;br&gt;
while true&lt;br&gt;
&amp;nbsp;% Show the detected cells&lt;br&gt;
&amp;nbsp;im_lab = bwlabel(~bw, 4);&lt;br&gt;
&amp;nbsp;imshow(label2rgb(im_lab, 'jet', 'w', 'shuffle')); &lt;br&gt;
&amp;nbsp;% Get the end points of a line from the user&lt;br&gt;
&amp;nbsp;% (should add some check to make sure the line is within the image bounds)&lt;br&gt;
&amp;nbsp;[x, y] = getline; &lt;br&gt;
&amp;nbsp;% Check for double click&lt;br&gt;
&amp;nbsp;if numel(x) == 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;&lt;br&gt;
&amp;nbsp;end;&lt;br&gt;
&amp;nbsp;% Only keep the first two points (this is cheating)&lt;br&gt;
&amp;nbsp;x = x(1:2);&lt;br&gt;
&amp;nbsp;y = y(1:2);&lt;br&gt;
&amp;nbsp;% Calculate the line length&lt;br&gt;
&amp;nbsp;len = ceil(hypot(diff(x), diff(y))); &lt;br&gt;
&amp;nbsp;% Figure out the linear indices of the pixels in the edge image that need set to 1&lt;br&gt;
&amp;nbsp;% (doubles length just to be very sure no gaps in the line... inefficiently)&lt;br&gt;
&amp;nbsp;cols = round(linspace(x(1), x(2), len*2));&lt;br&gt;
&amp;nbsp;rows = round(linspace(y(1), y(2), len*2));&lt;br&gt;
&amp;nbsp;inds = sub2ind(size(bw), rows, cols);&lt;br&gt;
&amp;nbsp;% Update the image&lt;br&gt;
&amp;nbsp;bw(inds) = true;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Pete</description>
    </item>
  </channel>
</rss>

