Path: news.mathworks.com!not-for-mail
From: "Adrian " <ajr@med.unc.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Need algorithm help: molecule length from an image
Date: Tue, 13 May 2008 19:08:03 +0000 (UTC)
Organization: University of North Carolina
Lines: 43
Message-ID: <g0couj$np$1@fred.mathworks.com>
References: <g023qb$j0m$1@fred.mathworks.com>
Reply-To: "Adrian " <ajr@med.unc.edu>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210705683 761 172.30.248.37 (13 May 2008 19:08:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 May 2008 19:08:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1371482
Xref: news.mathworks.com comp.soft-sys.matlab:468226


Thank you all for your insight into the matter. Sorry for
the lack of clarification for the image I linked to: the
squiggly line in the middle is in fact the molecule.
Everything else is background. The image is a transmission
electron micrograph, so it's 2D and fixed.

The way that we do length analysis is by manually drawing
along the molecule using a mouse and some software that came
with the electron microscope. As you can image, this is
somewhat inaccurate and tedious, especially if one is
scoring hundreds of molecules. In addition, for the project
I am working on, length analysis is the centerpiece, so I
want to have data as accurate as possible. 

I didn't include a scale bar - my apologies. I wanted to
isolate only one molecule to make the problem easier to
solve,  and forgot to include the scale. There is a scale
that converts pixel length to actual distance that I know
how to use, so the only problem is finding the pixel length. 

This is a method I have come up with from using your
suggestions. 

1) Find the average pixel shade (between 0 and 255)
2) Remove all pixels that are below the threshold (remove
the darker background).
3) Set the remaining pixels equal to 1; all other pixels
equal to 0.
4) Scan the image from left to right and then "walk" along
areas that are labeled as "1". If the program finds a pixel
that is labeled "1", look toward the 8 surrounding pixels to
find if there is another pixel labeled "1". If so, continue
to look for pixels labeled "1" (e.g., keep "walking" along
the molecule), and if possible, continue "walking" in the
same direction as previously (to prevent the "walker" from
going back to where it came from). Then, after walking along
the molecule, label all of the points it walked on as "0" so
the scanner won't walk there again. 
5) Output the length measurement as pixel and convert to nm
by looking at the scale.

Does this seem reasonable? Thank you very much for the
discussion..