area calculations - discrepancy in the manual and batch results

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

area calculations - discrepancy in the manual and batch results

ram prasad
Hi all,

I'm trying to get the number of black coloured pixels on either side of a
line, which will be drawn by me using the line selection tool.

My idea was to generate a macro that would,

1) Select the line tool
2) Wait for my input
3) Rotate my line by 90degrees.
3) Calculate slope and extrapolate the line to the edges of my image.
4) Make a polygon from the line coordinates and add it to ROI
5) Inverse my selection and add it to ROI
6) Duplicate the original image
7) Select ROI 0
8) Set foreground colour to blue
9) Fill the other slice with foreground colour.
10) Use thresholder to identify black pixels and make a selection
11) Restore selction on the original image and calculate the area of the
selection.
12) Repeat  6-11 for ROI 1.

When I implement this approach manually I get the expected area(approx 140k
pixels). However, the macro doesn't seem to work as the area calculations
seems to be in the range of (2M pixels) and I'm not sure why. Any pointers
are definitely appreciated.

Herewith, I'm attaching my script and a sample image for your reference.
The line in the image is where I would like to partition my image into two
halves(output of step 3).

Let me know if you need more information.

Thanks,
Ram

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

split_calc.txt (4K) Download Attachment
ed_10-2-2.jpg (483K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: area calculations - discrepancy in the manual and batch results

ram prasad
Hi all,

I just realized that I had sent a different version of my script from the one I was using for testing. Please find the script attached.

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

split_calc.txt (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: area calculations - discrepancy in the manual and batch results

Brandon Hurr
The logic in your workflow doesn't make sense here:
1) Select the line tool
2) Wait for my input
3) Rotate my line by 90 degrees.
3) Calculate slope and extrapolate the line to the edges of my image.
4) Make a polygon from the line coordinates and add it to ROI
5) Inverse my selection and add it to ROI
6) Duplicate the original image
7) Select ROI 0
8) Set foreground colour to blue
9) Fill the other slice with foreground colour.
10) Use thresholder to identify black pixels and make a selection
11) Restore selction on the original image and calculate the area of the
selection.
12) Repeat  6-11 for ROI 1.

You don't need to perpendicular line. You need the continuation of your
line to the edges of the image. I already gave you code for steps 1-5 and
it did work (but I fixed a potential bug in it related to completely
vertical line selections).

Also, you've got it set up for potentially going into batch mode. When you
do that, the image will not be displayed and your user will not be able to
input the initial line. If you want to loop through a series of images,
that's different than just putting it in batchmode.

I've changed some things and functionalized your segmentation (since it's
the same) and it seems to be working for me. Can you test again with this
and report back?

HTH,
B

On Fri, Jan 22, 2016 at 5:32 AM, Ramprasad Neethiraj <[hidden email]>
wrote:

> Hi all,
>
> I just realized that I had sent a different version of my script from the
> one I was using for testing. Please find the script attached.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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

split_calc.txt (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: area calculations - discrepancy in the manual and batch results

ram prasad
Hi Brandon,

Thank you very much for your reply. I really appreciate it.

A line was drawn by me on the vein which was then perpendicular'd to give
that blue line you see on that image. So just to make it more convenient, I
included that rotate line step in my script so that all I had to do was to
give it the first line and then let the tool rotate it by 90.

And yes, this script does exactly what I wanted it to do. I was under the
impression that looping through a series of images and putting it in the
batchmode are one and the same thing. Is there a way to do that? Almost
every hit I see on google talks about running things in batchmode or
running it as an image sequence but neither works for me.

Cheers,
Ram


On Sun, Jan 24, 2016 at 7:07 AM, Brandon Hurr <[hidden email]>
wrote:

> The logic in your workflow doesn't make sense here:
> 1) Select the line tool
> 2) Wait for my input
> 3) Rotate my line by 90 degrees.
> 3) Calculate slope and extrapolate the line to the edges of my image.
> 4) Make a polygon from the line coordinates and add it to ROI
> 5) Inverse my selection and add it to ROI
> 6) Duplicate the original image
> 7) Select ROI 0
> 8) Set foreground colour to blue
> 9) Fill the other slice with foreground colour.
> 10) Use thresholder to identify black pixels and make a selection
> 11) Restore selction on the original image and calculate the area of the
> selection.
> 12) Repeat  6-11 for ROI 1.
>
> You don't need to perpendicular line. You need the continuation of your
> line to the edges of the image. I already gave you code for steps 1-5 and
> it did work (but I fixed a potential bug in it related to completely
> vertical line selections).
>
> Also, you've got it set up for potentially going into batch mode. When you
> do that, the image will not be displayed and your user will not be able to
> input the initial line. If you want to loop through a series of images,
> that's different than just putting it in batchmode.
>
> I've changed some things and functionalized your segmentation (since it's
> the same) and it seems to be working for me. Can you test again with this
> and report back?
>
> HTH,
> B
>
> On Fri, Jan 22, 2016 at 5:32 AM, Ramprasad Neethiraj <[hidden email]
> >
> wrote:
>
> > Hi all,
> >
> > I just realized that I had sent a different version of my script from the
> > one I was using for testing. Please find the script attached.
> >
> > --
> > 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
Reply | Threaded
Open this post in threaded view
|

