Convert macro from NIH Image to ImageJ

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

Convert macro from NIH Image to ImageJ

dinurf
Hi All,

Could someone please help me to convert the macro below? The macro used to be written for NIH Image while I want to run it on ImageJ.

Thank you.

Nay

=============================================
macro 'Fractal Dilation';
var
        iterations,i:integer;
        tab:string;
begin
        SaveState;
        iterations:=64;
        tab:=chr(9);
        SetFont('Monaco');
        SetFontSize(9);
        ResetCounter;
        SetBinaryCount(1);
        NewTextWindow(contact(WindowTitle,'-Counts'), 140, 350);
        MoveWindow(500,50);
        Measure;
        writeln(1:3, tab, histogram[255]:7, tab, histogram[255]:5);
        for i:=1 to iterations do begin
                Dilate;
                Measure;
                writeln(i*2+1:3, tab, histogram[255]:7, tab, histogram[255]/(i*2+1):5);
        end;
        RestoreState;

end;
=========================================================
Reply | Threaded
Open this post in threaded view
|

Re: Convert macro from NIH Image to ImageJ

Rasband, Wayne (NIH/NIMH) [E]
> On Dec 31, 2015, at 1:05 AM, dinurf <[hidden email]> wrote:
>
> Hi All,
>
> Could someone please help me to convert the macro below? The macro used to
> be written for NIH Image while I want to run it on ImageJ.

A macro something like the following should work. Note that it assumes, like the NIH Image version, that objects are black and background is white and that black pixels have a value of 255.

-wayne

  macro "Fractal Dilation" {
     iterations = 64;
     run("Clear Results");
     setOption("BlackBackground", false);
     run("Make Binary"); // needed if image is not binary
     for (i=0; i<=iterations; i++) {
        showProgress(i, iterations);
        getRawStatistics(n, mean, min, max, std, hist);
        setResult("i*2+1", i, i*2+1);
        setResult("hist[255]", i, hist[255]);
        setResult("hist[255]/(i*2+1)", i, hist[255]/(i*2+1));
        run("Options...", "iterations=1 count=1 do=Dilate");
      }
     updateResults;
  }


> =============================================
> macro 'Fractal Dilation';
> var
> iterations,i:integer;
> tab:string;
> begin
> SaveState;
> iterations:=64;
> tab:=chr(9);
> SetFont('Monaco');
> SetFontSize(9);
> ResetCounter;
> SetBinaryCount(1);
> NewTextWindow(contact(WindowTitle,'-Counts'), 140, 350);
> MoveWindow(500,50);
> Measure;
> writeln(1:3, tab, histogram[255]:7, tab, histogram[255]:5);
> for i:=1 to iterations do begin
> Dilate;
> Measure;
> writeln(i*2+1:3, tab, histogram[255]:7, tab, histogram[255]/(i*2+1):5);
> end;
> RestoreState;
>
> end;
> =========================================================
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Convert-macro-from-NIH-Image-to-ImageJ-tp5015304.html
> Sent from the ImageJ mailing list archive at Nabble.com.

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

Re: Convert macro from NIH Image to ImageJ

dinurf
Thank you very much.

On Fri, Jan 1, 2016 at 4:32 AM, Rasband, Wayne (NIH/NIMH) [E] [via ImageJ] <[hidden email]> wrote:
> On Dec 31, 2015, at 1:05 AM, dinurf <[hidden email]> wrote:
>
> Hi All,
>
> Could someone please help me to convert the macro below? The macro used to
> be written for NIH Image while I want to run it on ImageJ.

A macro something like the following should work. Note that it assumes, like the NIH Image version, that objects are black and background is white and that black pixels have a value of 255.

-wayne

  macro "Fractal Dilation" {
     iterations = 64;
     run("Clear Results");
     setOption("BlackBackground", false);
     run("Make Binary"); // needed if image is not binary
     for (i=0; i<=iterations; i++) {
        showProgress(i, iterations);
        getRawStatistics(n, mean, min, max, std, hist);
        setResult("i*2+1", i, i*2+1);
        setResult("hist[255]", i, hist[255]);
        setResult("hist[255]/(i*2+1)", i, hist[255]/(i*2+1));
        run("Options...", "iterations=1 count=1 do=Dilate");
      }
     updateResults;
  }


