Hello All,
To make a long story short, we have been collecting tiled image data of some specimens which have two distinct regions labeled with a red and blue dye respectively. One of the dyes is fluorescent, so I have been collecting a series of images which capture the specimen as a whole and then another that just capture the fluorescent dye region. I wrote a macro which iterates through all of the directories of images and separates the red and blue regions for quantification. As a validation step, I have the macro creating thumbnail images of each specimen wherein the segmented region is stamped into the thumbnail image. That way, I can quickly go back and skim the images to make sure that the segmentation is working well and also check any cases that seem strange from just the numbers. The main problem I seem to be having is with the "Draw" command for stamping the ROI onto the thumbnail image. This seems to work very inconsistently when called from a macro (which is frustrating). The macro, overall, runs fine otherwise. For instance, last week, this is the output that the macro below was giving when run from my desktop computer: <http://imagej.1557.x6.nabble.com/file/t379027/3434_0009_S1_1.jpg> When I went to re-run the analysis earlier, this is the output it was giving for the same thumbnail: <http://imagej.1557.x6.nabble.com/file/t379027/3434_0009_S1.jpg> No changes or updates have been made to ImageJ as far as I know. Further, the "Draw" command works just fine when done manually (i.e. - when I draw a line on the image and then manually go to "Edit>Draw"). Seems to just be finicky when called from a macro. The same code works fine from my laptop (which has the same version installed). Are there any alternatives to Draw that I might use in my macro instead? If not, anybody have any ideas of what I might be able to do to get "Draw" to work a little more consistently? The full macro (quite long) is below... //Pick the main directory where all the data is stored main = getDirectory("Source Directory "); outputDir = getDirectory("Output Directory "); //temp comment out //Turn on batch mode setBatchMode(true); //Get files mouseList = getFileList(main); //sectionList = getFileList(main); setBackgroundColor(255, 255, 0); setForegroundColor(255, 255, 0); //Loop through mouse directories. Note - "Tiff Virtual Stack..." and "Bio-Formats" give memory errors. "Open()" works fine though. print("\\Clear"); print("MOUSE #" + ";" + "SLIDE #" + ";" + "SECTION ID" + ";" + "ROIs" + ";" + "MAX AREA"); for(k=0; k<mouseList.length; k++){ mousePath = outputDir + substring(mouseList[k], 0,4) + File.separator; //Create output directory for thumbnails if does not exist if (!File.exists(mousePath)) File.makeDirectory(mousePath); sectionDir = main + substring(mouseList[k], 0,4); sectionList = getFileList(main + mouseList[k]); //Iterate through the sections for each mouse for(i=0; i<sectionList.length; i++){ //run("TIFF Virtual Stack...", "open=["+main + slideList[i]+"]"); //run("Bio-Formats (Windowless)", "open=["+main + slideList[i]+"]"); open(sectionDir + File.separator + sectionList[i]); run("Set Scale...", "distance=0 global"); //Get image dimensions height = getHeight(); width = getWidth(); size = height * width; //Scale background subtraction, blur, and line width based on image size sigma = round(size * 0.0000008); if (round(size * 0.00009) < 1800){ radius = round(size * 0.00009); } else { radius = 1800; } line = size * 0.0000003; setLineWidth(line); //Analyze the channels to create binary masks of red and blue regions run("Gaussian Blur...", "sigma=["+sigma+"]"); fluorChan = "C1-" + sectionList[i]; transChan = "C2-" + sectionList[i]; nameLength = lengthOf(sectionList[i]) - 4; duplFluor = "C1-" + substring(sectionList[i], 0, nameLength) + "-1.tif"; duplTrans = "C2-" + substring(sectionList[i], 0, nameLength) + "-1.tif"; run("Split Channels"); run("Grays"); run("Invert"); run("Subtract Background...", "rolling=["+radius+"]"); selectWindow(fluorChan); run("Grays"); run("Duplicate...", " "); selectWindow(transChan); run("Duplicate...", " "); selectWindow(duplFluor); run("Auto Threshold", "method=Otsu ignore_black white"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); run("Dilate"); selectWindow(duplTrans); run("Auto Threshold", "method=Otsu ignore_black white"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); run("Erode"); imageCalculator("Subtract create", duplTrans, duplFluor); binScar = "Result of " + duplTrans; selectWindow(binScar); run("Analyze Particles...", "size=100-Infinity show=Nothing clear add"); //Find the biggest ROI numROIs = roiManager("count"); if (numROIs>1) { area=newArray(numROIs); for (j=0; j<numROIs;j++){ roiManager("select", j); getStatistics(area[j], mean, min, max, std, histogram); } areaLarge = 0; for (j=0; j<numROIs; j++){ if (area[j]>areaLarge) { areaLarge=area[j]; large = j; } } } else { roiManager("select", 0); getStatistics(area, mean, min, max, std, histogram); areaLarge = area; large = 0; } //Print stats print(substring(sectionList[i], 0, 4) + ";" + substring(sectionList[i], 5, 9) + ";" + substring(sectionList[i], 10, 12) + ";" + numROIs + ";" + areaLarge); //+ ";" + substring(sectionList[i], 5, 9) + ";" + substring(sectionList[i], 10, 12) + ";" numROIs + ";" + areaLarge); //Create thumbnails for validation imageCalculator("Difference create 32-bit", transChan, fluorChan); imgScar = "Result of " + transChan; selectWindow(imgScar); run("16-bit"); run("Enhance Contrast", "saturated=0.35"); selectWindow(fluorChan); run("Enhance Contrast", "saturated=0.35"); run("Merge Channels...", "c1=["+fluorChan+"] c3=["+imgScar+"] create"); run("RGB Color"); roiManager("Select", large); run("Draw", "slice"); run("Select None"); newWidth = 256; newHeight = getHeight() * round(256 / getHeight()); run("Size...", "width=["+newWidth+"] height=["+newHeight+"] depth=1 constrain average interpolation=Bicubic"); run("8-bit Color", "number=256"); thumbName = sectionList[i]; imagePath = mousePath + thumbName; saveAs("Tiff", imagePath); close("*"); call("java.lang.System.gc"); } //Save the log with all the measurements logPath = mousePath + substring(mouseList[k], 0, 4) + "_results.txt"; selectWindow("Log"); saveAs("Text", logPath); //Close everything and run garbage collection to free up memory run("Close All"); call("java.lang.System.gc"); //Make sure the log is clear before starting the next mouse print("\\Clear"); print("MOUSE #" + ";" + "SLIDE #" + ";" + "SECTION ID" + ";" + "ROIs" + ";" + "MAX AREA"); } Thanks in advance! -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |