Trouble with macro recording of color threshold

Sample image and/or code

Hi guys, I have been using image J to quantify the amount of horizontal fissures and vertical fissures on the surface of a cannula. I have found a fairly simply method that works, but it is time consuming, so I have attempted to record a macro to have less manual work per sample. However, the results of my macro are significantly different from when I run it manually. I am going to copy and paste all the settings/ steps I do manually and the results of that vs the macro and macro results

Original image:

4O.bmp (158.3 KB)
Color Threshold with following settings:

Then, convert image to 8-bit gray scale, where only black is that which I have selected in previous step.
Then, threshold so only black is included (basically just put settings on max)
Then, run particle analysis to get the following data and a mask of the results

4OFissures.bmp (53.9 KB)
ResultsFissuresManual.csv (11.4 KB)

This has been working great for what I want. I do this twice for the blue (fissures) and red (ridges) using different color thresholds. This is the macro I created to follow the steps I outlined above:

run("Color Threshold...");
// Color Thresholder 1.53h
// Autogenerated macro, single images only!
run("HSB Stack");
run("Convert Stack to Images");
for (i=0;i<3;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("Result of 0");
selectWindow("Result of Result of 0");
// Colour Thresholding-------------
//setThreshold(0, 0);
setOption("BlackBackground", false);
run("Convert to Mask");
run("Analyze Particles...", "  show=Masks display clear");

When I am recording this macro, the results are the same as the manual. However, when I run the macro, this is what I get:
4OFissuresManual.bmp (53.9 KB)
ResultsFissuresMacro.csv (12.5 KB)

I would really appreciate if anybody could figure out what my problem is, as I would love to have a working macro that allows me to do less work!

Converted text to code formatting </> button.

I would guess it is this step - manually you are using a threshold of 0, in your code you are not using a threshold of 0, you are using a threshold of "Default.

// in the code means the line is commented out and will not be run. Try commenting out the setAutoThreshold and re-enable the setThreshold(0,0)

I played around with it some more and I think the bulk of the issue is from the image calculator lines- the result of O it chooses as the primary result only has the filter for hue and not for the others I think… I do know that it is not the same as when I do it manually

It is not the image calculator lines, but I think there is some mix up with the options for black threshold and the background option. Your image ends up with an inverted LUT.
Try changing to white threshold and black background and see if that fixes it.

The problem is occurring either at the image calculator or in the steps before, because when I run just the color threshold macro and then due the threshold manually, it gives the same results. The mask created in these first steps is somewhat different (less thick in some places) than that created manually as I dont actually apply a filter when I do it manually I just set the threshold and it highlights what I want in black. Perhaps this is where the difference is?

I found the difference! There is some black in my original image from where the depth is undefined. This is included in the manual one but excluded in the macro… Will probably need to redo all my data with this new macro as it is probably more accurate