> =============================================
> macro 'Fractal Dilation';
> var
> iterations,i:integer;
> tab:string;
> begin
> SaveState;
> iterations:=64;
> tab:=chr(9);
> SetFont('Monaco');
> SetFontSize(9);
> ResetCounter;
> SetBinaryCount(1);
> NewTextWindow(contact(WindowTitle,'-Counts'), 140, 350);
> MoveWindow(500,50);
> Measure;
> writeln(1:3, tab, histogram[255]:7, tab, histogram[255]:5);
> for i:=1 to iterations do begin
> Dilate;
> Measure;
> writeln(i*2+1:3, tab, histogram[255]:7, tab, histogram[255]/(i*2+1):5);
> end;
> RestoreState;
>
> end;
> =========================================================
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Convert-macro-from-NIH-Image-to-ImageJ-tp5015304.html
> Sent from the ImageJ mailing list archive at Nabble.com.
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html



If you reply to this email, your message will be added to the discussion below:
http://imagej.1557.x6.nabble.com/Convert-macro-from-NIH-Image-to-ImageJ-tp5015304p5015305.html
To unsubscribe from Convert macro from NIH Image to ImageJ, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Convert macro from NIH Image to ImageJ

dinurf
Hello,

I downloaded a macro from ImageJ website a long time ago, the macro is
called FractalEDM (attaced) to compute an object's fractal dimension.
Because I am new using ImageJ, I don't really understand what has written
within the macro. So if you don't mind, Could you help me please to let me
know what step by step within the macro or general step? I cannot contact
the main author, her email was no longer used.

For example, for the first line, (requires "1.30p") and I see that they
used "run(Invert)" which is I don't understand why.

Besides that, I am also trying to used menu Distance Map. The steps I used:

1. Make an image into binary
2. Menu --> Process --> Binary --> Distance map
3. Menu --> Analyze --> Histogram , to get the list of data of values and
counts.

And I followed this way to get the fractal dimension:



But the result that I got, for example the koch snowflake, seems weird or
too high from the theoretical value. That's why I ask your help whether I
made some mistakes on those steps.

Is the way that I did using the above steps VERY different with the way
written in the macro?

Thank you.
I am looking forward your advice.

Dini



On Sat, Jan 9, 2016 at 10:28 AM, dinurf <[hidden email]> wrote:

> Thank you very much.
>
> On Fri, Jan 1, 2016 at 4:32 AM, Rasband, Wayne (NIH/NIMH) [E] [via ImageJ]
> <
> [hidden email]> wrote:
>
> > > On Dec 31, 2015, at 1:05 AM, dinurf <[hidden email]
> > <http:///user/SendEmail.jtp?type=node&node=5015305&i=0>> wrote:
> > >
> > > Hi All,
> > >
> > > Could someone please help me to convert the macro below? The macro used
> > to
> > > be written for NIH Image while I want to run it on ImageJ.
> >
> > A macro something like the following should work. Note that it assumes,
> > like the NIH Image version, that objects are black and background is
> white
> > and that black pixels have a value of 255.
> >
> > -wayne
> >
> >   macro "Fractal Dilation" {
> >      iterations = 64;
> >      run("Clear Results");
> >      setOption("BlackBackground", false);
> >      run("Make Binary"); // needed if image is not binary
> >      for (i=0; i<=iterations; i++) {
> >         showProgress(i, iterations);
> >         getRawStatistics(n, mean, min, max, std, hist);
> >         setResult("i*2+1", i, i*2+1);
> >         setResult("hist[255]", i, hist[255]);
> >         setResult("hist[255]/(i*2+1)", i, hist[255]/(i*2+1));
> >         run("Options...", "iterations=1 count=1 do=Dilate");
> >       }
> >      updateResults;
> >   }
> >
> >
> > > =============================================
> > > macro 'Fractal Dilation';
> > > var
> > > iterations,i:integer;
> > > tab:string;
> > > begin
> > > SaveState;
> > > iterations:=64;
> > > tab:=chr(9);
> > > SetFont('Monaco');
> > > SetFontSize(9);
> > > ResetCounter;
> > > SetBinaryCount(1);
> > > NewTextWindow(contact(WindowTitle,'-Counts'), 140, 350);
> > > MoveWindow(500,50);
> > > Measure;
> > > writeln(1:3, tab, histogram[255]:7, tab, histogram[255]:5);
> > > for i:=1 to iterations do begin
> > > Dilate;
> > > Measure;
> > > writeln(i*2+1:3, tab, histogram[255]:7, tab, histogram[255]/(i*2+1):5);
> > > end;
> > > RestoreState;
> > >
> > > end;
> > > =========================================================
> > > --
> > > View this message in context:
> >
> http://imagej.1557.x6.nabble.com/Convert-macro-from-NIH-Image-to-ImageJ-tp5015304.html
> > > Sent from the ImageJ mailing list archive at Nabble.com.
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
> >
> > ------------------------------
> > If you reply to this email, your message will be added to the discussion
> > below:
> >
> >
> http://imagej.1557.x6.nabble.com/Convert-macro-from-NIH-Image-to-ImageJ-tp5015304p5015305.html
> > To unsubscribe from Convert macro from NIH Image to ImageJ, click here
> > <
> >
> > .
> > NAML
> > <
>
http://imagej.1557.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
> >
> >
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Convert-macro-from-NIH-Image-to-ImageJ-tp5015304p5015355.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Untitled.png (368K) Download Attachment
FractalEDM notes.txt (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Convert macro from NIH Image to ImageJ

Gabriel Landini
> I downloaded a macro from ImageJ website a long time ago, the macro is
> called FractalEDM (attaced) to compute an object's fractal dimension.
> Because I am new using ImageJ, I don't really understand what has written
> within the macro. So if you don't mind, Could you help me please to let me
> know what step by step within the macro or general step? I cannot contact
> the main author, her email was no longer used.
>
> For example, for the first line, (requires "1.30p") and I see that they
> used "run(Invert)" which is I don't understand why.
>
> Besides that, I am also trying to used menu Distance Map. The steps I used:
>
> 1. Make an image into binary
> 2. Menu --> Process --> Binary --> Distance map
> 3. Menu --> Analyze --> Histogram , to get the list of data of values and
> counts.

It is not the area of the Minkowski 'sausage', but its length, what you use to
compute the 'dilation dimension'.
The length is related to the diameter of the disc used for the dilation:
Length(epsilon)=Area(epsilon)/epsilon, where epsilon is the diameter of the
dilation disc,

You can do that with the Maximum filer as you know exactly the radius, so you
divide the area of the sausage at a given radius by
(2*radius)+1 to get the length.
Then plot log((2*radius)+1) vs. the log of the length of the 'sausage' for
that radius. Then 1-slope should give you the fractal dimension.

Be aware that this procedure only works for closed contours. If you are
computing this for a tree or network with end points, you overestimate the
length of the 'sausage' at each free end. So you need to compensate for that
(which is not straightforward to do).

See fir example Eins S. An improved dilation method for the measurement of
fractal dimension. Acta Stereologica 1995;14(2):169-178.
http://popups.ulg.ac.be/0351-580X/index.php?id=831&file=1&pid=825

Maybe computing the box dimension would be easier as it does not suffer from
that problem.

Cheers

Gabriel

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

Re: Convert macro from NIH Image to ImageJ

dinurf
Dear Gabriel,

Thank you for your explanation. I am a bit confused since you explained
about dilation dimension. Are you referring to my first&previous question
about dilation macro? Because my recent&new question is about Euclidean
Distance Map macro.

But from your explanation about dilation dimension, I tried it as well. I
calculated the perimeter (length) first by dividing Area(epsilon)/epsilon
and also plotted the log radius vs log perimeter as you mentioned. I found
the fractal dimension for Koch Snowflake using that method was 1,2283,
since the slope is - 0,2283. That value is quite far from the theoretical
value, which is 1,2685.

I don't used an image with end points, I used the dilation macro/dilation
method for closed contours.

Thank you and thank you for the paper as well!

Regards,
Dini


On Mon, Jun 20, 2016 at 4:31 PM, Gabriel Landini <[hidden email]>
wrote:

> > I downloaded a macro from ImageJ website a long time ago, the macro is
> > called FractalEDM (attaced) to compute an object's fractal dimension.
> > Because I am new using ImageJ, I don't really understand what has written
> > within the macro. So if you don't mind, Could you help me please to let
> me
> > know what step by step within the macro or general step? I cannot contact
> > the main author, her email was no longer used.
> >
> > For example, for the first line, (requires "1.30p") and I see that they
> > used "run(Invert)" which is I don't understand why.
> >
> > Besides that, I am also trying to used menu Distance Map. The steps I
> used:
> >
> > 1. Make an image into binary
> > 2. Menu --> Process --> Binary --> Distance map
> > 3. Menu --> Analyze --> Histogram , to get the list of data of values and
> > counts.
>
> It is not the area of the Minkowski 'sausage', but its length, what you
> use to
> compute the 'dilation dimension'.
> The length is related to the diameter of the disc used for the dilation:
> Length(epsilon)=Area(epsilon)/epsilon, where epsilon is the diameter of the
> dilation disc,
>
> You can do that with the Maximum filer as you know exactly the radius, so
> you
> divide the area of the sausage at a given radius by
> (2*radius)+1 to get the length.
> Then plot log((2*radius)+1) vs. the log of the length of the 'sausage' for
> that radius. Then 1-slope should give you the fractal dimension.
>
> Be aware that this procedure only works for closed contours. If you are
> computing this for a tree or network with end points, you overestimate the
> length of the 'sausage' at each free end. So you need to compensate for
> that
> (which is not straightforward to do).
>
> See fir example Eins S. An improved dilation method for the measurement of
> fractal dimension. Acta Stereologica 1995;14(2):169-178.
> http://popups.ulg.ac.be/0351-580X/index.php?id=831&file=1&pid=825
>
> Maybe computing the box dimension would be easier as it does not suffer
> from
> that problem.
>
> Cheers
>
> Gabriel
>
> --
> 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: Convert macro from NIH Image to ImageJ

Gabriel Landini
On Monday 20 Jun 2016 18:15:30 Dini Nurfiani wrote:
> Thank you for your explanation. I am a bit confused since you explained
> about dilation dimension. Are you referring to my first&previous question
> about dilation macro? Because my recent&new question is about Euclidean
> Distance Map macro.

I commented on the figures you included in your email.
The EDM is somewhat equivalent to the nested dilations, but the fractal
dimension is not computed as the figure seemed to suggest: log of distance
transform vs log of pixels, but the the way I outlined  in my previous email.
It is 1- slope of (log(diameter) vs log(length[diameter]) ).

> But from your explanation about dilation dimension, I tried it as well. I
> calculated the perimeter (length) first by dividing Area(epsilon)/epsilon
> and also plotted the log radius vs log perimeter as you mentioned. I found
> the fractal dimension for Koch Snowflake using that method was 1,2283,
> since the slope is - 0,2283. That value is quite far from the theoretical
> value, which is 1,2685.

1. You need to make sure that the largest dilated version of the curve fits
*completely* within the frame of the image. So the curve has to have lots of
empty space around. In the figure you pasted before, the EDM was truncated by
the image borders. That will underestimate the number of pixels of the large
dilation discs.

2. Do not use diameters which are too small. At small scales the image you
used is made of short straight lines (with D=1).

Hope it helps

Gabriel

 

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

Re: Convert macro from NIH Image to ImageJ

dinurf
Thank you Gabriel,

I noted your explanation regarding to make sure the largest dilation has to
fit completely within the frame. I want to make sure something else again.
Can I dilate an image up to high iteration? as long as the largest dilation
still fit within the frame? For example, the following shape:

3 iterations

​4 iterations (in the upper right corner, there is pixel touching each
other. Will this influence the dilated area measured?)

​40 iterations (or I can go until higher/largest dilation?)


Thank you.

Regards,
Dini



On Mon, Jun 20, 2016 at 6:42 PM, Gabriel Landini <[hidden email]>
wrote:

> On Monday 20 Jun 2016 18:15:30 Dini Nurfiani wrote:
> > Thank you for your explanation. I am a bit confused since you explained
> > about dilation dimension. Are you referring to my first&previous question
> > about dilation macro? Because my recent&new question is about Euclidean
> > Distance Map macro.
>
> I commented on the figures you included in your email.
> The EDM is somewhat equivalent to the nested dilations, but the fractal
> dimension is not computed as the figure seemed to suggest: log of distance
> transform vs log of pixels, but the the way I outlined  in my previous
> email.
> It is 1- slope of (log(diameter) vs log(length[diameter]) ).
>
> > But from your explanation about dilation dimension, I tried it as well. I
> > calculated the perimeter (length) first by dividing Area(epsilon)/epsilon
> > and also plotted the log radius vs log perimeter as you mentioned. I
> found
> > the fractal dimension for Koch Snowflake using that method was 1,2283,
> > since the slope is - 0,2283. That value is quite far from the theoretical
> > value, which is 1,2685.
>
> 1. You need to make sure that the largest dilated version of the curve fits
> *completely* within the frame of the image. So the curve has to have lots
> of
> empty space around. In the figure you pasted before, the EDM was truncated
> by
> the image borders. That will underestimate the number of pixels of the
> large
> dilation discs.
>
> 2. Do not use diameters which are too small. At small scales the image you
> used is made of short straight lines (with D=1).
>
> Hope it helps
>
> Gabriel
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

3 iter.jpg (20K) Download Attachment
4 iter.jpg (20K) Download Attachment
40 iter.jpg (20K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Convert macro from NIH Image to ImageJ

Gabriel Landini
On Tuesday 21 Jun 2016 11:59:22 Dini Nurfiani wrote:

> I noted your explanation regarding to make sure the largest dilation has to
> fit completely within the frame. I want to make sure something else again.
> Can I dilate an image up to high iteration? as long as the largest dilation
> still fit within the frame? For example, the following shape:
>
> 3 iterations
>
> ​4 iterations (in the upper right corner, there is pixel touching each
> other. Will this influence the dilated area measured?)
>
> ​40 iterations (or I can go until higher/largest dilation?)

The purpose of the dilation is to remove detail on the curve, so you can
measure how 'shorter' it gets with less detail.
Once the dilation kernel gets close to the size of the largest detail in
object itself, the length of increase slows down, so part of your plot will
have a shallower slope (likely approach D=1, and the slope will get closer to
0).
If you apply too many dilations you will notice this shallowing of the log-log
plot. So it is best to be careful in deciding what is an appropriate range of
dilation sizes to be used to estimate the slope. Too small discs will not pick
up detail as you are close to the pixel matrix, too large and you approach the
object size.

There are various papers dealing with this including some trying to estimate
not only the fractal slope, but also the transition to an Euclidean range.
See: "Rigaut J.P. An empirical formulation relating boundary lengths to
resolution in specimens showing 'non-ideally fractal' dimensions. Journal of
Microscopy 133, 41-54. 1984."
That is quite a remarkable paper (by a remarkable scientist), way ahead of its
time. People were struggling to understand "just" fractals after Mandelbrot
published his famous book and JPR came up with his extended model for
asymptotic fractals very soon afterward.

Hope it is useful.

Gabriel

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

Re: Convert macro from NIH Image to ImageJ

dinurf
Hello Gabriel,

Noted. Thank you. I will read the paper.

Dini

On Tue, Jun 21, 2016 at 4:53 PM, Gabriel Landini <[hidden email]>
wrote:

> On Tuesday 21 Jun 2016 11:59:22 Dini Nurfiani wrote:
> > I noted your explanation regarding to make sure the largest dilation has
> to
> > fit completely within the frame. I want to make sure something else
> again.
> > Can I dilate an image up to high iteration? as long as the largest
> dilation
> > still fit within the frame? For example, the following shape:
> >
> > 3 iterations
> >
> > ​4 iterations (in the upper right corner, there is pixel touching each
> > other. Will this influence the dilated area measured?)
> >
> > ​40 iterations (or I can go until higher/largest dilation?)
>
> The purpose of the dilation is to remove detail on the curve, so you can
> measure how 'shorter' it gets with less detail.
> Once the dilation kernel gets close to the size of the largest detail in
> object itself, the length of increase slows down, so part of your plot will
> have a shallower slope (likely approach D=1, and the slope will get closer
> to
> 0).
> If you apply too many dilations you will notice this shallowing of the
> log-log
> plot. So it is best to be careful in deciding what is an appropriate range
> of
> dilation sizes to be used to estimate the slope. Too small discs will not
> pick
> up detail as you are close to the pixel matrix, too large and you approach
> the
> object size.
>
> There are various papers dealing with this including some trying to
> estimate
> not only the fractal slope, but also the transition to an Euclidean range.
> See: "Rigaut J.P. An empirical formulation relating boundary lengths to
> resolution in specimens showing 'non-ideally fractal' dimensions. Journal
> of
> Microscopy 133, 41-54. 1984."
> That is quite a remarkable paper (by a remarkable scientist), way ahead of
> its
> time. People were struggling to understand "just" fractals after Mandelbrot
> published his famous book and JPR came up with his extended model for
> asymptotic fractals very soon afterward.
>
> Hope it is useful.
>
> Gabriel
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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