Help needed: Macro to save plot profile data as text

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

Help needed: Macro to save plot profile data as text

Silas Kraus
Greetings.

I am a student at KIT, Germany, currently working on carbon
nanoparticles with the Scanning Electron Microscope and all new to this
list.

I am using ImageJ to make linescans over Nanoparticles. As I have a lot
of images, I wanted to create a macro that automates the process a bit.
After manually drawing a line, I want the macro to create a plot profile
and save the data as text in a file. So far, I have:

run("Plot Profile");
saveAs("Text", "/path/to/file/Values.txt");

The plot profile is created, but then I get an error message stating
that a TextWindow is needed. I searched the manual and the web for
several hours, but found nothing. Someone else on this mailing list also
had this problem, but never got an answer.
http://imagej.1557.x6.nabble.com/macro-script-to-save-radial-profile-plot-data-td5000012.html

As I need the data for a meeting tomorrow evening, help would be much
appreciated. :)

Thanks in advance!
Silas Kraus

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

Re: Help needed: Macro to save plot profile data as text

Peterbauer Thomas
On 2015-04-26 18:21, Silas Kraus wrote:

> I am using ImageJ to make linescans over Nanoparticles. As I have a lot
> of images, I wanted to create a macro that automates the process a bit.
> After manually drawing a line, I want the macro to create a plot profile
> and save the data as text in a file. So far, I have:
>
> run("Plot Profile");
> saveAs("Text", "/path/to/file/Values.txt");
>
> The plot profile is created, but then I get an error message stating
> that a TextWindow is needed. I searched the manual and the web for
> several hours, but found nothing. Someone else on this mailing list also
> had this problem, but never got an answer.
> http://imagej.1557.x6.nabble.com/macro-script-to-save-radial-profile-plot-data-td5000012.html

You are trying to save the plot, not the values. You have to get the
values into a results table:

run("Clear Results");
profile = getProfile();
for (i=0; i<profile.length; i++) {
    setResult("Value", i, profile[i]);
}
updateResults;
saveAs("results","/path/to/file");

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

Re: Help needed: Macro to save plot profile data as text

Silas Kraus
Hey thanks!

I already got help from another ImageJ user who sent me a link to a very
similar example macro that worked for me:
http://rsb.info.nih.gov/ij/macros/GetProfileExample.txt

> You are trying to save the plot, not the values. You have to get the
> values into a results table:
>
> run("Clear Results");
> profile = getProfile();
> for (i=0; i<profile.length; i++) {
>     setResult("Value", i, profile[i]);
> }
> updateResults;
> saveAs("results","/path/to/file");
>

The strange thing is that this code still threw the same error. It only
differs from the above mentioned example macro in one line: The
"updateResults;" command is outside of the loop. When I put it inside
the loop, everything works fine.

Anyway, thanks a lot for the quick help. Now I can get to work.
See you.
Silas Kraus

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

Re: Help needed: Macro to save plot profile data as text

Peterbauer Thomas
In reply to this post by Silas Kraus
On 2015-04-26 23:56, Silas Kraus wrote:
> I already got help from another ImageJ user who sent me a link to a very
> similar example macro that worked for me:
> http://rsb.info.nih.gov/ij/macros/GetProfileExample.txt

>> You are trying to save the plot, not the values. You have to get the
>> values into a results table:
>>
>> run("Clear Results");
>> profile = getProfile();
>> for (i=0; i<profile.length; i++) {
>>     setResult("Value", i, profile[i]);
>> }
>> updateResults;
>> saveAs("results","/path/to/file");
>>

> The strange thing is that this code still threw the same error. It only
> differs from the above mentioned example macro in one line: The
> "updateResults;" command is outside of the loop. When I put it inside
> the loop, everything works fine.

I cannot reproduce the error, neither with my code nor with the example macro. In the example macro, the "updateResults" command resides also outside the loop. There are just no curly brackets surrounding the "setResults" command, which means that only the first line following the for-statement (again only "setResults") is executed within the loop.


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

Re: Help needed: Macro to save plot profile data as text

Herbie-4
Dear ImageJ macro-coders,

ImageJ comes with an enormous amount of useful example code. However,
for many problems there exist various solutions and some are more
obvious than others...

In the here discussed situation one may follow an approach involving the
results table but the following appears more lucid and flexible, at
least to me:


Plot.getValues( x, y );
str = "X\tY\n"; // header
for ( i=0; i<x.length; i++ ) {
        str += "" + x[i] + "\t" + y[i] + "\n"; }
File.saveString( str, getDirectory( "imagej" ) + "/profileData.txt" );


Instead of x[i] and y[i] one may use d2s( x[i], d ) and d2s( y[i], d ),
with d denoting the number of decimal digits.

Happy coding

Herbie

:::::::::::::::::::::::::::::::::::::::::::::::
Am 27.04.15 um 10:04 schrieb Peterbauer Thomas:

> On 2015-04-26 23:56, Silas Kraus wrote:
>> I already got help from another ImageJ user who sent me a link to a
>> very similar example macro that worked for me:
>> http://rsb.info.nih.gov/ij/macros/GetProfileExample.txt
>
>>> You are trying to save the plot, not the values. You have to get
>>> the values into a results table:
>>>
>>> run("Clear Results"); profile = getProfile(); for (i=0;
>>> i<profile.length; i++) { setResult("Value", i, profile[i]); }
>>> updateResults; saveAs("results","/path/to/file");
>>>
>
>> The strange thing is that this code still threw the same error. It
>> only differs from the above mentioned example macro in one line:
>> The "updateResults;" command is outside of the loop. When I put it
>> inside the loop, everything works fine.
>
> I cannot reproduce the error, neither with my code nor with the
> example macro. In the example macro, the "updateResults" command
> resides also outside the loop. There are just no curly brackets
> surrounding the "setResults" command, which means that only the first
> line following the for-statement (again only "setResults") is
> executed within the loop.

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