naive question involving a macro to apply misc. (contrast, scale bar, convert image) to multiple files

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

naive question involving a macro to apply misc. (contrast, scale bar, convert image) to multiple files

William Jeffrey Triffo
hello,

I am trying to write a simple macro file to open a bunch of images,
'auto set' the contrast, add a scalebar, and then save the image as a
jpeg. In the text below, I have edited an example I found for converting
BioRad to TIFF (can't remember where), that I appended commands to based
on the output of the "record macro" function in ImageJ. To the author of
that macro, thanks.

regarding the scalebar, I am using the .DM3 reader plug-in which
(nicely) sets the scale for me for each image using the .DM3 header.

The macro appears to convert all the images in a directory to .jpg, but
the scalebar (and presumably the 'auto contrast' line) only appear to
effect the last file in the series. As you can see, I have done some
very crude debugging using 'wait', to see if the commands were running
over each other (I would not know).

at any rate, any help would be appreciated; I tried searching the
archive for "scale bar batch", etc, but did not find a post dealing with
this (although it seems like a frequent operation to me, so I may have
mis-used the search function on the listserv homepage).

thanks much,

-Jeff

//
// the macro also assumes that you have the biorad plugin install
// (Biorad_Reader.class) as well as the file handler for other
// file types (HandleExtraFileTypes.class)
//
// gma - 28 mar 05
//

  macro "Batch Convert Image to JPEG with Contrast and Scalebar" {convert("jpeg");}

  function convert(format) {
      requires("1.33s");
      dir1 = getDirectory("Choose Source Directory ");
      dir2 = getDirectory("Choose Destination Directory ");
      list = getFileList(dir1);
      setBatchMode(true);
      for (i=0; i<list.length; i++) {
          showProgress(i+1, list.length);
          open(dir1+list[i]);
          wait(1000);
        //  run("Enhance Contrast", "saturated=0.5");
          wait(1000);
          run("Scale Bar...", "width=0.10 height=12 font=42 color=White background=None location=[Lower Right] hide");
          wait(1000);
          saveAs(format, dir2+list[i]);
          close();
      }
  }
Reply | Threaded
Open this post in threaded view
|

Re: naive question involving a macro to apply misc. (contrast, scale bar, convert image) to multiple files

lechristophe
Maybe this plugin could be usefull for you:

http://ciar.rcm.upr.edu/projects/imageprocessor/multiples

it allows to simply batch a macro for every images inside a folder, so you
don't have to deal with the batch part in your macro. With this and the
macro recorder it is possible to set up simple processing without writing a
line of macro code (of course it is not as powerfull as really writing your
own macro).

Christophe


On Feb 11, 2008 9:18 AM, William Jeffrey Triffo <[hidden email]> wrote:

> hello,
>
> I am trying to write a simple macro file to open a bunch of images,
> 'auto set' the contrast, add a scalebar, and then save the image as a
> jpeg. In the text below, I have edited an example I found for converting
> BioRad to TIFF (can't remember where), that I appended commands to based
> on the output of the "record macro" function in ImageJ. To the author of
> that macro, thanks.
>
> regarding the scalebar, I am using the .DM3 reader plug-in which
> (nicely) sets the scale for me for each image using the .DM3 header.
>
> The macro appears to convert all the images in a directory to .jpg, but
> the scalebar (and presumably the 'auto contrast' line) only appear to
> effect the last file in the series. As you can see, I have done some
> very crude debugging using 'wait', to see if the commands were running
> over each other (I would not know).
>
> at any rate, any help would be appreciated; I tried searching the
> archive for "scale bar batch", etc, but did not find a post dealing with
> this (although it seems like a frequent operation to me, so I may have
> mis-used the search function on the listserv homepage).
>
> thanks much,
>
> -Jeff
>
> //
> // the macro also assumes that you have the biorad plugin install
> // (Biorad_Reader.class) as well as the file handler for other
> // file types (HandleExtraFileTypes.class)
> //
> // gma - 28 mar 05
> //
>
>  macro "Batch Convert Image to JPEG with Contrast and Scalebar"
> {convert("jpeg");}
>
>  function convert(format) {
>      requires("1.33s");
>      dir1 = getDirectory("Choose Source Directory ");
>      dir2 = getDirectory("Choose Destination Directory ");
>      list = getFileList(dir1);
>      setBatchMode(true);
>      for (i=0; i<list.length; i++) {
>          showProgress(i+1, list.length);
>          open(dir1+list[i]);
>          wait(1000);
>        //  run("Enhance Contrast", "saturated=0.5");
>          wait(1000);
>          run("Scale Bar...", "width=0.10 height=12 font=42 color=White
> background=None location=[Lower Right] hide");
>          wait(1000);
>          saveAs(format, dir2+list[i]);
>          close();
>      }
>  }
>
Reply | Threaded
Open this post in threaded view
|

Re: naive question involving a macro to apply misc. (contrast, scale bar, convert image) to multiple files

Michael Schmid
In reply to this post by William Jeffrey Triffo
Hi Jeff,

- Concerning Enhance Contrast:

This only modifies the display, not the image data, so it will
not be stored (except tiff and zip, where the display settings
are stored with the image).
Use "Apply LUT" to modify the image.

- Concerning the Scale Bar:

I have no problem with this, but it depends on the image
calibration. It the scale bar has a width of 0.1 it won't show
up in images that have a scale of e.g. 1 um/pixel.
To see whether you have a scale bar of almost zero width, you
can remove the "hide" (hide text) command and look whether you
see the label.

Michael
________________________________________________________________

On 11 Feb 2008, at 09:18, William Jeffrey Triffo wrote:

> hello,
>
> I am trying to write a simple macro file to open a bunch of images,  
> 'auto set' the contrast, add a scalebar, and then save the image as  
> a jpeg. In the text below, I have edited an example I found for  
> converting BioRad to TIFF (can't remember where), that I appended  
> commands to based on the output of the "record macro" function in  
> ImageJ. To the author of that macro, thanks.
>
> regarding the scalebar, I am using the .DM3 reader plug-in which  
> (nicely) sets the scale for me for each image using the .DM3 header.
>
> The macro appears to convert all the images in a directory to .jpg,  
> but the scalebar (and presumably the 'auto contrast' line) only  
> appear to effect the last file in the series. As you can see, I  
> have done some very crude debugging using 'wait', to see if the  
> commands were running over each other (I would not know).
>
> at any rate, any help would be appreciated; I tried searching the  
> archive for "scale bar batch", etc, but did not find a post dealing  
> with this (although it seems like a frequent operation to me, so I  
> may have mis-used the search function on the listserv homepage).
>
> thanks much,
>
> -Jeff
>
> //
> // the macro also assumes that you have the biorad plugin install
> // (Biorad_Reader.class) as well as the file handler for other
> // file types (HandleExtraFileTypes.class)
> //
> // gma - 28 mar 05
> //
>
>  macro "Batch Convert Image to JPEG with Contrast and  
> Scalebar" {convert("jpeg");}
>
>  function convert(format) {
>      requires("1.33s");
>      dir1 = getDirectory("Choose Source Directory ");
>      dir2 = getDirectory("Choose Destination Directory ");
>      list = getFileList(dir1);
>      setBatchMode(true);
>      for (i=0; i<list.length; i++) {
>          showProgress(i+1, list.length);
>          open(dir1+list[i]);
>          wait(1000);
> //  run("Enhance Contrast", "saturated=0.5");
>  wait(1000);
>  run("Scale Bar...", "width=0.10 height=12 font=42 color=White  
> background=None location=[Lower Right] hide");
>  wait(1000);
>          saveAs(format, dir2+list[i]);
>          close();
>      }
>  }
Reply | Threaded
Open this post in threaded view
|

Re: naive question involving a macro to apply misc. (contrast, scale bar, convert image) to multiple files

William Jeffrey Triffo
thanks Michael,

I now see that for many of the images, the units were different - the
"0.1" is fine when my units are microns (makes a 100nm bar), but for
higher-mag images the units switch to nanometers, so "0.1" at that point
means "1 Angstrom", which is sub-pixel at that point.

could someone send me the proper commands to scan the units in "Set
Scale" within the macro, so that I can use an "if/then" conditional to
set the width right for each image (100 vs. 0.1). When I look at the
output of the macro recorder after launching the "Set Scale" dialog, it
just says "run("Set Scale...");" (which makes sense). maybe what I am
really asking is how to look at the units field in the image header (?)

best,

-Jeff


Michael Schmid wrote:

> Hi Jeff,
>
> - Concerning Enhance Contrast:
>
> This only modifies the display, not the image data, so it will
> not be stored (except tiff and zip, where the display settings
> are stored with the image).
> Use "Apply LUT" to modify the image.
>
> - Concerning the Scale Bar:
>
> I have no problem with this, but it depends on the image
> calibration. It the scale bar has a width of 0.1 it won't show
> up in images that have a scale of e.g. 1 um/pixel.
> To see whether you have a scale bar of almost zero width, you
> can remove the "hide" (hide text) command and look whether you
> see the label.
>
> Michael
> ________________________________________________________________
>
> On 11 Feb 2008, at 09:18, William Jeffrey Triffo wrote:
>
>> hello,
>>
>> I am trying to write a simple macro file to open a bunch of images,
>> 'auto set' the contrast, add a scalebar, and then save the image as a
>> jpeg. In the text below, I have edited an example I found for
>> converting BioRad to TIFF (can't remember where), that I appended
>> commands to based on the output of the "record macro" function in
>> ImageJ. To the author of that macro, thanks.
>>
>> regarding the scalebar, I am using the .DM3 reader plug-in which
>> (nicely) sets the scale for me for each image using the .DM3 header.
>>
>> The macro appears to convert all the images in a directory to .jpg,
>> but the scalebar (and presumably the 'auto contrast' line) only
>> appear to effect the last file in the series. As you can see, I have
>> done some very crude debugging using 'wait', to see if the commands
>> were running over each other (I would not know).
>>
>> at any rate, any help would be appreciated; I tried searching the
>> archive for "scale bar batch", etc, but did not find a post dealing
>> with this (although it seems like a frequent operation to me, so I
>> may have mis-used the search function on the listserv homepage).
>>
>> thanks much,
>>
>> -Jeff
>>
>> //
>> // the macro also assumes that you have the biorad plugin install
>> // (Biorad_Reader.class) as well as the file handler for other
>> // file types (HandleExtraFileTypes.class)
>> //
>> // gma - 28 mar 05
>> //
>>
>>  macro "Batch Convert Image to JPEG with Contrast and Scalebar"
>> {convert("jpeg");}
>>
>>  function convert(format) {
>>      requires("1.33s");
>>      dir1 = getDirectory("Choose Source Directory ");
>>      dir2 = getDirectory("Choose Destination Directory ");
>>      list = getFileList(dir1);
>>      setBatchMode(true);
>>      for (i=0; i<list.length; i++) {
>>          showProgress(i+1, list.length);
>>          open(dir1+list[i]);
>>          wait(1000);
>>     //  run("Enhance Contrast", "saturated=0.5");
>>       wait(1000);
>>       run("Scale Bar...", "width=0.10 height=12 font=42 color=White
>> background=None location=[Lower Right] hide");
>>       wait(1000);
>>          saveAs(format, dir2+list[i]);
>>          close();
>>      }
>>  }
>
Reply | Threaded
Open this post in threaded view
|

Re: naive question involving a macro to apply misc. (contrast, scale bar, convert image) to multiple files

William Jeffrey Triffo
Please ignore my last email,

I see that there is a "getPixelSize" command.

thanks,

-Jeff


William Jeffrey Triffo wrote:

> thanks Michael,
>
> I now see that for many of the images, the units were different - the
> "0.1" is fine when my units are microns (makes a 100nm bar), but for
> higher-mag images the units switch to nanometers, so "0.1" at that
> point means "1 Angstrom", which is sub-pixel at that point.
>
> could someone send me the proper commands to scan the units in "Set
> Scale" within the macro, so that I can use an "if/then" conditional to
> set the width right for each image (100 vs. 0.1). When I look at the
> output of the macro recorder after launching the "Set Scale" dialog,
> it just says "run("Set Scale...");" (which makes sense). maybe what I
> am really asking is how to look at the units field in the image header
> (?)
>
> best,
>
> -Jeff
>
>
> Michael Schmid wrote:
>> Hi Jeff,
>>
>> - Concerning Enhance Contrast:
>>
>> This only modifies the display, not the image data, so it will
>> not be stored (except tiff and zip, where the display settings
>> are stored with the image).
>> Use "Apply LUT" to modify the image.
>>
>> - Concerning the Scale Bar:
>>
>> I have no problem with this, but it depends on the image
>> calibration. It the scale bar has a width of 0.1 it won't show
>> up in images that have a scale of e.g. 1 um/pixel.
>> To see whether you have a scale bar of almost zero width, you
>> can remove the "hide" (hide text) command and look whether you
>> see the label.
>>
>> Michael
>> ________________________________________________________________
>>
>> On 11 Feb 2008, at 09:18, William Jeffrey Triffo wrote:
>>
>>> hello,
>>>
>>> I am trying to write a simple macro file to open a bunch of images,
>>> 'auto set' the contrast, add a scalebar, and then save the image as
>>> a jpeg. In the text below, I have edited an example I found for
>>> converting BioRad to TIFF (can't remember where), that I appended
>>> commands to based on the output of the "record macro" function in
>>> ImageJ. To the author of that macro, thanks.
>>>
>>> regarding the scalebar, I am using the .DM3 reader plug-in which
>>> (nicely) sets the scale for me for each image using the .DM3 header.
>>>
>>> The macro appears to convert all the images in a directory to .jpg,
>>> but the scalebar (and presumably the 'auto contrast' line) only
>>> appear to effect the last file in the series. As you can see, I have
>>> done some very crude debugging using 'wait', to see if the commands
>>> were running over each other (I would not know).
>>>
>>> at any rate, any help would be appreciated; I tried searching the
>>> archive for "scale bar batch", etc, but did not find a post dealing
>>> with this (although it seems like a frequent operation to me, so I
>>> may have mis-used the search function on the listserv homepage).
>>>
>>> thanks much,
>>>
>>> -Jeff
>>>
>>> //
>>> // the macro also assumes that you have the biorad plugin install
>>> // (Biorad_Reader.class) as well as the file handler for other
>>> // file types (HandleExtraFileTypes.class)
>>> //
>>> // gma - 28 mar 05
>>> //
>>>
>>>  macro "Batch Convert Image to JPEG with Contrast and Scalebar"
>>> {convert("jpeg");}
>>>
>>>  function convert(format) {
>>>      requires("1.33s");
>>>      dir1 = getDirectory("Choose Source Directory ");
>>>      dir2 = getDirectory("Choose Destination Directory ");
>>>      list = getFileList(dir1);
>>>      setBatchMode(true);
>>>      for (i=0; i<list.length; i++) {
>>>          showProgress(i+1, list.length);
>>>          open(dir1+list[i]);
>>>          wait(1000);
>>>     //  run("Enhance Contrast", "saturated=0.5");
>>>       wait(1000);
>>>       run("Scale Bar...", "width=0.10 height=12 font=42 color=White
>>> background=None location=[Lower Right] hide");
>>>       wait(1000);
>>>          saveAs(format, dir2+list[i]);
>>>          close();
>>>      }
>>>  }
>>
>

--
-------------------------------------------------------------
Jeff Triffo
Auer Group, Donner Lab, Lawrence Berkeley National Laboratory
Raphael Group, Bioengineering Department, Rice University
Medical Scientist Training Program (MSTP), Baylor College of Medicine
phone (Berkeley): 510-486-7940
fax   (Berkeley): 510-486-6488