I’m having an issue with a macro I recently wrote and am hoping someone can help. It is a relatively simple macro for detecting the size of a large object based on edge detection, thresholding, and binarization. I got the macro working, but after an update to a newer version of FIJI, the macro no longer works.
The macro was developed and works in FIJI 2.0.0-rc-68/1.52h. One of my users recently updated to FIJI 2.0.0-rc-69/1.52p. The Java versions are the same. I skimmed through the ImageJ release notes and did find a line that may be related:
1.52k 29 January 2019
◦ Thanks to Herbie, fixed a bug that caused the Process>Binary>Make Binary command to incorrectly set the threshold of 8-bit binary images.
This makes me wonder if there was some kind of bug in the 1.52h version I developed my macro in that was corrected in 1.52k, causing the macro to no longer work as it did when originally developed. Alternatively, there may be some default that changed that I am not explicitly calling out in the macro. I imagine I could make it work in the new version, but more importantly, I’d like to understand best practices for this kind of work to make sure that I am making more robust macros in the future that are less likely to break on version changes.
My code and a sample image are below. In 1.52h, this code identifies the area of the large object in the middle of the image. The same code in 1.52p gets the foreground and background reversed so that the erosions, dilations, and fill holes operate oppositely from intended. I tried adding the setThreshold option as mentioned in some posts I found in he forums, but that doesn’t seem to help. I tried changing the BlackBackground option to True, but that not only didn’t help, it seems to cause a difference between binary commands executed from the command editor or from the program menus (for example erosion and dilation has opposite effects depending on where you execute them from).
Adding to the confusion, I notice that the LUT gets inverted in the 1.52h version, but not in the 1.52p version. Again, it doesn’t matter to me what the color is, as long as the foreground/background is identified properly for the binary morphology operations.
Any suggestions would be greatly appreciated.
run("Duplicate...", "title=Thresh"); //create a copy of the image titled "Thresh"
run("8-bit"); //convert to 8-bit grayscale
run("Gray Morphology", "radius=2 type=circle operator=erode"); //gray morphology to smooth dark edgees
run("Find Edges"); //essentially the derivative of pixel intensty vs position - highlights contrast
run("Gray Morphology", "radius=4 type=circle operator=dilate"); // smooth edges to fill in minor gaps
run("Auto Threshold", "method=Li white");
setOption("BlackBackground", false); //binary conversion setting
//setThreshold(127, 255);
run("Make Binary"); //convert to binary image
run("Options...", "iterations=5 count=1 pad do=Dilate"); //Dilate to fill gaps in edge
run("Fill Holes"); //Fill center of defined perimeter
run("Options...", "iterations=5 count=1 pad do=Erode"); //Erode to undo previous dilation
run("Erode"); //Erode to undo enlarging effect of find edges
run("Open"); //Erode/Dilate to remove remaining small defects (dots) and smooth edges