Divide using macro



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


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.


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

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


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


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



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);


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

Best regards