Dear Esteemed List,
I'd like to create a macro that will select an ROI based on the Hue range I define in order to subsequently delete those regions/values from my histological RGB images. Using Landini's Threshold Colour Plugin, I set my hue, saturation and brightness settings, press "Select" in the Threshold Colour dialogue, and press "Macro" in the Threshold Colour dialogue in order to generate the code in the recorder (see below). I subsequently hit the delete key on my keyboard to delete my selection (this adds run("Clear", "slice"); to my macro recorder). THE PROBLEM: When I run this macro, it stalls immediately prior to the run("Clear", "slice"); line and gives an error that indicates that the "Clear" command requires a selection. I'm confused b/c I HAVE pressed the "Select" button within the CT dialogue, but I don't think it's actually doing anything that gets recorded in the macro. If I do this process manually, I get the result I want: an image with portions of it defined by the hue range deleted. But, the macro isn't working. MY QUESTION: is there a way to either a. make the CT dialogue record my selection in the macro OR b. select this color thresholded area as an ROI in some other manner?? Any and ALL help much appreciated!! Many thanks! dani run("Threshold Colour"); // Threshold Colour v1.12a------ // Autogenerated macro, single images only! // G. Landini 27/Sep/2010. // min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=0; max[0]=207; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=0; max[2]=255; filter[2]="pass"; for (i=0;i<3;i++){ selectWindow(""+i); setThreshold(min[i], max[i]); run("Convert to Mask"); if (filter[i]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (i=0;i<3;i++){ selectWindow(""+i); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Threshold Colour ------------ run("Clear", "slice"); |
On Tuesday 16 Oct 2012 00:42:25 you wrote:
> Dear Esteemed List, > > I'd like to create a macro that will select an ROI based on the Hue range I > define in order to subsequently delete those regions/values from my > histological RGB images. Using Landini's Threshold Colour Plugin, I set my > hue, saturation and brightness settings, press "Select" in the Threshold > Colour dialogue, and press "Macro" in the Threshold Colour dialogue in order > to generate the code in the recorder (see below). I subsequently hit the > delete key on my keyboard to delete my selection (this adds run("Clear", > "slice"); to my macro recorder). > > THE PROBLEM: When I run this macro, it stalls immediately prior to the > > run("Clear", "slice"); > > line and gives an error that indicates that the "Clear" command requires a > selection. The Macro button on that plugin only records a macro that binarises the image according to the slider and checkbox settings. It is unaware of the status of the other buttons. It can't record everything that could potentially be done through the GUI. If you want to make the thresholded areas zero, maybe you could subtract the binarised result from the original. Or you could create a selection on the binary image and transfer it to the original via the Restore Selection command and the clear it. Regards Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by danih
Hi Dani,
as I see it, the first problem is that the macro created by "Threshold Colour" is destructive. You have to duplicate the image first. After running the macro created by "Threshold Colour", you get a mask, not a selection. You need Edit>Selection>Create Selection. Then you can select the original image and transfer the selection to the original image via Edit>Selection>Restore Selection. You can also transfer the selection via the ROI Manager (before adding to the ROI manager, clear an other selections in the ROI Manager's list). Michael ________________________________________________________________ On Oct 16, 2012, at 01:42, danih wrote: > Dear Esteemed List, > > I'd like to create a macro that will select an ROI based on the Hue range I > define in order to subsequently delete those regions/values from my > histological RGB images. Using Landini's Threshold Colour Plugin, I set my > hue, saturation and brightness settings, press "Select" in the Threshold > Colour dialogue, and press "Macro" in the Threshold Colour dialogue in order > to generate the code in the recorder (see below). I subsequently hit the > delete key on my keyboard to delete my selection (this adds run("Clear", > "slice"); to my macro recorder). > > THE PROBLEM: When I run this macro, it stalls immediately prior to the > > run("Clear", "slice"); > > line and gives an error that indicates that the "Clear" command requires a > selection. > > I'm confused b/c I HAVE pressed the "Select" button within the CT dialogue, > but I don't think it's actually doing anything that gets recorded in the > macro. If I do this process manually, I get the result I want: an image > with portions of it defined by the hue range deleted. But, the macro isn't > working. > > MY QUESTION: is there a way to either a. make the CT dialogue record my > selection in the macro OR b. select this color thresholded area as an ROI in > some other manner?? Any and ALL help much appreciated!! > > Many thanks! > > dani > > > run("Threshold Colour"); > // Threshold Colour v1.12a------ > // Autogenerated macro, single images only! > // G. Landini 27/Sep/2010. > // > min=newArray(3); > max=newArray(3); > filter=newArray(3); > a=getTitle(); > run("HSB Stack"); > run("Convert Stack to Images"); > selectWindow("Hue"); > rename("0"); > selectWindow("Saturation"); > rename("1"); > selectWindow("Brightness"); > rename("2"); > min[0]=0; > max[0]=207; > filter[0]="pass"; > min[1]=0; > max[1]=255; > filter[1]="pass"; > min[2]=0; > max[2]=255; > filter[2]="pass"; > for (i=0;i<3;i++){ > selectWindow(""+i); > setThreshold(min[i], max[i]); > run("Convert to Mask"); > if (filter[i]=="stop") run("Invert"); > } > imageCalculator("AND create", "0","1"); > imageCalculator("AND create", "Result of 0","2"); > for (i=0;i<3;i++){ > selectWindow(""+i); > close(); > } > selectWindow("Result of 0"); > close(); > selectWindow("Result of Result of 0"); > rename(a); > // Threshold Colour ------------ > run("Clear", "slice"); > > > > -- > View this message in context: http://imagej.1557.n6.nabble.com/Threshold-Colour-select-macro-question-tp5000412.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 |
In reply to this post by danih
Dear Michael and Gabriel,
Thank you so very much! You were absolutely right!! I had to duplicate the original, create a selection based on the color threshold (after converting it to 8bit) , then restore the selection in the original, then delete. My batch is running perfectly now. Thanks again!! The new/improved code is pasted below: imgName=getTitle(); run("Duplicate...", "title=1.tif"); run("Threshold Colour"); // Threshold Colour v1.12a------ // Autogenerated macro, single images only! // G. Landini 27/Sep/2010. // min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=0; max[0]=207; filter[0]="pass"; min[1]=0; max[1]=255; filter[1]="pass"; min[2]=0; max[2]=255; filter[2]="pass"; for (i=0;i<3;i++){ selectWindow(""+i); setThreshold(min[i], max[i]); run("Convert to Mask"); if (filter[i]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (i=0;i<3;i++){ selectWindow(""+i); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Threshold Colour ------------ run("8-bit"); run("Create Selection"); selectWindow(imgName); run("Restore Selection"); run("Clear", "slice"); -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by danih
Hello,
I am trying to run this as a macro to process a folder of images but the macro stops after only processing one. This is the code I am using: inputDir = getDirectory("Please select a directory for processing"); allFiles = getFileList(inputDir); outputDir1 = getDirectory("Please select a directory for saving Color Threshold Images"); outputDir2 = getDirectory("Please select a directory for saving inverted 8bit Images"); setBatchMode(true); for(i=0; i<allFiles.length; i++) { path = inputDir + allFiles[i]; if(!endsWith(path, "/")) open(path); if(nImages>=1) { if(endsWith(path, "f")) { t = getTitle(); s = lastIndexOf(t, '.'); t = substring(t, 0, s); t = replace(t, " ", "_"); t1 = t + "-ColorThreshold"; t2 = t + "-8bit"; run("Duplicate...", " "); run("Threshold Colour"); // Threshold Colour v1.13------ // Autogenerated macro, single images only! // G. Landini 30/Aug/2011. // min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=63; max[0]=206; filter[0]="stop"; min[1]=18; max[1]=255; filter[1]="pass"; min[2]=11; max[2]=255; filter[2]="pass"; for (i=0;i<3;i++){ selectWindow(""+i); setThreshold(min[i], max[i]); run("Convert to Mask"); if (filter[i]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (i=0;i<3;i++){ selectWindow(""+i); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Threshold Colour ------------ run("8-bit"); run("Create Selection"); selectWindow("SBM-2-AT8-LVL1-34-sl11-CurvesAdj.tif"); run("Restore Selection"); setBackgroundColor(255, 255, 255); run("Make Inverse"); run("Clear", "slice"); run("Select None"); saveAs("Tiff", outputDir1 + t1 + ".tif"); run("8-bit"); saveAs("Tiff", outputDir2 + t2 + ".tif"); run("Close"); } } } Any suggestions would be very much appreciated! Kind regards, Tate |
Hello List,
Has anybody found a solution for the problem of yorkh2/Tate? I'm struggling with the same problem: I cannot run the Color Threshold Macro on multiple files.. Thanks for any help Andreas Code I'm using: dir1 = "......"; dir2 = "........."; list = getFileList(dir1); setBatchMode(true); for (i=0; i<list.length; i++) { showProgress(i+1, list.length); open(dir1+list[i]); run("Color Threshold..."); // Color Thresholder 2.0.0-rc-30/1.49s // Autogenerated macro, single images only! min=newArray(3); max=newArray(3); filter=newArray(3); a=getTitle(); run("HSB Stack"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=40; max[0]=125; filter[0]="pass"; min[1]=78; max[1]=255; filter[1]="pass"; min[2]=0; max[2]=255; filter[2]="pass"; for (i=0;i<3;i++){ selectWindow(""+i); setThreshold(min[i], max[i]); run("Convert to Mask"); if (filter[i]=="stop") run("Invert"); } imageCalculator("AND create", "0","1"); imageCalculator("AND create", "Result of 0","2"); for (i=0;i<3;i++){ selectWindow(""+i); close(); } selectWindow("Result of 0"); close(); selectWindow("Result of Result of 0"); rename(a); // Colour Thresholding------------- saveAs("TIFF", dir2+list[i]); close(); } setBatchMode(false); |
Hello Andreas and others,
Guessing you've solved this problem by now. If not I came across Arjun Mehta article 'How to Automate ImageJ Analysis with Macros and Batch Processing' whilst trying to tackle a similar problem to yours. You can find it on Scribd via this url:https://www.scribd.com/doc/95224926/How-to-Automate-ImageJ-Analysis-With-Macros-and-Batch-Processing At the end of the article Arjun describes how to batch process, which may solve your problem. Alex |
Hi Alex,
I used the Multiple Image Processor in Fiji which worked nicely for me. regards Andreas |
Free forum by Nabble | Edit this page |