<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016</link>
    <title>MATLAB Central Newsreader - Need algorithm help: molecule length from an image</title>
    <description>Feed for thread: Need algorithm help: molecule length from an image</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The 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>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 15 May 2008 23:27:01 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#432391</link>
      <author>Ken Campbell</author>
      <description>&amp;lt;SNIP&amp;gt;&lt;br&gt;
&lt;br&gt;
&amp;gt; &amp;gt; Adrian,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; This is very roughly coded but it gives 'an' answer. &lt;br&gt;
You &lt;br&gt;
&amp;gt; &amp;gt; might find it  helpful.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Ken&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; % Read in image and compress to 2D&lt;br&gt;
&amp;gt; &amp;gt; ifs='c:\temp\mol.png';&lt;br&gt;
&amp;gt; &amp;gt; im=imread(ifs);&lt;br&gt;
&amp;gt; &amp;gt; im=sum(im,3);&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; % Show original image&lt;br&gt;
&amp;gt; &amp;gt; figure(1);&lt;br&gt;
&amp;gt; &amp;gt; imagesc(im);&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; % Blur and display&lt;br&gt;
&amp;gt; &amp;gt; filt=fspecial('disk',2);&lt;br&gt;
&amp;gt; &amp;gt; blurred_im=imfilter(im,filt,'replicate');&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; figure(2);&lt;br&gt;
&amp;gt; &amp;gt; imagesc(blurred_im);&lt;br&gt;
&amp;gt; &amp;gt; colorbar;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; % Threshold the blurred version&lt;br&gt;
&amp;gt; &amp;gt; threshold_im=zeros(size(im));&lt;br&gt;
&amp;gt; &amp;gt; threshold_im(blurred_im&amp;gt;230)=1;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; figure(3);&lt;br&gt;
&amp;gt; &amp;gt; imagesc(threshold_im);&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; % And keep only the largest 'island' which is the &lt;br&gt;
molecule&lt;br&gt;
&amp;gt; &amp;gt; molecule_im=bwareaopen(threshold_im,600);&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; figure(4);&lt;br&gt;
&amp;gt; &amp;gt; clf;&lt;br&gt;
&amp;gt; &amp;gt; imagesc(molecule_im);&lt;br&gt;
&amp;gt; &amp;gt; hold on;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; % Now get the perimeter&lt;br&gt;
&amp;gt; &amp;gt; mol_properties=regionprops(bwlabel(molecule_im), ...&lt;br&gt;
&amp;gt; &amp;gt;     'perimeter');&lt;br&gt;
&amp;gt; &amp;gt; molecule_length=(mol_properties.Perimeter)/2&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; % And draw it to make sure we have the right thing&lt;br&gt;
&amp;gt; &amp;gt; [p,l]=bwboundaries(molecule_im,4,'noholes');&lt;br&gt;
&amp;gt; &amp;gt; boundary=p{1};&lt;br&gt;
&amp;gt; &amp;gt; plot(boundary(:,2),boundary(:,1),'y');&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Ken,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is there anyway to modify your code to outline more than &lt;br&gt;
one&lt;br&gt;
&amp;gt; molecule? It works great for one molecule, but when I &lt;br&gt;
start&lt;br&gt;
&amp;gt; looking at more than one, the program breaks. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm planning on making a GUI for the program so the user &lt;br&gt;
can&lt;br&gt;
&amp;gt; change the thresholds as needed for an image. After trying&lt;br&gt;
&amp;gt; out your algorithm with various DNA images I have, the&lt;br&gt;
&amp;gt; shading is different between each one (because of the&lt;br&gt;
&amp;gt; inconsistent heavy-metal shadowing, I assume). &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; Adrian &lt;br&gt;
&lt;br&gt;
You might be able to get round the inconsistent shadowing &lt;br&gt;
by doing some background correction. Look at imtophat &lt;br&gt;
and/or imbothat.&lt;br&gt;
&lt;br&gt;
Getting the code to identify lots of molecules at the same &lt;br&gt;
time is too complicated for the quick code I posted (your &lt;br&gt;
original image only had one molecule after all), but the &lt;br&gt;
general idea is the same. (1) Make the molecules stand out &lt;br&gt;
by some blurring/background correction, (2) set the minimum &lt;br&gt;
size of the molecule you want to analyze with the second &lt;br&gt;
parameter to bwareaopen and (3) analyze the perimeters. You &lt;br&gt;
might want to correct the 4/8 connected ness problem my &lt;br&gt;
original code had.&lt;br&gt;
&lt;br&gt;
I'm a bit too busy to do the whole thing for you :-) but it &lt;br&gt;
shouldn't be too hard. Writing the GUI to do it &lt;br&gt;
interactively will probably take you longer (it would &lt;br&gt;
certainly take me longer) than getting the image-processing &lt;br&gt;
part of the code to work once you understand the algorithm &lt;br&gt;
and the underlying Matlab commands.&lt;br&gt;
&lt;br&gt;
Ken&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 16:27:02 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#432279</link>
      <author>Adrian </author>
      <description>"Ken Campbell" &amp;lt;campbeks@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g0d7jc$mtc$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in &lt;br&gt;
