Macro for automatically detecting/setting a scale

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro for automatically detecting/setting a scale

DavidG
Hi,

I'm just getting started using ImageJ for some leaf area analysis and have a
question about automatically setting the scale for multiple images.  I
couldn't find another thread about this specific issue, but I apologize if
it has been addressed previously.

I need to analyze the areas of leaves in a large batch of images.  The
images will be taken against a uniform background containing an object of
known size for scale.  My dilemma comes from the fact that it will not be
possible for all of the images to be taken from a uniform distance, causing
the scale to differ slightly from image to image.

Is it possible to create a macro that can detect an object of known size
within each image and then set the scale accordingly?  Ideally, I would like
to be able to process many images in series. Any help or suggestions are
appreciated!

I've been really impressed looking through the ImageJ community's posts the
past few days and I'm excited at all of the possible functions!

Thanks,
David





--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Macro for automatically detecting/setting a scale

Brandon Hurr
David,

Absolutely you can do this. I do this all the time, but I use a color chart
as a size reference. In the past we've used an oblong reference that was
blue so we could pick it out from the white, black, and gray backgrounds we
were using at the time.
What you do is you measure your scale. Say it is 3.14 centimeters long and
1 cm wide.
You then paint it a color that separates it from your background and your
objects of interest (leaves).
Then you run color segmentation to find your object and measure it in terms
of pixels in the image.  I think I use feret's distance to get the longest
dimension of the scale. Then you can use that to compute your scaling
factor.

Rather than set the pixel scale for each image in ImageJ, I typically apply
this transformation to the data that is output, but I know others prefer
the other way. I do this because you have to make sure you reset the scale
after every loop and it's easy to do the transformation on each object (I
typically do this in R across many variables, but ImageJ can do this
quickly enough too).

Are you starting from nothing?
What do your images look like?

B





On Thu, Sep 27, 2018 at 4:22 PM DavidG <[hidden email]> wrote:

> Hi,
>
> I'm just getting started using ImageJ for some leaf area analysis and have
> a
> question about automatically setting the scale for multiple images.  I
> couldn't find another thread about this specific issue, but I apologize if
> it has been addressed previously.
>
> I need to analyze the areas of leaves in a large batch of images.  The
> images will be taken against a uniform background containing an object of
> known size for scale.  My dilemma comes from the fact that it will not be
> possible for all of the images to be taken from a uniform distance, causing
> the scale to differ slightly from image to image.
>
> Is it possible to create a macro that can detect an object of known size
> within each image and then set the scale accordingly?  Ideally, I would
> like
> to be able to process many images in series. Any help or suggestions are
> appreciated!
>
> I've been really impressed looking through the ImageJ community's posts the
> past few days and I'm excited at all of the possible functions!
>
> Thanks,
> David
>
>
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> 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: Macro for automatically detecting/setting a scale

DavidG
Brandon,

Thanks so much for the quick response!  I really am starting from nothing
when it comes to ImageJ.  My background is in molecular biology, so I
haven't had much exposure to computer science yet.    The project is sort of
a citizen science project.  Participants will be all be given a grid printed
on a poster on which they will arrange the leaves before taking pictures and
sending them in.  The poster will include a scale/object from which we will
set the scale.  

I think I follow along with your explanation for setting the scale for a
single image in your first paragraph, but let me make sure I'm following
along with the second part.  Please tell me if I am misunderstanding.

It sounds like it would be difficult to write a script that will have to
reset the scale before analyzing each new image.  But, if I set it up to
take a measurement of the length of the object being used for scale and the
area of the leaf (both measurements in pixels) and outputting those values
for each individual image, then a calculation could be done for leaf area
taking into account the unique scaling factor for each image?

I think this method makes sense and I'll see if I can get it to work this
afternoon.  Thanks again!

David



--
Sent from: http://imagej.1557.x6.nabble.com/

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