Hi All,
I am using ImageJ64 1.48c on MacOSX 10.7.5. I want to colour segment selections of images, measure them and create a visual record of where the ROIs are on the image. I created something similar to the following macro to achieve this. You can try it out on the "Fluorescent Cells" sample image in which you have selected a region to analyse. I will have a large number of images to analyse, with several colour channels in each, so I need to use it in batch mode. It works when BatchMode(false), but then does not work when BatchMode(true). I think that either the "RestoreSelection" command or the "Flatten" command doesn't work in Batch mode, at least in these circumstances. The updates to Version 1.47r and 1.46b were meant to fix the RestoreSelection/Batch mode incompatibility problem, but either it hasn't been fixed for all circumstances, or it has been "unfixed" in 1.48c, or Flatten is the problem. Can anyone suggest a fix or workaround to this issue? // 1. Choose destination folders for the masks, patch files indicating the location of each segmented ROI, and other data. DestinationFolder = getDirectory("Select or Create a primary Destination Folder for Your Data Files"); if (isOpen("ROI Manager")) { selectWindow("ROI Manager"); run("Close"); } img_title=getTitle(); Channel = "H1S1B1"; ChMask = Channel+"_Mask_"+img_title; setBatchMode(false); // 2. Convert composite RGB to simple single slice RGB files run("RGB Color"); img_title=getTitle(); selectWindow(img_title); run("Duplicate...", "title=RGB"); selectWindow(img_title); run("Duplicate...", "title=ChMask"); run("Threshold Colour"); // 3. Use Threshold Colour v1.12a (G. Landini 27/Sep/2010) to create a colour channel mask min=newArray(3); max=newArray(3); filter=newArray(3); run("HSB Stack"); run("Convert Stack to Images"); selectWindow("Hue"); rename("0"); selectWindow("Saturation"); rename("1"); selectWindow("Brightness"); rename("2"); min[0]=127; max[0]=255; 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(ChMask); // End Threshold Colour ------------ selectWindow("Threshold Colour"); run("Close"); // 4. Tidy up mask and save selectWindow(ChMask); run("Remove Outliers...", "radius=5 threshold=50 which=Bright"); run("Remove Outliers...", "radius=5 threshold=50 which=Dark"); run("Close-"); saveAs("tiff", DestinationFolder+ChMask); // 5. Identify colour patches using Analyze Particles. By using Restore Selection just prior to Analyze Particles, and choosing the Exclude Edge Particles option, only those patches contained wholly within the selected part of the image are analysed. selectWindow(ChMask); run("Set Measurements...", "area centroid center perimeter shape median skewness area_fraction stack limit redirect=None decimal=3"); run("Restore Selection"); run("Analyze Particles...", "size=30-Infinity circularity=0.00-1.00 show=Nothing display exclude clear summarize add in_situ stack"); // 6. Create and store an image indicating the identities of the patches on the RGB image selectWindow("RGB"); run("Restore Selection"); roiManager("Show All with labels"); run("Labels...", "color=white font=18 show draw"); run("Flatten"); Patches = Channel+"_Patches_"+img_title; saveAs("jpeg", DestinationFolder+Patches); selectWindow("RGB"); run("Close"); selectWindow(img_title); roiManager("reset"); |
On Sep 17, 2013, at 9:44 PM, Guy wrote:
> Hi All, > > I am using ImageJ64 1.48c on MacOSX 10.7.5. I want to colour segment > selections of images, measure them and create a visual record of where the > ROIs are on the image. I created something similar to the following macro to > achieve this. You can try it out on the "Fluorescent Cells" sample image in > which you have selected a region to analyse. I will have a large number of > images to analyse, with several colour channels in each, so I need to use it > in batch mode. It works when BatchMode(false), but then does not work when > BatchMode(true). I think that either the "RestoreSelection" command or the > "Flatten" command doesn't work in Batch mode, at least in these > circumstances. The updates to Version 1.47r and 1.46b were meant to fix the > RestoreSelection/Batch mode incompatibility problem, but either it hasn't > been fixed for all circumstances, or it has been "unfixed" in 1.48c, or > Flatten is the problem. Can anyone suggest a fix or workaround to this > issue? This bug is fixed in the ImageJ 1.48d daily build. The roiManager("Show All with labels") macro function was not working in batch mode. -wayne > // /1. Choose destination folders for the masks, patch files indicating the > location of each segmented ROI, and other data. / > DestinationFolder = getDirectory("Select or Create a primary Destination > Folder for Your Data Files"); > if (isOpen("ROI Manager")) { > selectWindow("ROI Manager"); > run("Close"); > } > img_title=getTitle(); > Channel = "H1S1B1"; > ChMask = Channel+"_Mask_"+img_title; > setBatchMode(*false*); > // /2. Convert composite RGB to simple single slice RGB files/ > run("RGB Color"); > img_title=getTitle(); > selectWindow(img_title); > run("Duplicate...", "title=RGB"); > selectWindow(img_title); > run("Duplicate...", "title=ChMask"); > run("Threshold Colour"); > // /3. Use Threshold Colour v1.12a (G. Landini 27/Sep/2010) to create a > colour channel mask/ > min=newArray(3); > max=newArray(3); > filter=newArray(3); > run("HSB Stack"); > run("Convert Stack to Images"); > selectWindow("Hue"); > rename("0"); > selectWindow("Saturation"); > rename("1"); > selectWindow("Brightness"); > rename("2"); > min[0]=127; > max[0]=255; > 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(ChMask); > // End Threshold Colour ------------ > selectWindow("Threshold Colour"); > run("Close"); > // /4. Tidy up mask and save/ > selectWindow(ChMask); > run("Remove Outliers...", "radius=5 threshold=50 which=Bright"); > run("Remove Outliers...", "radius=5 threshold=50 which=Dark"); > run("Close-"); > saveAs("tiff", DestinationFolder+ChMask); > // /5. Identify colour patches using Analyze Particles. By using Restore > Selection just prior to Analyze Particles, and choosing the Exclude Edge > Particles option, only those patches contained wholly within the selected > part of the image are analysed./ > selectWindow(ChMask); > run("Set Measurements...", "area centroid center perimeter shape median > skewness area_fraction stack limit redirect=None decimal=3"); > run("Restore Selection"); > run("Analyze Particles...", "size=30-Infinity circularity=0.00-1.00 > show=Nothing display exclude clear summarize add in_situ stack"); > // /6. Create and store an image indicating the identities of the patches on > the RGB image/ > selectWindow("RGB"); > run("Restore Selection"); > roiManager("Show All with labels"); > run("Labels...", "color=white font=18 show draw"); > run("Flatten"); > Patches = Channel+"_Patches_"+img_title; > saveAs("jpeg", DestinationFolder+Patches); > selectWindow("RGB"); > run("Close"); > selectWindow(img_title); > roiManager("reset"); > > > > > > > > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/ROI-Manager-in-Batch-Mode-tp5004840.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 |
Free forum by Nabble | Edit this page |