&amp;gt; message &amp;lt;g0crs0$6al$1@canopus.cc.umanitoba.ca&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; In article &amp;lt;g0couj$np$1@fred.mathworks.com&amp;gt;, Adrian  &lt;br&gt;
&amp;gt; &amp;lt;ajr@med.unc.edu&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;4) Scan the image from left to right and then "walk" &lt;br&gt;
&amp;gt; along&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;areas that are labeled as "1". If the program finds a &lt;br&gt;
&amp;gt; pixel&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;that is labeled "1", look toward the 8 surrounding &lt;br&gt;
&amp;gt; pixels to&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;find if there is another pixel labeled "1". If so, &lt;br&gt;
&amp;gt; continue&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;to look for pixels labeled "1" (e.g., keep "walking" &lt;br&gt;
&amp;gt; along&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;the molecule), and if possible, continue "walking" in the&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;same direction as previously (to prevent the "walker" &lt;br&gt;
&amp;gt; from&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;going back to where it came from). Then, after walking &lt;br&gt;
&amp;gt; along&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;the molecule, label all of the points it walked on &lt;br&gt;
&amp;gt; as "0" so&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;the scanner won't walk there again. &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;5) Output the length measurement as pixel and convert to &lt;br&gt;
&amp;gt; nm&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;by looking at the scale.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Suppose you have&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 1011&lt;br&gt;
&amp;gt; &amp;gt; 0100&lt;br&gt;
&amp;gt; &amp;gt; 0010&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; And you start at the top-left corner. You walk left to &lt;br&gt;
&amp;gt; right so you&lt;br&gt;
&amp;gt; &amp;gt; encounter the top-left 1. Presumably you increment your &lt;br&gt;
&amp;gt; count to 1.&lt;br&gt;
&amp;gt; &amp;gt; You examine the surrounding pixels and find&lt;br&gt;
&amp;gt; &amp;gt; the 1 diagonally down and right. You try to continue left &lt;br&gt;
&amp;gt; to right, but&lt;br&gt;
&amp;gt; &amp;gt; there is no 1 there so you take the path that is open by &lt;br&gt;
&amp;gt; going diagonally&lt;br&gt;
&amp;gt; &amp;gt; down and right. However, as you were not able to continue &lt;br&gt;
&amp;gt; in the same&lt;br&gt;
&amp;gt; &amp;gt; direction as you had been going, you label the points you &lt;br&gt;
&amp;gt; walked in&lt;br&gt;
&amp;gt; &amp;gt; that stretch with a 0 so the scanner won't walk there &lt;br&gt;
&amp;gt; again, leading to&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 0011&lt;br&gt;
&amp;gt; &amp;gt; 0100&lt;br&gt;
&amp;gt; &amp;gt; 0010&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; You are at the second pixel, presumably you increment &lt;br&gt;
&amp;gt; your count to 2.&lt;br&gt;
&amp;gt; &amp;gt; Now you are headed diagonally down and right. You examine &lt;br&gt;
&amp;gt; the&lt;br&gt;
&amp;gt; &amp;gt; surrounding pixels and find the 1 diagonally up and right &lt;br&gt;
&amp;gt; and&lt;br&gt;
&amp;gt; &amp;gt; the 1 diagonally down and right. As per your algorithm, &lt;br&gt;
&amp;gt; you prefer&lt;br&gt;
&amp;gt; &amp;gt; to keep going in the same direction, so you take the &lt;br&gt;
&amp;gt; diagonal&lt;br&gt;
&amp;gt; &amp;gt; down and right. As you -were- able to continue in the &lt;br&gt;
&amp;gt; same direction,&lt;br&gt;
&amp;gt; &amp;gt; you are on a run and so do -not- mark the pixel you came &lt;br&gt;
&amp;gt; from with a 0.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; You are at the third pixel, presumably you increment your &lt;br&gt;
&amp;gt; count to 3.&lt;br&gt;
&amp;gt; &amp;gt; You look around from that bottom pixel and find the only &lt;br&gt;
&amp;gt; path open&lt;br&gt;
&amp;gt; &amp;gt; to be the one up and left. However, as you were not able &lt;br&gt;
&amp;gt; to continue&lt;br&gt;
&amp;gt; &amp;gt; in the same direction as you had been going, you label &lt;br&gt;
&amp;gt; the points&lt;br&gt;
&amp;gt; &amp;gt; you walked in the run with a 0 won't walk there again, &lt;br&gt;
&amp;gt; leading to&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 0011&lt;br&gt;
&amp;gt; &amp;gt; 0000&lt;br&gt;
&amp;gt; &amp;gt; 0000&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; There is now an ambiguity in your algorithm: you had an &lt;br&gt;
&amp;gt; available&lt;br&gt;
&amp;gt; &amp;gt; path up-left a moment ago, but that pixel is now 0'd, and &lt;br&gt;
&amp;gt; there&lt;br&gt;
&amp;gt; &amp;gt; are now no pixels left in the neighbourhood that are non-&lt;br&gt;
&amp;gt; 0. Do you&lt;br&gt;
&amp;gt; &amp;gt; stop at this point with a pixel count of 3? My &lt;br&gt;
&amp;gt; interpretation of&lt;br&gt;
&amp;gt; &amp;gt; your algorithm is that you do -not- stop, because your &lt;br&gt;
&amp;gt; instruction&lt;br&gt;
&amp;gt; &amp;gt; was to do the search before the 0'ing.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; So you are now back at 2nd row 2nd column. Your algorithm &lt;br&gt;
&amp;gt; didn't&lt;br&gt;
&amp;gt; &amp;gt; say anything about not counting on backtracks, so &lt;br&gt;
&amp;gt; presumably you&lt;br&gt;
&amp;gt; &amp;gt; increment the count to 4. You look around and find the &lt;br&gt;
&amp;gt; open path&lt;br&gt;
&amp;gt; &amp;gt; to the up-right. That's a change of direction, so you 0 &lt;br&gt;
&amp;gt; out the pixels&lt;br&gt;
&amp;gt; &amp;gt; you had in that run, which makes no change because they &lt;br&gt;
&amp;gt; are already 0.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; You are now at the 1st row 3rd column, trying to head up &lt;br&gt;
&amp;gt; and right.&lt;br&gt;
&amp;gt; &amp;gt; Presumably you increment your counter to 5. You look &lt;br&gt;
&amp;gt; around and&lt;br&gt;
&amp;gt; &amp;gt; find the open path to the right. That's a change of &lt;br&gt;
&amp;gt; direction&lt;br&gt;
&amp;gt; &amp;gt; so you 0 out the pixels you had in that run, which makes &lt;br&gt;
&amp;gt; the matrix&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 0001&lt;br&gt;
&amp;gt; &amp;gt; 0000&lt;br&gt;
&amp;gt; &amp;gt; 0000&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; You are now at the 1st row 4th column, trying to head &lt;br&gt;
&amp;gt; right.&lt;br&gt;
&amp;gt; &amp;gt; Presumably you increment your counter to 6. You look &lt;br&gt;
&amp;gt; around and find&lt;br&gt;
&amp;gt; &amp;gt; no open paths. Presumably you stop there.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Your recorded molecule length is now 6, but the longest &lt;br&gt;
&amp;gt; connected&lt;br&gt;
&amp;gt; &amp;gt; chain was 4 -- (1,1) -&amp;gt; (2,2) -&amp;gt; (1,3) -&amp;gt; (1,4), so &lt;br&gt;
&amp;gt; arguably the&lt;br&gt;
&amp;gt; &amp;gt; molecule length is 4 instead. Or, since there were two &lt;br&gt;
&amp;gt; diagonal&lt;br&gt;
&amp;gt; &amp;gt; moves and then 1 lateral move, 2*sqrt(2)+1, which is &lt;br&gt;
&amp;gt; about 3.8.&lt;br&gt;
&amp;gt; &amp;gt; Add 1 if you are counting from the edges instead of from &lt;br&gt;
&amp;gt; the centers.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Now, suppose you had started with&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 101111&lt;br&gt;
&amp;gt; &amp;gt; 010000&lt;br&gt;
&amp;gt; &amp;gt; 001000&lt;br&gt;
&amp;gt; &amp;gt; 000100&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; then when you are examining (2,2) after coming from (1,1),&lt;br&gt;
&amp;gt; &amp;gt; because your algorithm always continues in the same &lt;br&gt;
&amp;gt; direction if it&lt;br&gt;
&amp;gt; &amp;gt; can, it would continue on the downward diagonal to the &lt;br&gt;
&amp;gt; edge, find&lt;br&gt;
&amp;gt; &amp;gt; the upward-left step from the bottom as the only &lt;br&gt;
&amp;gt; connection to the&lt;br&gt;
&amp;gt; &amp;gt; bottom pixel, and would 0 out the entire diagonal, &lt;br&gt;
&amp;gt; leaving you with&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 001111&lt;br&gt;
&amp;gt; &amp;gt; 000000&lt;br&gt;
&amp;gt; &amp;gt; 000000&lt;br&gt;
&amp;gt; &amp;gt; 000000&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; with you positioned at (3,3). There are no connections &lt;br&gt;
&amp;gt; from there&lt;br&gt;
&amp;gt; &amp;gt; so the algorithm would stop, unable to reach that chain &lt;br&gt;
&amp;gt; at the top&lt;br&gt;
&amp;gt; &amp;gt; right corner. The algorithm has thus clearly not found &lt;br&gt;
&amp;gt; the proper length.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Generally speaking, the algorithm's preference for &lt;br&gt;
&amp;gt; continuing in&lt;br&gt;
&amp;gt; &amp;gt; the same direction as possible is going to create &lt;br&gt;
&amp;gt; problems for you,&lt;br&gt;
&amp;gt; &amp;gt; as it will be unable to recognize where the molecule &lt;br&gt;
&amp;gt; changes&lt;br&gt;
&amp;gt; &amp;gt; direction even just due to a standard convex curve. And &lt;br&gt;
&amp;gt; as I showed&lt;br&gt;
&amp;gt; &amp;gt; above, counting pixels visited is not an accurate length &lt;br&gt;
&amp;gt; measure&lt;br&gt;
&amp;gt; &amp;gt; if any branches exist. Thirdly, you are not talking into &lt;br&gt;
&amp;gt; account&lt;br&gt;
&amp;gt; &amp;gt; that diagonal moves are further than vertical or &lt;br&gt;
&amp;gt; horizontal moves.&lt;br&gt;
&amp;gt; &amp;gt; -- &lt;br&gt;
&amp;gt; &amp;gt;   "Prevention is the daughter of intelligence."&lt;br&gt;
&amp;gt; &amp;gt;                                               -- Sir &lt;br&gt;
&amp;gt; Walter Raleigh&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Adrian,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is very roughly coded but it gives 'an' answer. You &lt;br&gt;
&amp;gt; might find it  helpful.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Ken&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Read in image and compress to 2D&lt;br&gt;
&amp;gt; ifs='c:\temp\mol.png';&lt;br&gt;
&amp;gt; im=imread(ifs);&lt;br&gt;
&amp;gt; im=sum(im,3);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Show original image&lt;br&gt;
&amp;gt; figure(1);&lt;br&gt;
&amp;gt; imagesc(im);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Blur and display&lt;br&gt;
&amp;gt; filt=fspecial('disk',2);&lt;br&gt;
&amp;gt; blurred_im=imfilter(im,filt,'replicate');&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; figure(2);&lt;br&gt;
&amp;gt; imagesc(blurred_im);&lt;br&gt;
&amp;gt; colorbar;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Threshold the blurred version&lt;br&gt;
&amp;gt; threshold_im=zeros(size(im));&lt;br&gt;
&amp;gt; threshold_im(blurred_im&amp;gt;230)=1;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; figure(3);&lt;br&gt;
&amp;gt; imagesc(threshold_im);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % And keep only the largest 'island' which is the molecule&lt;br&gt;
&amp;gt; molecule_im=bwareaopen(threshold_im,600);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; figure(4);&lt;br&gt;
&amp;gt; clf;&lt;br&gt;
&amp;gt; imagesc(molecule_im);&lt;br&gt;
&amp;gt; hold on;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Now get the perimeter&lt;br&gt;
&amp;gt; mol_properties=regionprops(bwlabel(molecule_im), ...&lt;br&gt;
&amp;gt;     'perimeter');&lt;br&gt;
&amp;gt; molecule_length=(mol_properties.Perimeter)/2&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % And draw it to make sure we have the right thing&lt;br&gt;
&amp;gt; [p,l]=bwboundaries(molecule_im,4,'noholes');&lt;br&gt;
&amp;gt; boundary=p{1};&lt;br&gt;
&amp;gt; plot(boundary(:,2),boundary(:,1),'y');&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Ken,&lt;br&gt;
&lt;br&gt;
Is there anyway to modify your code to outline more than one&lt;br&gt;
molecule? It works great for one molecule, but when I start&lt;br&gt;
looking at more than one, the program breaks. &lt;br&gt;
&lt;br&gt;
I'm planning on making a GUI for the program so the user can&lt;br&gt;
change the thresholds as needed for an image. After trying&lt;br&gt;
out your algorithm with various DNA images I have, the&lt;br&gt;
shading is different between each one (because of the&lt;br&gt;
inconsistent heavy-metal shadowing, I assume). &lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Adrian &lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 15 May 2008 15:22:02 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#432269</link>
      <author>Adrian </author>
      <description>Thank you so much for your responses and analysis of my&lt;br&gt;
