Hi all,
I'm trying to write my own macro that uses batch mode to open a folder of images, set a scale and place a scale bar on all of them then save away to a specified folder. I'm using the run("Set Scale...") function to set the scale of each image which seems to work fine. I've then created my own dialog which replicates the info needed for the inbuilt scale bar plus dialog- i don't use that as it requires an image to be open and i want the dialog to open at the start and then be used for all images before batch mode begins. The result of the macro is a white bar along the lower right of the image, no text is seen and i can't change the colour. Basically the run(scale bar...) function doesn't seem to 'see' or accept the variables i've created which i've plugged into the run(scale bar...) function. I think i've maybe made an error putting my variables into run(scale bar...) function so i've attached that bit of code to the email. I know there are other ways to make scale bars by not using the scale bar function by making rectangles of a certain size etc but this is the easiest method for me to get my head around. Thanks for the advice! Matt See extracted code below: colours = newArray("White", "Black", "Red", "Green", "Blue"); locations = newArray("Lower Left", "Lower Right", "Upper Left", "Upper Right"); Dialog.create("Scale Bar Options"); Dialog.addMessage("Fill in parameters"); Dialog.addNumber("Width of SB", 100); Dialog.addNumber("Height of SB", 3); Dialog.addNumber("Font Size", 14); Dialog.addChoice("Colour", colours); Dialog.addChoice("Location", locations); Dialog.show(); width = Dialog.getNumber(); height = Dialog.getNumber(); font = Dialog.getNumber(); color = Dialog.getChoice(); location = Dialog.getChoice(); setBatchMode(true); // runs up to 6 times faster for (i=0; i<list.length; i++) { path = dir+list[i]; open(path); title = getTitle(); run("Set Scale...", "distance=scale known=1 pixel=1 unit=um"); run("Scale Bar...", "width, height, font, color, background=None, location, bold"); saveAs("tiff", dirsave + title); close(); } -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Matt,
If your images are not in RGB, then the colour of your scalebar will follow the LUT colour. You can add "overlay" into run("Scale Bar...",...) so that the scalebar is an overlay on top of your image. Best Regards, John ________________________________________ From: ImageJ Interest Group [[hidden email]] On Behalf Of Matthew Pearson [[hidden email]] Sent: Thursday, July 12, 2012 5:56 PM To: [hidden email] Subject: batch mode scale bar macro Hi all, I'm trying to write my own macro that uses batch mode to open a folder of images, set a scale and place a scale bar on all of them then save away to a specified folder. I'm using the run("Set Scale...") function to set the scale of each image which seems to work fine. I've then created my own dialog which replicates the info needed for the inbuilt scale bar plus dialog- i don't use that as it requires an image to be open and i want the dialog to open at the start and then be used for all images before batch mode begins. The result of the macro is a white bar along the lower right of the image, no text is seen and i can't change the colour. Basically the run(scale bar...) function doesn't seem to 'see' or accept the variables i've created which i've plugged into the run(scale bar...) function. I think i've maybe made an error putting my variables into run(scale bar...) function so i've attached that bit of code to the email. I know there are other ways to make scale bars by not using the scale bar function by making rectangles of a certain size etc but this is the easiest method for me to get my head around. Thanks for the advice! Matt See extracted code below: colours = newArray("White", "Black", "Red", "Green", "Blue"); locations = newArray("Lower Left", "Lower Right", "Upper Left", "Upper Right"); Dialog.create("Scale Bar Options"); Dialog.addMessage("Fill in parameters"); Dialog.addNumber("Width of SB", 100); Dialog.addNumber("Height of SB", 3); Dialog.addNumber("Font Size", 14); Dialog.addChoice("Colour", colours); Dialog.addChoice("Location", locations); Dialog.show(); width = Dialog.getNumber(); height = Dialog.getNumber(); font = Dialog.getNumber(); color = Dialog.getChoice(); location = Dialog.getChoice(); setBatchMode(true); // runs up to 6 times faster for (i=0; i<list.length; i++) { path = dir+list[i]; open(path); title = getTitle(); run("Set Scale...", "distance=scale known=1 pixel=1 unit=um"); run("Scale Bar...", "width, height, font, color, background=None, location, bold"); saveAs("tiff", dirsave + title); close(); } -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi John,
Yes thanks thats a good point. However i changed some test images to RGB and tried again but still got only a white rectangle and no text. Perhaps you just can't use the scale bar plus in a macro.. Thanks, Matt On 12 Jul 2012, at 11:28, LIM Soon Yew John (IMB) wrote: > Hi Matt, > > If your images are not in RGB, then the colour of your scalebar will > follow the LUT colour. You can add "overlay" into run("Scale > Bar...",...) so that the scalebar is an overlay on top of your image. > > Best Regards, > John > ________________________________________ > From: ImageJ Interest Group [[hidden email]] On Behalf Of > Matthew Pearson [[hidden email]] > Sent: Thursday, July 12, 2012 5:56 PM > To: [hidden email] > Subject: batch mode scale bar macro > > Hi all, > > I'm trying to write my own macro that uses batch mode to open a folder > of images, set a scale and place a scale bar on all of them then save > away to a specified folder. > > I'm using the run("Set Scale...") function to set the scale of each > image which seems to work fine. I've then created my own dialog which > replicates the info needed for the inbuilt scale bar plus dialog- i > don't use that as it requires an image to be open and i want the > dialog to open at the start and then be used for all images before > batch mode begins. > > The result of the macro is a white bar along the lower right of the > image, no text is seen and i can't change the colour. Basically the > run(scale bar...) function doesn't seem to 'see' or accept the > variables i've created which i've plugged into the run(scale bar...) > function. I think i've maybe made an error putting my variables into > run(scale bar...) function so i've attached that bit of code to the > email. > > I know there are other ways to make scale bars by not using the scale > bar function by making rectangles of a certain size etc but this is > the easiest method for me to get my head around. > > Thanks for the advice! > Matt > > See extracted code below: > > colours = newArray("White", "Black", "Red", "Green", "Blue"); > locations = newArray("Lower Left", "Lower Right", "Upper Left", "Upper > Right"); > > Dialog.create("Scale Bar Options"); > Dialog.addMessage("Fill in parameters"); > Dialog.addNumber("Width of SB", 100); > Dialog.addNumber("Height of SB", 3); > Dialog.addNumber("Font Size", 14); > Dialog.addChoice("Colour", colours); > Dialog.addChoice("Location", locations); > Dialog.show(); > > width = Dialog.getNumber(); > height = Dialog.getNumber(); > font = Dialog.getNumber(); > color = Dialog.getChoice(); > location = Dialog.getChoice(); > > setBatchMode(true); // runs up to 6 times faster > for (i=0; i<list.length; i++) { > path = dir+list[i]; > open(path); > title = getTitle(); > > run("Set Scale...", "distance=scale known=1 pixel=1 unit=um"); > run("Scale Bar...", "width, height, font, color, background=None, > location, bold"); > > saveAs("tiff", dirsave + title); > close(); > } > > -- > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > Matt Pearson Microscopy and Imaging Facility MRC Human Genetics Unit University of Edinburgh Crewe Road Edinburgh EH4 2XU Tel: 0131 467 8425 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Matt,
> However i changed some test images to RGB and tried again but still got only a > white rectangle and no text. The problem is that you are not passing a single string with keyword=value pairs to the ScaleBar command. See Jérôme's guide at <http://imagej.nih.gov/ij/docs/macro_reference_guide.pdf> and compare the output of the Macro Recorder to the call you are making. You will have to use string concatenation such as run("Scale Bar...", "width="+ width +" height="+ height +" font=" + font +" color="+ color); or run("Scale Bar...", "width=&width height=&height font=&font color=&color); HTH, -tiago; -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |