naive question involving a macro to apply misc. (contrast, scale bar, convert image) to multiple files
Posted by William Jeffrey Triffo on Feb 11, 2008; 8:18am
URL: http://imagej.273.s1.nabble.com/naive-question-involving-a-macro-to-apply-misc-contrast-scale-bar-convert-image-to-multiple-files-tp3697222.html
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();
}
}