problem. I will try all of your suggestions and will post&lt;br&gt;
anything I come up with. &lt;br&gt;
&lt;br&gt;
Ken, thank you for the code - I just tried and it and seems&lt;br&gt;
to be working very well. Your algorithm is very clean,&lt;br&gt;
something I admire. I clearly need to learn more of the&lt;br&gt;
advanced functions MATLAB has to offer.&lt;br&gt;
&lt;br&gt;
Thanks again to everyone for your help,&lt;br&gt;
Adrian Randall&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 13 May 2008 23:18:04 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431917</link>
      <author>Ken Campbell</author>
      <description>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in &lt;br&gt;
message &amp;lt;g0crs0$6al$1@canopus.cc.umanitoba.ca&amp;gt;...&lt;br&gt;
&amp;gt; In article &amp;lt;g0couj$np$1@fred.mathworks.com&amp;gt;, Adrian  &lt;br&gt;
&amp;lt;ajr@med.unc.edu&amp;gt; wrote:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;4) Scan the image from left to right and then "walk" &lt;br&gt;
along&lt;br&gt;
&amp;gt; &amp;gt;areas that are labeled as "1". If the program finds a &lt;br&gt;
pixel&lt;br&gt;
&amp;gt; &amp;gt;that is labeled "1", look toward the 8 surrounding &lt;br&gt;
pixels to&lt;br&gt;
&amp;gt; &amp;gt;find if there is another pixel labeled "1". If so, &lt;br&gt;
continue&lt;br&gt;
&amp;gt; &amp;gt;to look for pixels labeled "1" (e.g., keep "walking" &lt;br&gt;
along&lt;br&gt;
&amp;gt; &amp;gt;the molecule), and if possible, continue "walking" in the&lt;br&gt;
&amp;gt; &amp;gt;same direction as previously (to prevent the "walker" &lt;br&gt;
from&lt;br&gt;
&amp;gt; &amp;gt;going back to where it came from). Then, after walking &lt;br&gt;
along&lt;br&gt;
&amp;gt; &amp;gt;the molecule, label all of the points it walked on &lt;br&gt;
as "0" so&lt;br&gt;
&amp;gt; &amp;gt;the scanner won't walk there again. &lt;br&gt;
&amp;gt; &amp;gt;5) Output the length measurement as pixel and convert to &lt;br&gt;
nm&lt;br&gt;
&amp;gt; &amp;gt;by looking at the scale.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Suppose you have&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 1011&lt;br&gt;
&amp;gt; 0100&lt;br&gt;
&amp;gt; 0010&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And you start at the top-left corner. You walk left to &lt;br&gt;
right so you&lt;br&gt;
&amp;gt; encounter the top-left 1. Presumably you increment your &lt;br&gt;
count to 1.&lt;br&gt;
&amp;gt; You examine the surrounding pixels and find&lt;br&gt;
&amp;gt; the 1 diagonally down and right. You try to continue left &lt;br&gt;
to right, but&lt;br&gt;
&amp;gt; there is no 1 there so you take the path that is open by &lt;br&gt;
going diagonally&lt;br&gt;
&amp;gt; down and right. However, as you were not able to continue &lt;br&gt;
in the same&lt;br&gt;
&amp;gt; direction as you had been going, you label the points you &lt;br&gt;
walked in&lt;br&gt;
&amp;gt; that stretch with a 0 so the scanner won't walk there &lt;br&gt;
again, leading to&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 0011&lt;br&gt;
&amp;gt; 0100&lt;br&gt;
&amp;gt; 0010&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You are at the second pixel, presumably you increment &lt;br&gt;
your count to 2.&lt;br&gt;
&amp;gt; Now you are headed diagonally down and right. You examine &lt;br&gt;
the&lt;br&gt;
&amp;gt; surrounding pixels and find the 1 diagonally up and right &lt;br&gt;
and&lt;br&gt;
&amp;gt; the 1 diagonally down and right. As per your algorithm, &lt;br&gt;
you prefer&lt;br&gt;
&amp;gt; to keep going in the same direction, so you take the &lt;br&gt;
diagonal&lt;br&gt;
&amp;gt; down and right. As you -were- able to continue in the &lt;br&gt;
same direction,&lt;br&gt;
&amp;gt; you are on a run and so do -not- mark the pixel you came &lt;br&gt;
from with a 0.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You are at the third pixel, presumably you increment your &lt;br&gt;
count to 3.&lt;br&gt;
&amp;gt; You look around from that bottom pixel and find the only &lt;br&gt;
path open&lt;br&gt;
&amp;gt; to be the one up and left. However, as you were not able &lt;br&gt;
to continue&lt;br&gt;
&amp;gt; in the same direction as you had been going, you label &lt;br&gt;
the points&lt;br&gt;
&amp;gt; you walked in the run with a 0 won't walk there again, &lt;br&gt;
leading to&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 0011&lt;br&gt;
&amp;gt; 0000&lt;br&gt;
&amp;gt; 0000&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; There is now an ambiguity in your algorithm: you had an &lt;br&gt;
available&lt;br&gt;
&amp;gt; path up-left a moment ago, but that pixel is now 0'd, and &lt;br&gt;
there&lt;br&gt;
&amp;gt; are now no pixels left in the neighbourhood that are non-&lt;br&gt;
0. Do you&lt;br&gt;
&amp;gt; stop at this point with a pixel count of 3? My &lt;br&gt;
interpretation of&lt;br&gt;
&amp;gt; your algorithm is that you do -not- stop, because your &lt;br&gt;
instruction&lt;br&gt;
&amp;gt; was to do the search before the 0'ing.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; So you are now back at 2nd row 2nd column. Your algorithm &lt;br&gt;
didn't&lt;br&gt;
&amp;gt; say anything about not counting on backtracks, so &lt;br&gt;
presumably you&lt;br&gt;
&amp;gt; increment the count to 4. You look around and find the &lt;br&gt;
open path&lt;br&gt;
&amp;gt; to the up-right. That's a change of direction, so you 0 &lt;br&gt;
out the pixels&lt;br&gt;
&amp;gt; you had in that run, which makes no change because they &lt;br&gt;
are already 0.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You are now at the 1st row 3rd column, trying to head up &lt;br&gt;
and right.&lt;br&gt;
&amp;gt; Presumably you increment your counter to 5. You look &lt;br&gt;
around and&lt;br&gt;
&amp;gt; find the open path to the right. That's a change of &lt;br&gt;
direction&lt;br&gt;
&amp;gt; so you 0 out the pixels you had in that run, which makes &lt;br&gt;
the matrix&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 0001&lt;br&gt;
&amp;gt; 0000&lt;br&gt;
&amp;gt; 0000&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You are now at the 1st row 4th column, trying to head &lt;br&gt;
right.&lt;br&gt;
&amp;gt; Presumably you increment your counter to 6. You look &lt;br&gt;
around and find&lt;br&gt;
&amp;gt; no open paths. Presumably you stop there.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Your recorded molecule length is now 6, but the longest &lt;br&gt;
connected&lt;br&gt;
&amp;gt; chain was 4 -- (1,1) -&amp;gt; (2,2) -&amp;gt; (1,3) -&amp;gt; (1,4), so &lt;br&gt;
arguably the&lt;br&gt;
&amp;gt; molecule length is 4 instead. Or, since there were two &lt;br&gt;
diagonal&lt;br&gt;
&amp;gt; moves and then 1 lateral move, 2*sqrt(2)+1, which is &lt;br&gt;
about 3.8.&lt;br&gt;
&amp;gt; Add 1 if you are counting from the edges instead of from &lt;br&gt;
the centers.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Now, suppose you had started with&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 101111&lt;br&gt;
&amp;gt; 010000&lt;br&gt;
&amp;gt; 001000&lt;br&gt;
&amp;gt; 000100&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; then when you are examining (2,2) after coming from (1,1),&lt;br&gt;
&amp;gt; because your algorithm always continues in the same &lt;br&gt;
direction if it&lt;br&gt;
&amp;gt; can, it would continue on the downward diagonal to the &lt;br&gt;
edge, find&lt;br&gt;
&amp;gt; the upward-left step from the bottom as the only &lt;br&gt;
connection to the&lt;br&gt;
&amp;gt; bottom pixel, and would 0 out the entire diagonal, &lt;br&gt;
leaving you with&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 001111&lt;br&gt;
&amp;gt; 000000&lt;br&gt;
&amp;gt; 000000&lt;br&gt;
&amp;gt; 000000&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; with you positioned at (3,3). There are no connections &lt;br&gt;
from there&lt;br&gt;
&amp;gt; so the algorithm would stop, unable to reach that chain &lt;br&gt;
at the top&lt;br&gt;
&amp;gt; right corner. The algorithm has thus clearly not found &lt;br&gt;
the proper length.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Generally speaking, the algorithm's preference for &lt;br&gt;
continuing in&lt;br&gt;
&amp;gt; the same direction as possible is going to create &lt;br&gt;
problems for you,&lt;br&gt;
&amp;gt; as it will be unable to recognize where the molecule &lt;br&gt;
changes&lt;br&gt;
&amp;gt; direction even just due to a standard convex curve. And &lt;br&gt;
as I showed&lt;br&gt;
&amp;gt; above, counting pixels visited is not an accurate length &lt;br&gt;
measure&lt;br&gt;
&amp;gt; if any branches exist. Thirdly, you are not talking into &lt;br&gt;
account&lt;br&gt;
&amp;gt; that diagonal moves are further than vertical or &lt;br&gt;
horizontal moves.&lt;br&gt;
&amp;gt; -- &lt;br&gt;
&amp;gt;   "Prevention is the daughter of intelligence."&lt;br&gt;
&amp;gt;                                               -- Sir &lt;br&gt;
Walter Raleigh&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Adrian,&lt;br&gt;
&lt;br&gt;
This is very roughly coded but it gives 'an' answer. You &lt;br&gt;
might find it  helpful.&lt;br&gt;
&lt;br&gt;
Ken&lt;br&gt;
&lt;br&gt;
% Read in image and compress to 2D&lt;br&gt;
ifs='c:\temp\mol.png';&lt;br&gt;
im=imread(ifs);&lt;br&gt;
im=sum(im,3);&lt;br&gt;
&lt;br&gt;
% Show original image&lt;br&gt;
figure(1);&lt;br&gt;
imagesc(im);&lt;br&gt;
&lt;br&gt;
% Blur and display&lt;br&gt;
filt=fspecial('disk',2);&lt;br&gt;
blurred_im=imfilter(im,filt,'replicate');&lt;br&gt;
&lt;br&gt;
figure(2);&lt;br&gt;
imagesc(blurred_im);&lt;br&gt;
colorbar;&lt;br&gt;
&lt;br&gt;
% Threshold the blurred version&lt;br&gt;
threshold_im=zeros(size(im));&lt;br&gt;
threshold_im(blurred_im&amp;gt;230)=1;&lt;br&gt;
&lt;br&gt;
figure(3);&lt;br&gt;
imagesc(threshold_im);&lt;br&gt;
&lt;br&gt;
% And keep only the largest 'island' which is the molecule&lt;br&gt;
molecule_im=bwareaopen(threshold_im,600);&lt;br&gt;
&lt;br&gt;
figure(4);&lt;br&gt;
clf;&lt;br&gt;
imagesc(molecule_im);&lt;br&gt;
hold on;&lt;br&gt;
&lt;br&gt;
% Now get the perimeter&lt;br&gt;
mol_properties=regionprops(bwlabel(molecule_im), ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'perimeter');&lt;br&gt;
molecule_length=(mol_properties.Perimeter)/2&lt;br&gt;
&lt;br&gt;
% And draw it to make sure we have the right thing&lt;br&gt;
[p,l]=bwboundaries(molecule_im,4,'noholes');&lt;br&gt;
boundary=p{1};&lt;br&gt;
plot(boundary(:,2),boundary(:,1),'y');&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 13 May 2008 19:57:52 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431892</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;g0couj$np$1@fred.mathworks.com&amp;gt;, Adrian  &amp;lt;ajr@med.unc.edu&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt;4) Scan the image from left to right and then "walk" along&lt;br&gt;
&amp;gt;areas that are labeled as "1". If the program finds a pixel&lt;br&gt;
&amp;gt;that is labeled "1", look toward the 8 surrounding pixels to&lt;br&gt;
&amp;gt;find if there is another pixel labeled "1". If so, continue&lt;br&gt;
&amp;gt;to look for pixels labeled "1" (e.g., keep "walking" along&lt;br&gt;
&amp;gt;the molecule), and if possible, continue "walking" in the&lt;br&gt;
&amp;gt;same direction as previously (to prevent the "walker" from&lt;br&gt;
&amp;gt;going back to where it came from). Then, after walking along&lt;br&gt;
&amp;gt;the molecule, label all of the points it walked on as "0" so&lt;br&gt;
&amp;gt;the scanner won't walk there again. &lt;br&gt;
&amp;gt;5) Output the length measurement as pixel and convert to nm&lt;br&gt;
&amp;gt;by looking at the scale.&lt;br&gt;
&lt;br&gt;
Suppose you have&lt;br&gt;
&lt;br&gt;
1011&lt;br&gt;
0100&lt;br&gt;
0010&lt;br&gt;
&lt;br&gt;
And you start at the top-left corner. You walk left to right so you&lt;br&gt;
encounter the top-left 1. Presumably you increment your count to 1.&lt;br&gt;
You examine the surrounding pixels and find&lt;br&gt;
the 1 diagonally down and right. You try to continue left to right, but&lt;br&gt;
there is no 1 there so you take the path that is open by going diagonally&lt;br&gt;
down and right. However, as you were not able to continue in the same&lt;br&gt;
direction as you had been going, you label the points you walked in&lt;br&gt;
that stretch with a 0 so the scanner won't walk there again, leading to&lt;br&gt;
&lt;br&gt;
0011&lt;br&gt;
0100&lt;br&gt;
0010&lt;br&gt;
&lt;br&gt;
You are at the second pixel, presumably you increment your count to 2.&lt;br&gt;
Now you are headed diagonally down and right. You examine the&lt;br&gt;
surrounding pixels and find the 1 diagonally up and right and&lt;br&gt;
the 1 diagonally down and right. As per your algorithm, you prefer&lt;br&gt;
to keep going in the same direction, so you take the diagonal&lt;br&gt;
down and right. As you -were- able to continue in the same direction,&lt;br&gt;
you are on a run and so do -not- mark the pixel you came from with a 0.&lt;br&gt;
&lt;br&gt;
You are at the third pixel, presumably you increment your count to 3.&lt;br&gt;
You look around from that bottom pixel and find the only path open&lt;br&gt;
to be the one up and left. However, as you were not able to continue&lt;br&gt;
in the same direction as you had been going, you label the points&lt;br&gt;
you walked in the run with a 0 won't walk there again, leading to&lt;br&gt;
&lt;br&gt;
0011&lt;br&gt;
0000&lt;br&gt;
0000&lt;br&gt;
&lt;br&gt;
There is now an ambiguity in your algorithm: you had an available&lt;br&gt;
path up-left a moment ago, but that pixel is now 0'd, and there&lt;br&gt;
are now no pixels left in the neighbourhood that are non-0. Do you&lt;br&gt;
stop at this point with a pixel count of 3? My interpretation of&lt;br&gt;
your algorithm is that you do -not- stop, because your instruction&lt;br&gt;
was to do the search before the 0'ing.&lt;br&gt;
&lt;br&gt;
So you are now back at 2nd row 2nd column. Your algorithm didn't&lt;br&gt;
say anything about not counting on backtracks, so presumably you&lt;br&gt;
increment the count to 4. You look around and find the open path&lt;br&gt;
to the up-right. That's a change of direction, so you 0 out the pixels&lt;br&gt;
you had in that run, which makes no change because they are already 0.&lt;br&gt;
&lt;br&gt;
You are now at the 1st row 3rd column, trying to head up and right.&lt;br&gt;
Presumably you increment your counter to 5. You look around and&lt;br&gt;
find the open path to the right. That's a change of direction&lt;br&gt;
so you 0 out the pixels you had in that run, which makes the matrix&lt;br&gt;
&lt;br&gt;
0001&lt;br&gt;
0000&lt;br&gt;
0000&lt;br&gt;
&lt;br&gt;
You are now at the 1st row 4th column, trying to head right.&lt;br&gt;
Presumably you increment your counter to 6. You look around and find&lt;br&gt;
no open paths. Presumably you stop there.&lt;br&gt;
&lt;br&gt;
Your recorded molecule length is now 6, but the longest connected&lt;br&gt;
chain was 4 -- (1,1) -&amp;gt; (2,2) -&amp;gt; (1,3) -&amp;gt; (1,4), so arguably the&lt;br&gt;
molecule length is 4 instead. Or, since there were two diagonal&lt;br&gt;
moves and then 1 lateral move, 2*sqrt(2)+1, which is about 3.8.&lt;br&gt;
Add 1 if you are counting from the edges instead of from the centers.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Now, suppose you had started with&lt;br&gt;
&lt;br&gt;
101111&lt;br&gt;
010000&lt;br&gt;
001000&lt;br&gt;
000100&lt;br&gt;
&lt;br&gt;
then when you are examining (2,2) after coming from (1,1),&lt;br&gt;
because your algorithm always continues in the same direction if it&lt;br&gt;
can, it would continue on the downward diagonal to the edge, find&lt;br&gt;
the upward-left step from the bottom as the only connection to the&lt;br&gt;
bottom pixel, and would 0 out the entire diagonal, leaving you with&lt;br&gt;
&lt;br&gt;
001111&lt;br&gt;
000000&lt;br&gt;
000000&lt;br&gt;
000000&lt;br&gt;
&lt;br&gt;
with you positioned at (3,3). There are no connections from there&lt;br&gt;
so the algorithm would stop, unable to reach that chain at the top&lt;br&gt;
right corner. The algorithm has thus clearly not found the proper length.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Generally speaking, the algorithm's preference for continuing in&lt;br&gt;
the same direction as possible is going to create problems for you,&lt;br&gt;
as it will be unable to recognize where the molecule changes&lt;br&gt;
direction even just due to a standard convex curve. And as I showed&lt;br&gt;
above, counting pixels visited is not an accurate length measure&lt;br&gt;
if any branches exist. Thirdly, you are not talking into account&lt;br&gt;
that diagonal moves are further than vertical or horizontal moves.&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;"Prevention is the daughter of intelligence."&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-- Sir Walter Raleigh&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 13 May 2008 19:27:04 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431887</link>
      <author>ImageAnalyst</author>
      <description>On May 13, 3:08=A0pm, "Adrian " &amp;lt;a...@med.unc.edu&amp;gt; wrote:&lt;br&gt;
