automate distance measure of uneven surface

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

automate distance measure of uneven surface

daschneider9
Greetings,

I need to process a large image set of masks (like the one attached) which represent a tissue cross section (lower white region) and surrounding airspace (upper black region). I've written macros to get me this far but I don't know if there is already an existing automatic way to measure the distance of the surface.

Note, as in this example image, that there are occasional white-black interfaces not to be included. These occur in the non-tissue space (in the image the single white blotch in upper right quadrant) and those holes in the deeper tissue space (one about mid-lower left side, another on low right side). All images are oriented in this way to start. I'm not concerned about not catching the bit of surface that is just below the left edge boundary.  If it will make for a much simpler solution, I could remove the bits of white-in-black and black-in-white not representing the surface to be measured. But as you can see, hand drawing the surface with a line for a hundred or more images is not feasible nor likely to be accurate.

Is there a plugin or function already out there that I can use (preferably in a macro or batch process) to get this done?

Thank you for your assistance,

Dave

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Measure length of surface white boundary.tif (872K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: automate distance measure of uneven surface

Herbie
Good day Dave,

if this

"hand drawing the surface with a line"

is what you want to avoid, did you try "Find Edges"?

However, drawing a border line is no "distance measure".
So what is it that you really need?

A bit clueless

Herbie

::::::::::::::::::::::::::::::::::::::::::::::::
Am 25.02.16 um 18:06 schrieb David A. Schneider:

> Greetings,
>
> I need to process a large image set of masks (like the one attached)
> which represent a tissue cross section (lower white region) and
> surrounding airspace (upper black region). I've written macros to get
> me this far but I don't know if there is already an existing
> automatic way to measure the distance of the surface.
>
> Note, as in this example image, that there are occasional white-black
> interfaces not to be included. These occur in the non-tissue space
> (in the image the single white blotch in upper right quadrant) and
> those holes in the deeper tissue space (one about mid-lower left
> side, another on low right side). All images are oriented in this way
> to start. I'm not concerned about not catching the bit of surface
> that is just below the left edge boundary.  If it will make for a
> much simpler solution, I could remove the bits of white-in-black and
> black-in-white not representing the surface to be measured. But as
> you can see, hand drawing the surface with a line for a hundred or
> more images is not feasible nor likely to be accurate.
>
> Is there a plugin or function already out there that I can use
> (preferably in a macro or batch process) to get this done?
>
> Thank you for your assistance,
>
> Dave
>
> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: automate distance measure of uneven surface

daschneider9
In reply to this post by daschneider9
Herbie, Thank you for your reply and sorry if I wasn't clear.

What I would like is the distance of that surface edge. 'Find edges' will produce an image of the edge in question, but how do I get its length? I can use the magic wand to select the found edge, but the measure command doesn't seem to include a distance measure for this type of shape.

I must be dense, seems like this should be pretty easy.

Thanks again.

Dave

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: automate distance measure of uneven surface

Herbie
Sorry Dave,

distance could mean a lot but length of the line appears reasonably
clear to me.

If you really have a binary image (the one you've posted is not!) then
counting the pixels of the _skeletonized_ and _selected_ edge will give
you the length.
(I measure a length of 1760 pixels, i.e. about 587.6 microns)

That said, it remains the problem of selecting the line... (By hand you
can use the Wand-tool.)

You need to write an ImageJ-macro that is facilitated by recording the
steps described above. The selection however may become difficult, if
you don't have a good estimate of the border position (approximate
height position in pixels). For the example image
        doWand( 0, 100 );
works well.

HTH

Herbie

::::::::::::::::::::::::::::::::::::::::::::::::
Am 25.02.16 um 19:54 schrieb David A. Schneider:

> Herbie, Thank you for your reply and sorry if I wasn't clear.
>
> What I would like is the distance of that surface edge. 'Find edges'
> will produce an image of the edge in question, but how do I get its
> length? I can use the magic wand to select the found edge, but the
> measure command doesn't seem to include a distance measure for this
> type of shape.
>
> I must be dense, seems like this should be pretty easy.
>
> Thanks again.
>
> Dave
>
> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: automate distance measure of uneven surface

Michael Schmid
In reply to this post by daschneider9
Hi David,

you can use the wand tool to get the outline of the airspace, then measure the perimeter and subtract the length at the image border. Unfortunately this will be very inaccurate because of the pixelated edge; the wand will follow the pixel outlines.

Better have a short macro that takes the coordinates with getSelectionCoordinates, then eliminate those at the border (typically, the last 3 points, unless you have a particle touching the 'air' borders).
Then create a new segmented line with these coordinates or a subset of them (e.g. each 2nd or 3rd one, or moving averages, for some smoothing); see the makeSelection command with type "polyline".

A very simple version of the macro, without smoothing, is like this, but it will follow the pixel outlines:

setAutoThreshold("Default");
run("Convert to Mask"); //make sure it's a binary image
doWand(0, 0, 0, "Legacy");  //assumes (0,0) is air
getSelectionCoordinates(x,y);
newLength = x.length-3;
x2 = Array.trim(x, newLength);
y2 = Array.trim(y, newLength);
makeSelection("Polyline", x2, y2);
run("Set Measurements...", "perimeter redirect=None decimal=3");
run("Measure");


Michael
________________________________________________________________
On Feb 25, 2016, at 18:06, David A. Schneider wrote:

> Greetings,
>
> I need to process a large image set of masks (like the one attached) which represent a tissue cross section (lower white region) and surrounding airspace (upper black region). I've written macros to get me this far but I don't know if there is already an existing automatic way to measure the distance of the surface.
>
> Note, as in this example image, that there are occasional white-black interfaces not to be included. These occur in the non-tissue space (in the image the single white blotch in upper right quadrant) and those holes in the deeper tissue space (one about mid-lower left side, another on low right side). All images are oriented in this way to start. I'm not concerned about not catching the bit of surface that is just below the left edge boundary.  If it will make for a much simpler solution, I could remove the bits of white-in-black and black-in-white not representing the surface to be measured. But as you can see, hand drawing the surface with a line for a hundred or more images is not feasible nor likely to be accurate.
>
> Is there a plugin or function already out there that I can use (preferably in a macro or batch process) to get this done?
>
> Thank you for your assistance,
>
> Dave

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: automate distance measure of uneven surface

Herbie
Dear Dave,

I must admit that Michael's length estimate is much better than the
simple one that I've proposed. Mine may be regarded as a a lower bound
estimate...

Best

Herbie

::::::::::::::::::::::::::::::::::::::::::::
Am 25.02.16 um 21:36 schrieb Michael Schmid:

> Hi David,
>
> you can use the wand tool to get the outline of the airspace, then
> measure the perimeter and subtract the length at the image border.
> Unfortunately this will be very inaccurate because of the pixelated
> edge; the wand will follow the pixel outlines.
>
> Better have a short macro that takes the coordinates with
> getSelectionCoordinates, then eliminate those at the border
> (typically, the last 3 points, unless you have a particle touching
> the 'air' borders). Then create a new segmented line with these
> coordinates or a subset of them (e.g. each 2nd or 3rd one, or moving
> averages, for some smoothing); see the makeSelection command with
> type "polyline".
>
> A very simple version of the macro, without smoothing, is like this,
> but it will follow the pixel outlines:
>
> setAutoThreshold("Default"); run("Convert to Mask"); //make sure it's
> a binary image doWand(0, 0, 0, "Legacy");  //assumes (0,0) is air
> getSelectionCoordinates(x,y); newLength = x.length-3; x2 =
> Array.trim(x, newLength); y2 = Array.trim(y, newLength);
> makeSelection("Polyline", x2, y2); run("Set Measurements...",
> "perimeter redirect=None decimal=3"); run("Measure");
>
>
> Michael
> ________________________________________________________________ On
> Feb 25, 2016, at 18:06, David A. Schneider wrote:
>
>> Greetings,
>>
>> I need to process a large image set of masks (like the one
>> attached) which represent a tissue cross section (lower white
>> region) and surrounding airspace (upper black region). I've written
>> macros to get me this far but I don't know if there is already an
>> existing automatic way to measure the distance of the surface.
>>
>> Note, as in this example image, that there are occasional
>> white-black interfaces not to be included. These occur in the
>> non-tissue space (in the image the single white blotch in upper
>> right quadrant) and those holes in the deeper tissue space (one
>> about mid-lower left side, another on low right side). All images
>> are oriented in this way to start. I'm not concerned about not
>> catching the bit of surface that is just below the left edge
>> boundary.  If it will make for a much simpler solution, I could
>> remove the bits of white-in-black and black-in-white not
>> representing the surface to be measured. But as you can see, hand
>> drawing the surface with a line for a hundred or more images is not
>> feasible nor likely to be accurate.
>>
>> Is there a plugin or function already out there that I can use
>> (preferably in a macro or batch process) to get this done?
>>
>> Thank you for your assistance,
>>
>> Dave
>
> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: automate distance measure of uneven surface

daschneider9
In reply to this post by Michael Schmid
Michael,

The macro is working very well and you've taught me a couple new things, too.

Thank you for your time and advice.

Dave
Reply | Threaded
Open this post in threaded view
|

Re: automate distance measure of uneven surface

daschneider9
In reply to this post by Herbie
Herbie,

Greatly appreciate your advice and time on this, too. I am having good success with Michael's suggestion.

Best wishes to all.
Dave
Reply | Threaded
Open this post in threaded view
|

Re: automate distance measure of uneven surface

Kenneth Sloan-2
In reply to this post by Herbie
As usual, my approach would involve writing Java code.  Computing a “length” of a perimeter is tricky, because it depends on the size of the pixels.  Consider the famous paper “How long is the coastline of Great Britain?”

My first attempt would be to count the BLACK pixels that have at least 1 WHITE neighbor.
This isn’t quite right, but I would validate this against known images to see if it matters, to you.  The next twiddle might be to count a BLACK pixel with 1 WHITE neighbor as contributing 1.0 to the length, and BLACK pixels with more than 1 WHITE neighbors as contributions 1.4 to the length.  I’m not even sure that that’s correct - but, again, I would try it on known shapes to see if it’s “close enough for gov’t work”.

There may be a clever way to do this as a macro, but it’s so simple to do in Java that I wouldn’t look any further.

There are more complicated ways to do this - that probably give more precise answers.  If necessary, I would crawl around the perimeter, selecting boundary pixels and then imposing a distance constraint (don’t try to count every pixel, because that gives unwanted tiny-scale pieces - perhaps require the next point to be something like 5 pixels distant from the previous one.  That is - automatically sketch the boundary, and compute the length of the sketch.  The image you showed looks amenable to this approach.

The downside is: this is a moderately difficult Java program to write, if you haven’t written a lot of similar ones, before.  I would classify it as a reasonable class project for an undergraduate CS major (writing it, debugging it, validating it, wrapping it up with proper documentation, etc.).

--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.




> On Feb 26, 2016, at 03:22 , Herbie <[hidden email]> wrote:
>
> Dear Dave,
>
> I must admit that Michael's length estimate is much better than the simple one that I've proposed. Mine may be regarded as a a lower bound estimate...
>
> Best
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::::::::::::
> Am 25.02.16 um 21:36 schrieb Michael Schmid:
>> Hi David,
>>
>> you can use the wand tool to get the outline of the airspace, then
>> measure the perimeter and subtract the length at the image border.
>> Unfortunately this will be very inaccurate because of the pixelated
>> edge; the wand will follow the pixel outlines.
>>
>> Better have a short macro that takes the coordinates with
>> getSelectionCoordinates, then eliminate those at the border
>> (typically, the last 3 points, unless you have a particle touching
>> the 'air' borders). Then create a new segmented line with these
>> coordinates or a subset of them (e.g. each 2nd or 3rd one, or moving
>> averages, for some smoothing); see the makeSelection command with
>> type "polyline".
>>
>> A very simple version of the macro, without smoothing, is like this,
>> but it will follow the pixel outlines:
>>
>> setAutoThreshold("Default"); run("Convert to Mask"); //make sure it's
>> a binary image doWand(0, 0, 0, "Legacy");  //assumes (0,0) is air
>> getSelectionCoordinates(x,y); newLength = x.length-3; x2 =
>> Array.trim(x, newLength); y2 = Array.trim(y, newLength);
>> makeSelection("Polyline", x2, y2); run("Set Measurements...",
>> "perimeter redirect=None decimal=3"); run("Measure");
>>
>>
>> Michael
>> ________________________________________________________________ On
>> Feb 25, 2016, at 18:06, David A. Schneider wrote:
>>
>>> Greetings,
>>>
>>> I need to process a large image set of masks (like the one
>>> attached) which represent a tissue cross section (lower white
>>> region) and surrounding airspace (upper black region). I've written
>>> macros to get me this far but I don't know if there is already an
>>> existing automatic way to measure the distance of the surface.
>>>
>>> Note, as in this example image, that there are occasional
>>> white-black interfaces not to be included. These occur in the
>>> non-tissue space (in the image the single white blotch in upper
>>> right quadrant) and those holes in the deeper tissue space (one
>>> about mid-lower left side, another on low right side). All images
>>> are oriented in this way to start. I'm not concerned about not
>>> catching the bit of surface that is just below the left edge
>>> boundary.  If it will make for a much simpler solution, I could
>>> remove the bits of white-in-black and black-in-white not
>>> representing the surface to be measured. But as you can see, hand
>>> drawing the surface with a line for a hundred or more images is not
>>> feasible nor likely to be accurate.
>>>
>>> Is there a plugin or function already out there that I can use
>>> (preferably in a macro or batch process) to get this done?
>>>
>>> Thank you for your assistance,
>>>
>>> Dave
>>
>> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html