Re: area calculations - discrepancy in the manual and batch results

Brandon Hurr
Ram,

Your previously attached code has no perpendicular calculations in it.
Also, the approach you've laid out seems dangerous to me because given a
line (slope + intercept) there are infinite perpendicular lines. How are
you anchoring it? Are you predrawing your dark blue lines and then drawing
the line perpendicular to that?

Attached I've included the ability to select a folder and loop through that
folder. I've also included a results table that stores the area to the
right and left of your line that are "black" pixels as defined by your
color thresholding step.

If you can explain better why you want to draw a perpendicular line, and
how you would anchor that line, I might be able to adapt the macro to that.
I have recently developed code for computing perpendiculars but relative to
the midpoint of the drawn line, but this code doesn't seem to apply in your
situation (in my opinion).


HTH,
B


On Sun, Jan 24, 2016 at 4:25 PM, ram prasad <[hidden email]> wrote:

> Hi Brandon,
>
> Thank you very much for your reply. I really appreciate it.
>
> A line was drawn by me on the vein which was then perpendicular'd to give
> that blue line you see on that image. So just to make it more convenient, I
> included that rotate line step in my script so that all I had to do was to
> give it the first line and then let the tool rotate it by 90.
>
> And yes, this script does exactly what I wanted it to do. I was under the
> impression that looping through a series of images and putting it in the
> batchmode are one and the same thing. Is there a way to do that? Almost
> every hit I see on google talks about running things in batchmode or
> running it as an image sequence but neither works for me.
>
> Cheers,
> Ram
>
>
> On Sun, Jan 24, 2016 at 7:07 AM, Brandon Hurr <[hidden email]>
> wrote:
>
> > The logic in your workflow doesn't make sense here:
> > 1) Select the line tool
> > 2) Wait for my input
> > 3) Rotate my line by 90 degrees.
> > 3) Calculate slope and extrapolate the line to the edges of my image.
> > 4) Make a polygon from the line coordinates and add it to ROI
> > 5) Inverse my selection and add it to ROI
> > 6) Duplicate the original image
> > 7) Select ROI 0
> > 8) Set foreground colour to blue
> > 9) Fill the other slice with foreground colour.
> > 10) Use thresholder to identify black pixels and make a selection
> > 11) Restore selction on the original image and calculate the area of the
> > selection.
> > 12) Repeat  6-11 for ROI 1.
> >
> > You don't need to perpendicular line. You need the continuation of your
> > line to the edges of the image. I already gave you code for steps 1-5 and
> > it did work (but I fixed a potential bug in it related to completely
> > vertical line selections).
> >
> > Also, you've got it set up for potentially going into batch mode. When
> you
> > do that, the image will not be displayed and your user will not be able
> to
> > input the initial line. If you want to loop through a series of images,
> > that's different than just putting it in batchmode.
> >
> > I've changed some things and functionalized your segmentation (since it's
> > the same) and it seems to be working for me. Can you test again with this
> > and report back?
> >
> > HTH,
> > B
> >
> > On Fri, Jan 22, 2016 at 5:32 AM, Ramprasad Neethiraj <
> [hidden email]
> > >
> > wrote:
> >
> > > Hi all,
> > >
> > > I just realized that I had sent a different version of my script from
> the
> > > one I was using for testing. Please find the script attached.
> > >
> > > --
> > > 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
>
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