&amp;gt; Thank you all for your insight into the matter. Sorry for&lt;br&gt;
&amp;gt; the lack of clarification for the image I linked to: the&lt;br&gt;
&amp;gt; squiggly line in the middle is in fact the molecule.&lt;br&gt;
&amp;gt; Everything else is background. The image is a transmission&lt;br&gt;
&amp;gt; electron micrograph, so it's 2D and fixed.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; The way that we do length analysis is by manually drawing&lt;br&gt;
&amp;gt; along the molecule using a mouse and some software that came&lt;br&gt;
&amp;gt; with the electron microscope. As you can image, this is&lt;br&gt;
&amp;gt; somewhat inaccurate and tedious, especially if one is&lt;br&gt;
&amp;gt; scoring hundreds of molecules. In addition, for the project&lt;br&gt;
&amp;gt; I am working on, length analysis is the centerpiece, so I&lt;br&gt;
&amp;gt; want to have data as accurate as possible.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I didn't include a scale bar - my apologies. I wanted to&lt;br&gt;
&amp;gt; isolate only one molecule to make the problem easier to&lt;br&gt;
&amp;gt; solve, =A0and forgot to include the scale. There is a scale&lt;br&gt;
&amp;gt; that converts pixel length to actual distance that I know&lt;br&gt;
&amp;gt; how to use, so the only problem is finding the pixel length.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; This is a method I have come up with from using your&lt;br&gt;
&amp;gt; suggestions.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 1) Find the average pixel shade (between 0 and 255)&lt;br&gt;
&amp;gt; 2) Remove all pixels that are below the threshold (remove&lt;br&gt;
&amp;gt; the darker background).&lt;br&gt;
&amp;gt; 3) Set the remaining pixels equal to 1; all other pixels&lt;br&gt;
&amp;gt; equal to 0.&lt;br&gt;
&amp;gt; 4) Scan the image from left to right and then "walk" along&lt;br&gt;
&amp;gt; areas that are labeled as "1". If the program finds a pixel&lt;br&gt;
&amp;gt; that is labeled "1", look toward the 8 surrounding pixels to&lt;br&gt;
&amp;gt; find if there is another pixel labeled "1". If so, continue&lt;br&gt;
&amp;gt; to look for pixels labeled "1" (e.g., keep "walking" along&lt;br&gt;
&amp;gt; the molecule), and if possible, continue "walking" in the&lt;br&gt;
&amp;gt; same direction as previously (to prevent the "walker" from&lt;br&gt;
&amp;gt; going back to where it came from). Then, after walking along&lt;br&gt;
&amp;gt; the molecule, label all of the points it walked on as "0" so&lt;br&gt;
&amp;gt; the scanner won't walk there again.&lt;br&gt;
&amp;gt; 5) Output the length measurement as pixel and convert to nm&lt;br&gt;
&amp;gt; by looking at the scale.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Does this seem reasonable? Thank you very much for the&lt;br&gt;
&amp;gt; discussion..&lt;br&gt;
&lt;br&gt;
--------------------------------------------------------------------------&lt;br&gt;
Adrian:&lt;br&gt;
Glad you're still monitoring and we're not just wasting our time&lt;br&gt;
here.  You could do what you described with this algorithm:&lt;br&gt;
1. Binarize the image at some threshold.&lt;br&gt;
2. Skeletonize the image - bwmorph(thresholdedImageArray, 'skel',&lt;br&gt;
Inf).  That's what I'm doing but you're essentially doing bwlabel and&lt;br&gt;
then binarizing the labeled image.  Skeletonizing has the advantage&lt;br&gt;
that it will ignore parts of the line that are thicker than one pixel&lt;br&gt;
but it will under count big solid balled up areas.  Your method will&lt;br&gt;
overcount parts of the line that are thicker than one pixel but will&lt;br&gt;
correctly count big balled up areas.&lt;br&gt;
3. Sum the pixels in the image Sum(sum(skeletonizedImageArray))&lt;br&gt;
The only point I might add is that you might want to count triple and&lt;br&gt;
quad points (where the line touches or crosses itself) twice rather&lt;br&gt;
than avoiding counting those pixels like you said.  The molecule would&lt;br&gt;
actually occur twice at those positions.  Think about it and you'll&lt;br&gt;
see why.&lt;br&gt;
Regards,&lt;br&gt;
ImageAnalyst&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 13 May 2008 19:08:03 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431880</link>
      <author>Adrian </author>
      <description>Thank you all for your insight into the matter. Sorry for&lt;br&gt;
