Make Thickness with the same color gradient between different samples

Hi everyone,
I have different samples. I would like to use the Thickness result to show my samples in 3D. But I found the Thickness is done sample-independent. So the color gradient will change with the sample’s change.

Is there a way to make expressions of thickness images with the same color gradient between different samples? But I think this needs to be done with a macro, because there is no such interaction option under BoneJ / Thickness. Or is it there, but I miss it?

I’m a novice to macro, and it’s very difficult for me. I hope you can give me some suggestions.

Thanks in advance.
Mengying

Thickness always stretches the display range from 0 to the maximum pixel value (local thickness) in the image. Because images have different maxima, the same display colour represents a different local thickness in each image. What you have to do is set the display range to the same values across all the images.

You can do it with the macro command setMinAndMax(min, max), like this:

myMaxValue = 60;  //<- set your desired max value to be displayed in the LUT here
setMinAndMax(0, myMaxValue);

You have to run this macro for every image.

If you include a scale bar in only one image it will be true for all of them.

You can also create a custom scale bar of any size like this, which can be handy if you are arranging elements in a more complicated figure.

//Maximum thickness to display. Make sure it's the same max as applied to the images!
myMaxValue = 60;
//Width of the scale bar
rampWidth = 128;
//Height of the scale bar 
rampHeight = 16; 

//The ramp image contains floating-point values from 0 to 1 running left to right
newImage("Untitled", "32-bit ramp", rampWidth, rampHeight, 1);
//Multiplying values stretches them linearly from 0 to your max value
run("Multiply...", "value="+myMaxValue);
//Set the display range to stretch the LUT from 0 to your max value
setMinAndMax(0, myMaxValue);
//Apply the Fire LUT
run("Fire");

Thanks @mdoube
It works perfectly!

I also try your other advice. I found that this code can generate a separate scale bar. It’s so nice. However, the scale bar generated by this method does not indicate a digital scale. How can I add it? Moreover, what is the “Multiply…” in this code used for? Is it used for batch processing? And the “Fire” in run(“Fire”) needs to fix according to my sample?

Best wishes.
Mengying

You have to add the numbers it in your layout program: I usually use Inkscape. You have to put 0 at the left and your max value at the right, then if you need to put some other markers, just use the align and distribute tools to spread them out and line them up.

I added some comments to the script in the original reply to explain what each line is doing.

Thank you for your detailed explanation and solved my problems.

Hello @mdoube,
I’m sorry, but there seems to be a little problem left to be solved.
Follow the code you offered, I can successfully change the slice LUT. But I can’t change the 3D viewer’s LUT. Why the color of the 3D view generated based on the slice that has changed LUT can’t be consistent with the slice?

Thanks in advance :smile:.
Mengying

I have tried for a long time and found that when importing data, if “Convert to 8-bit Graysacle” is checked, the 3D view’s color will change with the slice color. And if I check the “Convert to RGB”, it also seems to work! Although I don’t understand the reason behind this, and I don’t know if it’s correct, the color of the 3D view is at least changing correctly in my eyes.

If anyone has a similar problem with me, try it.

This is my preferred method for viewing stacks with LUTs in the 3D Viewer: set the LUT and the display range to the desired range, then Image>Type>RGB Color fixes the pixel values to RGB for the 3D Viewer to display. Note that converting to RGB is irreversible and wrecks the actual measurement data, so it is a step to be used only for display purposes (e.g. to visualise your results or to make a figure for publication) and not for analysis. It is important to save your measurement image or to duplicate it prior to converting to RGB.

OK! Thank you for your kind reminding. I will pay attention to it!