split_calc2.txt (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: area calculations - discrepancy in the manual and batch results

ram prasad
HI Brandon,

Thank you very much for the script. Works like a charm.

As for the perpendicular line, I'm trying to draw a line perpendicular to
the central vein. To achieve that, first, I draw a line as shown in
step1.png (attached) and then rotate the selection around the midpoint by
90degrees to get step2.png (attached). So if I just draw the first line and
then ask the macro to rotate it by 90degress, that should work, no?

Cheers,
Ram

On Mon, Jan 25, 2016 at 6:38 PM, Brandon Hurr <[hidden email]>
wrote:

> Ram,
>
> Your previously attached code has no perpendicular calculations in it.
> Also, the approach you've laid out seems dangerous to me because given a
> line (slope + intercept) there are infinite perpendicular lines. How are
> you anchoring it? Are you predrawing your dark blue lines and then drawing
> the line perpendicular to that?
>
> Attached I've included the ability to select a folder and loop through that
> folder. I've also included a results table that stores the area to the
> right and left of your line that are "black" pixels as defined by your
> color thresholding step.
>
> If you can explain better why you want to draw a perpendicular line, and
> how you would anchor that line, I might be able to adapt the macro to that.
> I have recently developed code for computing perpendiculars but relative to
> the midpoint of the drawn line, but this code doesn't seem to apply in your
> situation (in my opinion).
>
>
> HTH,
> B
>
>
> On Sun, Jan 24, 2016 at 4:25 PM, ram prasad <[hidden email]> wrote:
>
> > Hi Brandon,
> >
> > Thank you very much for your reply. I really appreciate it.
> >
> > A line was drawn by me on the vein which was then perpendicular'd to give
> > that blue line you see on that image. So just to make it more
> convenient, I
> > included that rotate line step in my script so that all I had to do was
> to
> > give it the first line and then let the tool rotate it by 90.
> >
> > And yes, this script does exactly what I wanted it to do. I was under the
> > impression that looping through a series of images and putting it in the
> > batchmode are one and the same thing. Is there a way to do that? Almost
> > every hit I see on google talks about running things in batchmode or
> > running it as an image sequence but neither works for me.
> >
> > Cheers,
> > Ram
> >
> >
> > On Sun, Jan 24, 2016 at 7:07 AM, Brandon Hurr <[hidden email]>
> > wrote:
> >
> > > The logic in your workflow doesn't make sense here:
> > > 1) Select the line tool
> > > 2) Wait for my input
> > > 3) Rotate my line by 90 degrees.
> > > 3) Calculate slope and extrapolate the line to the edges of my image.
> > > 4) Make a polygon from the line coordinates and add it to ROI
> > > 5) Inverse my selection and add it to ROI
> > > 6) Duplicate the original image
> > > 7) Select ROI 0
> > > 8) Set foreground colour to blue
> > > 9) Fill the other slice with foreground colour.
> > > 10) Use thresholder to identify black pixels and make a selection
> > > 11) Restore selction on the original image and calculate the area of
> the
> > > selection.
> > > 12) Repeat  6-11 for ROI 1.
> > >
> > > You don't need to perpendicular line. You need the continuation of your
> > > line to the edges of the image. I already gave you code for steps 1-5
> and
> > > it did work (but I fixed a potential bug in it related to completely
> > > vertical line selections).
> > >
> > > Also, you've got it set up for potentially going into batch mode. When
> > you
> > > do that, the image will not be displayed and your user will not be able
> > to
> > > input the initial line. If you want to loop through a series of images,
> > > that's different than just putting it in batchmode.
> > >
> > > I've changed some things and functionalized your segmentation (since
> it's
> > > the same) and it seems to be working for me. Can you test again with
> this
> > > and report back?
> > >
> > > HTH,
> > > B
> > >
> > > On Fri, Jan 22, 2016 at 5:32 AM, Ramprasad Neethiraj <
> > [hidden email]
> > > >
> > > wrote:
> > >
> > > > Hi all,
> > > >
> > > > I just realized that I had sent a different version of my script from
> > the
> > > > one I was using for testing. Please find the script attached.
> > > >
> > > > --
> > > > 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
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