the lack of clarification for the image I linked to: the&lt;br&gt;
squiggly line in the middle is in fact the molecule.&lt;br&gt;
Everything else is background. The image is a transmission&lt;br&gt;
electron micrograph, so it's 2D and fixed.&lt;br&gt;
&lt;br&gt;
The way that we do length analysis is by manually drawing&lt;br&gt;
along the molecule using a mouse and some software that came&lt;br&gt;
with the electron microscope. As you can image, this is&lt;br&gt;
somewhat inaccurate and tedious, especially if one is&lt;br&gt;
scoring hundreds of molecules. In addition, for the project&lt;br&gt;
I am working on, length analysis is the centerpiece, so I&lt;br&gt;
want to have data as accurate as possible. &lt;br&gt;
&lt;br&gt;
I didn't include a scale bar - my apologies. I wanted to&lt;br&gt;
isolate only one molecule to make the problem easier to&lt;br&gt;
solve,  and forgot to include the scale. There is a scale&lt;br&gt;
that converts pixel length to actual distance that I know&lt;br&gt;
how to use, so the only problem is finding the pixel length. &lt;br&gt;
&lt;br&gt;
This is a method I have come up with from using your&lt;br&gt;
suggestions. &lt;br&gt;
&lt;br&gt;
1) Find the average pixel shade (between 0 and 255)&lt;br&gt;
2) Remove all pixels that are below the threshold (remove&lt;br&gt;
the darker background).&lt;br&gt;
3) Set the remaining pixels equal to 1; all other pixels&lt;br&gt;
equal to 0.&lt;br&gt;
4) Scan the image from left to right and then "walk" along&lt;br&gt;
areas that are labeled as "1". If the program finds a pixel&lt;br&gt;
that is labeled "1", look toward the 8 surrounding pixels to&lt;br&gt;
find if there is another pixel labeled "1". If so, continue&lt;br&gt;
to look for pixels labeled "1" (e.g., keep "walking" along&lt;br&gt;
the molecule), and if possible, continue "walking" in the&lt;br&gt;
same direction as previously (to prevent the "walker" from&lt;br&gt;
going back to where it came from). Then, after walking along&lt;br&gt;
the molecule, label all of the points it walked on as "0" so&lt;br&gt;
the scanner won't walk there again. &lt;br&gt;
5) Output the length measurement as pixel and convert to nm&lt;br&gt;
by looking at the scale.&lt;br&gt;
&lt;br&gt;
Does this seem reasonable? Thank you very much for the&lt;br&gt;
discussion..&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 13 May 2008 04:26:03 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431703</link>
      <author>Ken Campbell</author>
      <description>ImageAnalyst &amp;lt;imageanalyst@mailinator.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;7d6b1108-5156-49cb-84bf-&lt;br&gt;
