Divide using macro

imagej

#1

Hi everyone

Trying to divide a image by a number like 500 and the result is always a integer number. Can you please help me to understand how I can change this?

Best regars

Hugo Trindade


#2

Convert the image to a 32-bit image first. This then allows for decimal values. 8-bit and 16-bit are both integer formats, and therefore pixels can only have integer values.


#3

You need to first convert the image to 32-bit floating point. Here is an example:

   run("Boats (356K)");
   run("32-bit");
   run("Divide...", "value=500");
   resetMinAndMax();
   getStatistics(area, mean, min, max);
   print("mean="+mean+", min="+min+", max="+max);

#4

It was that. Thank you for your help.Best regards


#5

One last question: how can I save 32 bits images in DICOM?

If I do my operations and then reconvert to 16 bits the values change.

Thank you

Hugo


#6

This depends on the Scale When Converting user setting in Edit > Options > Conversions…

To make sure the values are preserved, you can scale your image to the target range before converting:

setMinAndMax(0, 65535);
run("16-bit");

#7

Thank you. It works well with _Scale When Converting. The macro code does not, but I can work with that,

Best regards