step1.png (1M) Download Attachment
step2.png (1M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: area calculations - discrepancy in the manual and batch results

Brandon Hurr
Ram

Yes that should work very well. Just add the one line after the user input
to rotate and it should be fine.

I think it's run("Rotate...", 90); but you should record it and make sure.

B
On Tue, Jan 26, 2016 at 10:22 ram prasad <[hidden email]> wrote:

> HI Brandon,
>
> Thank you very much for the script. Works like a charm.
>
> As for the perpendicular line, I'm trying to draw a line perpendicular to
> the central vein. To achieve that, first, I draw a line as shown in
> step1.png (attached) and then rotate the selection around the midpoint by
> 90degrees to get step2.png (attached). So if I just draw the first line and
> then ask the macro to rotate it by 90degress, that should work, no?
>
> Cheers,
> Ram
>
> On Mon, Jan 25, 2016 at 6:38 PM, Brandon Hurr <[hidden email]>
> wrote:
>
> > Ram,
> >
> > Your previously attached code has no perpendicular calculations in it.
> > Also, the approach you've laid out seems dangerous to me because given a
> > line (slope + intercept) there are infinite perpendicular lines. How are
> > you anchoring it? Are you predrawing your dark blue lines and then
> drawing
> > the line perpendicular to that?
> >
> > Attached I've included the ability to select a folder and loop through
> that
> > folder. I've also included a results table that stores the area to the
> > right and left of your line that are "black" pixels as defined by your
> > color thresholding step.
> >
> > If you can explain better why you want to draw a perpendicular line, and
> > how you would anchor that line, I might be able to adapt the macro to
> that.
> > I have recently developed code for computing perpendiculars but relative
> to
> > the midpoint of the drawn line, but this code doesn't seem to apply in
> your
> > situation (in my opinion).
> >
> >
> > HTH,
> > B
> >
> >
> > On Sun, Jan 24, 2016 at 4:25 PM, ram prasad <[hidden email]>
> wrote:
> >
> > > Hi Brandon,
> > >
> > > Thank you very much for your reply. I really appreciate it.
> > >
> > > A line was drawn by me on the vein which was then perpendicular'd to
> give
> > > that blue line you see on that image. So just to make it more
> > convenient, I
> > > included that rotate line step in my script so that all I had to do was
> > to
> > > give it the first line and then let the tool rotate it by 90.
> > >
> > > And yes, this script does exactly what I wanted it to do. I was under
> the
> > > impression that looping through a series of images and putting it in
> the
> > > batchmode are one and the same thing. Is there a way to do that? Almost
> > > every hit I see on google talks about running things in batchmode or
> > > running it as an image sequence but neither works for me.
> > >
> > > Cheers,
> > > Ram
> > >
> > >
> > > On Sun, Jan 24, 2016 at 7:07 AM, Brandon Hurr <[hidden email]>
> > > wrote:
> > >
> > > > The logic in your workflow doesn't make sense here:
> > > > 1) Select the line tool
> > > > 2) Wait for my input
> > > > 3) Rotate my line by 90 degrees.
> > > > 3) Calculate slope and extrapolate the line to the edges of my image.
> > > > 4) Make a polygon from the line coordinates and add it to ROI
> > > > 5) Inverse my selection and add it to ROI
> > > > 6) Duplicate the original image
> > > > 7) Select ROI 0
> > > > 8) Set foreground colour to blue
> > > > 9) Fill the other slice with foreground colour.
> > > > 10) Use thresholder to identify black pixels and make a selection
> > > > 11) Restore selction on the original image and calculate the area of
> > the
> > > > selection.
> > > > 12) Repeat  6-11 for ROI 1.
> > > >
> > > > You don't need to perpendicular line. You need the continuation of
> your
> > > > line to the edges of the image. I already gave you code for steps 1-5
> > and
> > > > it did work (but I fixed a potential bug in it related to completely
> > > > vertical line selections).
> > > >
> > > > Also, you've got it set up for potentially going into batch mode.
> When
> > > you
> > > > do that, the image will not be displayed and your user will not be
> able
> > > to
> > > > input the initial line. If you want to loop through a series of
> images,
> > > > that's different than just putting it in batchmode.
> > > >
> > > > I've changed some things and functionalized your segmentation (since
> > it's
> > > > the same) and it seems to be working for me. Can you test again with
> > this
> > > > and report back?
> > > >
> > > > HTH,
> > > > B
> > > >
> > > > On Fri, Jan 22, 2016 at 5:32 AM, Ramprasad Neethiraj <
> > > [hidden email]
> > > > >
> > > > wrote:
> > > >
> > > > > Hi all,
> > > > >
> > > > > I just realized that I had sent a different version of my script
> from
> > > the
> > > > > one I was using for testing. Please find the script attached.
> > > > >
> > > > > --
> > > > > 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
> > >
> >
> > --
> > 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