423bb11b437a@k13g2000hse.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On May 11, 7:12=A0pm, rober...@ibd.nrc-cnrc.gc.ca (Walter &lt;br&gt;
Roberson)&lt;br&gt;
&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; In article &amp;lt;g07jfi$af...@fred.mathworks.com&amp;gt;,&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Roger Stafford &lt;br&gt;
&amp;lt;ellieandrogerxy...@mindspring.com.invalid&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; =A0Note to ImageAnalyst: In my opinion the length of &lt;br&gt;
the shape's perimet=&lt;br&gt;
&amp;gt; er&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;(presumably divided by 2) is not a reliable measure of &lt;br&gt;
what Adrian is see=&lt;br&gt;
&amp;gt; king&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;as the over-all length of a molecule. =A0Its outline &lt;br&gt;
is likely to be a so=&lt;br&gt;
&amp;gt; mewhat&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;jagged affair as is characteristic of long-chain &lt;br&gt;
molecules with differing=&lt;br&gt;
&amp;gt;  kinds&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;of structures and would tend to give too large and &lt;br&gt;
inconsistent a value.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Hmmm, that triggers the throught that the molecule may &lt;br&gt;
have significant&lt;br&gt;
&amp;gt; &amp;gt; 3 dimensional components; unless we have at least two &lt;br&gt;
views of it&lt;br&gt;
&amp;gt; &amp;gt; in different planes, we would not be able to tell &lt;br&gt;
whether the molecule&lt;br&gt;
&amp;gt; &amp;gt; just happens to be shorter in the direction of view, &lt;br&gt;
but long into&lt;br&gt;
&amp;gt; &amp;gt; or out of the direction of view.&lt;br&gt;
&amp;gt; &amp;gt; --&lt;br&gt;
&amp;gt; &amp;gt; =A0 "The quirks and arbitrariness we observe force us &lt;br&gt;
to the&lt;br&gt;
&amp;gt; &amp;gt; =A0 conclusion that ours is not the only universe." -- &lt;br&gt;
Walter Kistler&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ----------------------------------------------------------&lt;br&gt;
------------------=&lt;br&gt;
&amp;gt; ----------------&lt;br&gt;
&amp;gt; Well Walter, I believe you're exactly right.  I imagine &lt;br&gt;
that, assuming&lt;br&gt;
&amp;gt; the molecule is the string-like object in the scene, that &lt;br&gt;
if you took&lt;br&gt;
&amp;gt; a picture of it at one time, at another time the molecule &lt;br&gt;
could have&lt;br&gt;
&amp;gt; squiggled to a completely different shape, and since it's &lt;br&gt;
probably&lt;br&gt;
&amp;gt; floating around in 3D in some liquid, its projected shape &lt;br&gt;
(onto a 2D&lt;br&gt;
&amp;gt; image) and length could be completely different from one &lt;br&gt;
image to the&lt;br&gt;
&amp;gt; next.  This change is called "repeatability" and is how &lt;br&gt;
this one&lt;br&gt;
&amp;gt; molecule specimen changes from one snap of that one &lt;br&gt;
molecule to the&lt;br&gt;
&amp;gt; next.  There's also something called "reproducibility" &lt;br&gt;
which is a&lt;br&gt;
&amp;gt; different specimen of the same species of molecule but &lt;br&gt;
imaged as a&lt;br&gt;
&amp;gt; separate sample on perhaps a different microscope.  So &lt;br&gt;
because of all&lt;br&gt;
&amp;gt; this, it's possible that the molecule could have &lt;br&gt;
different "lengths"&lt;br&gt;
&amp;gt; depending on when you snapped the picture because you're &lt;br&gt;
seeing just a&lt;br&gt;
&amp;gt; 2D projection of it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And another thing . . . when you take a look at the image &lt;br&gt;
he posted,&lt;br&gt;
&amp;gt; let's say the "head" of the molecule is that wad of &lt;br&gt;
curled up stuff&lt;br&gt;
&amp;gt; plus the loop, and the tail is the other end.  Now &lt;br&gt;
exactly where does&lt;br&gt;
&amp;gt; the tail end?  You can see that it's not so easy to &lt;br&gt;
answer.  Maybe it&lt;br&gt;
&amp;gt; curls around down below and heads back to the right.  &lt;br&gt;
(It's not as&lt;br&gt;
&amp;gt; obvious now - I think he replaced the with a smaller &lt;br&gt;
version of what&lt;br&gt;
&amp;gt; he used to have).  But the tail seems to sort of fade &lt;br&gt;
away and it's&lt;br&gt;
&amp;gt; not really clear where it ends.  It is sort of a &lt;br&gt;
judgement call.  And&lt;br&gt;
&amp;gt; what about the head?  Is there a bunch of length there &lt;br&gt;
that is all&lt;br&gt;
&amp;gt; tangled up into a ball so that you can't really know &lt;br&gt;
the "true"&lt;br&gt;
&amp;gt; length?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; And Adrian didn't say what kind of precision he needs.  &lt;br&gt;
Maybe a fully&lt;br&gt;
&amp;gt; automated method with sub-pixel precision is needed, but &lt;br&gt;
maybe just&lt;br&gt;
&amp;gt; hand-tracing the line is good enough especially if the &lt;br&gt;
length changes&lt;br&gt;
&amp;gt; a lot from one snapshot to the next.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Because of all this, it probably doesn't make sense to go &lt;br&gt;
overboard&lt;br&gt;
&amp;gt; with fancy algorithms to get the length of the molecule &lt;br&gt;
in that one&lt;br&gt;
&amp;gt; single, specific picture with sub-pixel precision when &lt;br&gt;
the "length" of&lt;br&gt;
&amp;gt; the molecule may vary by tens or hundreds of pixels from &lt;br&gt;
one picture&lt;br&gt;
&amp;gt; to the next.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hey Adrian, are you ever going to check back here for &lt;br&gt;
answers to your&lt;br&gt;
&amp;gt; question, and answer some of the issues brought up?&lt;br&gt;
&amp;gt; Regards,&lt;br&gt;
&amp;gt; ImageAnalyst&lt;br&gt;
&lt;br&gt;
I would be interested in Adrian's comments too but I've &lt;br&gt;
enjoyed following the thread and thinking about the &lt;br&gt;
different ways of approaching the problem. There have been &lt;br&gt;
some good ideas.&lt;br&gt;
&lt;br&gt;
I am wary of answering questions that Adrian really needs &lt;br&gt;
to answer but I think the image shows a molecule that has &lt;br&gt;
been deposited on a surface and then stained with something &lt;br&gt;
to increase the contrast for electron microscopy. This &lt;br&gt;
means that the molecule is deposited 'flat' on a surface  &lt;br&gt;
and doesn't cross over itself. I agree that the problem is &lt;br&gt;
harder if this isn't the case. For what it's worth I don't &lt;br&gt;
think that you can do electron microscopy on molecules 'in &lt;br&gt;
solution'.&lt;br&gt;
&lt;br&gt;
I've seen people talk about similar images in seminars I've &lt;br&gt;
attended and I'd be surprised if Adrian needs to 'unravel' &lt;br&gt;
the ball or requires 'sub-pixel' methods. I think &lt;br&gt;
the 'perimeter' approach is probably the most appropriate &lt;br&gt;
idea that's been suggested so far for this type of work.&lt;br&gt;
&lt;br&gt;
But as ImageAnalyst points out, that's really for Adrian to &lt;br&gt;
decide.&lt;br&gt;
&lt;br&gt;
Ken&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 12 May 2008 18:19:32 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431625</link>
      <author>ImageAnalyst</author>
      <description>On May 11, 7:12=A0pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)&lt;br&gt;
