Bug in the IJ.run("Multiply...", "value=x") function


#1

I want to make you aware of a bug I ran into in a python script that I wrote to re-scale all my images. In the following code the multiplication commanded by the IJ.run command does not occur.

    Max = imp.getStatistics().max
    IJ.run(imp, "Divide...", "value="+str(Max))

    IJ.run(imp, "Multiply...", "value = 65535")

User Iarganda suggested to me the following code as an alternative solution, this works:

    # read processor (only works for 2D)
    ip = imp.getProcessor();
    # divide by maximum value
    ip.multiply( 1.0/Max )
    ip.resetMinAndMax()
    # multiply by new maximum
    ip.multiply( 65535 )
    ip.resetMinAndMax()

Thanks to Iarganda for the help!

Sverre


#2

Does not seem to be a bug. Just a white space issue in your "value · = · 65535" argument. Either of the following seems to work fine:

#@ImagePlus imp
from ij import IJ
IJ.run(imp, "Multiply...", "value=65535")
imp_max = imp.getStatistics().max
IJ.run(imp, "Multiply...", "value=%s" % imp_max)

#3

Yes you are right tferr, just a stupid mistake on my part. I remember having the same problem with spacing in the dividing, don’t know why I didn’t fix it in the multiplication…

Thanks!