wrote:&lt;br&gt;
&amp;gt; In article &amp;lt;g07jfi$af...@fred.mathworks.com&amp;gt;,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Roger Stafford &amp;lt;ellieandrogerxy...@mindspring.com.invalid&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; =A0Note to ImageAnalyst: In my opinion the length of the shape's perimet=&lt;br&gt;
er&lt;br&gt;
&amp;gt; &amp;gt;(presumably divided by 2) is not a reliable measure of what Adrian is see=&lt;br&gt;
king&lt;br&gt;
&amp;gt; &amp;gt;as the over-all length of a molecule. =A0Its outline is likely to be a so=&lt;br&gt;
mewhat&lt;br&gt;
&amp;gt; &amp;gt;jagged affair as is characteristic of long-chain molecules with differing=&lt;br&gt;
&amp;nbsp;kinds&lt;br&gt;
&amp;gt; &amp;gt;of structures and would tend to give too large and inconsistent a value.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Hmmm, that triggers the throught that the molecule may have significant&lt;br&gt;
&amp;gt; 3 dimensional components; unless we have at least two views of it&lt;br&gt;
&amp;gt; in different planes, we would not be able to tell whether the molecule&lt;br&gt;
&amp;gt; just happens to be shorter in the direction of view, but long into&lt;br&gt;
&amp;gt; or out of the direction of view.&lt;br&gt;
&amp;gt; --&lt;br&gt;
&amp;gt; =A0 "The quirks and arbitrariness we observe force us to the&lt;br&gt;
&amp;gt; =A0 conclusion that ours is not the only universe." -- Walter Kistler&lt;br&gt;
&lt;br&gt;
----------------------------------------------------------------------------=&lt;br&gt;
----------------&lt;br&gt;
Well Walter, I believe you're exactly right.  I imagine that, assuming&lt;br&gt;
the molecule is the string-like object in the scene, that if you took&lt;br&gt;
a picture of it at one time, at another time the molecule could have&lt;br&gt;
squiggled to a completely different shape, and since it's probably&lt;br&gt;
floating around in 3D in some liquid, its projected shape (onto a 2D&lt;br&gt;
image) and length could be completely different from one image to the&lt;br&gt;
next.  This change is called "repeatability" and is how this one&lt;br&gt;
molecule specimen changes from one snap of that one molecule to the&lt;br&gt;
next.  There's also something called "reproducibility" which is a&lt;br&gt;
different specimen of the same species of molecule but imaged as a&lt;br&gt;
separate sample on perhaps a different microscope.  So because of all&lt;br&gt;
this, it's possible that the molecule could have different "lengths"&lt;br&gt;
depending on when you snapped the picture because you're seeing just a&lt;br&gt;
2D projection of it.&lt;br&gt;
&lt;br&gt;
And another thing . . . when you take a look at the image he posted,&lt;br&gt;
let's say the "head" of the molecule is that wad of curled up stuff&lt;br&gt;
plus the loop, and the tail is the other end.  Now exactly where does&lt;br&gt;
the tail end?  You can see that it's not so easy to answer.  Maybe it&lt;br&gt;
curls around down below and heads back to the right.  (It's not as&lt;br&gt;
obvious now - I think he replaced the with a smaller version of what&lt;br&gt;
he used to have).  But the tail seems to sort of fade away and it's&lt;br&gt;
not really clear where it ends.  It is sort of a judgement call.  And&lt;br&gt;
what about the head?  Is there a bunch of length there that is all&lt;br&gt;
tangled up into a ball so that you can't really know the "true"&lt;br&gt;
length?&lt;br&gt;
&lt;br&gt;
And Adrian didn't say what kind of precision he needs.  Maybe a fully&lt;br&gt;
automated method with sub-pixel precision is needed, but maybe just&lt;br&gt;
hand-tracing the line is good enough especially if the length changes&lt;br&gt;
a lot from one snapshot to the next.&lt;br&gt;
&lt;br&gt;
Because of all this, it probably doesn't make sense to go overboard&lt;br&gt;
with fancy algorithms to get the length of the molecule in that one&lt;br&gt;
single, specific picture with sub-pixel precision when the "length" of&lt;br&gt;
the molecule may vary by tens or hundreds of pixels from one picture&lt;br&gt;
to the next.&lt;br&gt;
&lt;br&gt;
Hey Adrian, are you ever going to check back here for answers to your&lt;br&gt;
question, and answer some of the issues brought up?&lt;br&gt;
Regards,&lt;br&gt;
ImageAnalyst&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 11 May 2008 23:12:36 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431483</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;g07jfi$afk$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
Roger Stafford &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt;  Note to ImageAnalyst: In my opinion the length of the shape's perimeter &lt;br&gt;
&amp;gt;(presumably divided by 2) is not a reliable measure of what Adrian is seeking &lt;br&gt;
&amp;gt;as the over-all length of a molecule.  Its outline is likely to be a somewhat &lt;br&gt;
&amp;gt;jagged affair as is characteristic of long-chain molecules with differing kinds &lt;br&gt;
&amp;gt;of structures and would tend to give too large and inconsistent a value.&lt;br&gt;
&lt;br&gt;
Hmmm, that triggers the throught that the molecule may have significant&lt;br&gt;
3 dimensional components; unless we have at least two views of it&lt;br&gt;
in different planes, we would not be able to tell whether the molecule&lt;br&gt;
just happens to be shorter in the direction of view, but long into&lt;br&gt;
or out of the direction of view.&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;"The quirks and arbitrariness we observe force us to the&lt;br&gt;
&amp;nbsp;&amp;nbsp;conclusion that ours is not the only universe." -- Walter Kistler&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 11 May 2008 20:04:02 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431465</link>
      <author>Roger Stafford</author>
      <description>"Adrian " &amp;lt;ajr@med.unc.edu&amp;gt; wrote in message &amp;lt;g023qb$j0m&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My name is Adrian Randall and I work in an Electron&lt;br&gt;
&amp;gt; Microscopy lab. I am trying to determine the lengths of&lt;br&gt;
&amp;gt; molecules from images using MATLAB. I have just finished a&lt;br&gt;
&amp;gt; semester of MATLAB, so I'm very familiar with the program. I&lt;br&gt;
&amp;gt; need help coming up with an algorithm for such a program.&lt;br&gt;
&amp;gt; Does anyone have any experience with image analysis that&lt;br&gt;
&amp;gt; could give me a hand? &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Here is a link to what an electron micrograph looks like:&lt;br&gt;
&amp;gt; &lt;a href="http://www.unc.edu/~arandall/image.png"&gt;http://www.unc.edu/~arandall/image.png&lt;/a&gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you in advance for any suggestions!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -Adrian Randall (ajr [at] med.unc.edu) &lt;br&gt;
------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Adrian, there is no denying that your problem is a difficult one and involves &lt;br&gt;
several stages.  In my opinion the most difficult stage comes after you have &lt;br&gt;
successfully processed an image to the point where it is a single connected &lt;br&gt;
black and white image without any false holes within it, giving a good &lt;br&gt;
silhouette of the laid-out molecule.  What I describe here is by no means a &lt;br&gt;
solution but merely an insight into what kinds of problems need to be solved.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Think how human beings would proceed if faced with this problem.  They &lt;br&gt;
would probably start sketching little line segments or arcs which were more &lt;br&gt;
or less tangent to the shape at various points, and then they would begin &lt;br&gt;
drawing a kind of envelope along these lines or curves.  This would hopefully &lt;br&gt;
produce a single curve running along the centered-length of the shape.  &lt;br&gt;
Finally they would probably whip out their handy little arc length tool with the &lt;br&gt;
calibrated wheel at one end and roll it along the total length of the curve to &lt;br&gt;
get its length.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;This should give you an idea of the formidable tasks that await you in this &lt;br&gt;
project if you want to develop a fully automated and reliable answer to your &lt;br&gt;
question.  You will need to find best-fitting line segments or arcs to various &lt;br&gt;
regions of the shape.  You need to be able to connect these into a single &lt;br&gt;
coherent envelope curve along the length of the shape.  Finally you need to &lt;br&gt;
determine the length of this envelope.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Note to ImageAnalyst: In my opinion the length of the shape's perimeter &lt;br&gt;
(presumably divided by 2) is not a reliable measure of what Adrian is seeking &lt;br&gt;
as the over-all length of a molecule.  Its outline is likely to be a somewhat &lt;br&gt;
jagged affair as is characteristic of long-chain molecules with differing kinds &lt;br&gt;
of structures and would tend to give too large and inconsistent a value.  I &lt;br&gt;
think his problem is more difficult than that.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 11 May 2008 17:10:53 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431455</link>
      <author>ImageAnalyst</author>
      <description>On May 9, 2:06=A0pm, "Adrian " &amp;lt;a...@med.unc.edu&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; My name is Adrian Randall and I work in an Electron&lt;br&gt;
&amp;gt; Microscopy lab. I am trying to determine the lengths of&lt;br&gt;
&amp;gt; molecules from images using MATLAB. I have just finished a&lt;br&gt;
&amp;gt; semester of MATLAB, so I'm very familiar with the program. I&lt;br&gt;
&amp;gt; need help coming up with an algorithm for such a program.&lt;br&gt;
&amp;gt; Does anyone have any experience with image analysis that&lt;br&gt;
&amp;gt; could give me a hand?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Here is a link to what an electron micrograph looks like:&lt;a href="http://www.unc.ed="&gt;http://www.unc.ed=&lt;/a&gt;&lt;br&gt;
u/~arandall/image.png&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thank you in advance for any suggestions!&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; -Adrian Randall (ajr [at] med.unc.edu)&lt;br&gt;
&lt;br&gt;
Adrian:&lt;br&gt;
Thanks for posting the image in advance (that's one better than most&lt;br&gt;
people).  I do have nearly 30 years of image analysis experience and&lt;br&gt;
might be able to help you but you didn't say what you were looking for&lt;br&gt;
and I don't recognize what is what in the image.  Is this an atomic&lt;br&gt;
force microscopy image (the only one that I know of that allows you to&lt;br&gt;
see individual atoms)?  Can you have the system imprint a scale bar&lt;br&gt;
onto the image?  You need to do a spatial calibration on the image so&lt;br&gt;
to determine the length of a molecule you first need some sort of&lt;br&gt;
scale bar or other way of knowing how many pixels equal how many real&lt;br&gt;
world unit.  If that molecule is that long squiggle then there are&lt;br&gt;
many ways of finding it.  You could even just manually trace it.  But&lt;br&gt;
then when you have the number of pixels long it is, you'll want to&lt;br&gt;
convert than into nanometers or something.  This is where you'll need&lt;br&gt;
the spatial calibration.&lt;br&gt;
&lt;br&gt;
To find the squiggle, you could try something like a big blurring&lt;br&gt;
(convolution) filter and subtract the original image, threshold, then&lt;br&gt;
clean up a bit (maybe by doing a morphological closing operation to&lt;br&gt;
make sure the squiggle is not in multiple pieces or a smaller median&lt;br&gt;
filter to throw out small particles), then bwlabel() and regionprops()&lt;br&gt;
and toss out all blobs except the blob with the largest area.  Then&lt;br&gt;
look at its perimeter property.  Then multiply by your spatial&lt;br&gt;
calibration factor.  That's what I'd try first and then I'd modify the&lt;br&gt;
algorithm depending on the quality of results I achieved.&lt;br&gt;
Regards,&lt;br&gt;
ImageAnalyst&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 09 May 2008 19:35:02 -0400</pubDate>
      <title>Re: Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431289</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;g023qb$j0m$1@fred.mathworks.com&amp;gt;, Adrian  &amp;lt;ajr@med.unc.edu&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt;My name is Adrian Randall and I work in an Electron&lt;br&gt;
&amp;gt;Microscopy lab. I am trying to determine the lengths of&lt;br&gt;
&amp;gt;molecules from images using MATLAB.&lt;br&gt;
&lt;br&gt;
I had a glance at the image, and the first question in my mind&lt;br&gt;
was whether you want the length as folded (e.g., the length&lt;br&gt;
of an appropriate oriented bounded box), or if you want the&lt;br&gt;
length as if were unfolded (length of the perimeter) ? If as if&lt;br&gt;
unfolded, then how should the loop at one end be treated, as&lt;br&gt;
a circle whose diameter is to be taken, or the circumference&lt;br&gt;
(af if the loop were stretched out to its maximum length) ?&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;"Man's life is but a jest,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;A dream, a shadow, bubble, air, a vapor at the best."&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-- George Walter Thornbury&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 09 May 2008 18:06:03 -0400</pubDate>
      <title>Need algorithm help: molecule length from an image</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/169016#431285</link>
      <author>Adrian </author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
My name is Adrian Randall and I work in an Electron&lt;br&gt;
Microscopy lab. I am trying to determine the lengths of&lt;br&gt;
molecules from images using MATLAB. I have just finished a&lt;br&gt;
semester of MATLAB, so I'm very familiar with the program. I&lt;br&gt;
need help coming up with an algorithm for such a program.&lt;br&gt;
Does anyone have any experience with image analysis that&lt;br&gt;
could give me a hand? &lt;br&gt;
&lt;br&gt;
Here is a link to what an electron micrograph looks like:&lt;br&gt;
&lt;a href="http://www.unc.edu/~arandall/image.png"&gt;http://www.unc.edu/~arandall/image.png&lt;/a&gt; &lt;br&gt;
&lt;br&gt;
Thank you in advance for any suggestions!&lt;br&gt;
&lt;br&gt;
-Adrian Randall (ajr [at] med.unc.edu) &lt;br&gt;
</description>
    </item>
  </channel>
</rss>
