Login  Register

Re: Jython/Python and ImageCalculator returning NoneType

Posted by J. Daniel Fenn on Feb 13, 2017; 6:04pm
URL: http://imagej.273.s1.nabble.com/Jython-Python-and-ImageCalculator-returning-NoneType-tp5018085p5018087.html

I did try the recorder, and that got me started.

I have found a way to make it work, but I'm not fully understanding why.

If I do NOT run .show() on the original imp1 and imp1 images, then
imp3.show works.

In other words, this DOES work.

''''
imp1 = ImagePlus(fImage)
imp2 = ImagePlus(dImage)

imp3 = ImageCalculator().run("Subtract create", imp1, imp2)

imp1.show()
imp2.show()
imp3.show()

''''

Whereas this

'''''
imp1 = ImagePlus(fImage).show()
imp2 = ImagePlus(dImage).show()

imp3 = ImageCalculator().run("Subtract create", imp1, imp2)
imp3.show()
'''''

does NOT work.

Am I doing something wrong by showing (.show()) the images before image
calculator?  This seems strange to me, but maybe I'm misunderstanding
something.

-Dan


On 02/13/2017 12:57 PM, Herbie wrote:

> Good day Dan,
>
> did you try the Recorder?
>
> Here is what I get as Java-Code (sorry no experience with Jython/Python):
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.*;
>
> public class My_Plugin implements PlugIn {
>
>     public void run(String arg) {
>         ImageCalculator ic = new ImageCalculator();
>         ImagePlus imp1 = WindowManager.getImage("Untitled");
>         ImagePlus imp2 = WindowManager.getImage("Untitled-1");
>         ImagePlus imp3 = ic.run("Subtract create 32-bit", imp1, imp2);
>         imp3.show();
>     }
>
> }
>
> Watch for eMail line breaks!
>
> HTH
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::::::::::::
> Am 13.02.17 um 18:26 schrieb J. Daniel Fenn:
>> I'm trying the following.
>>
>> '''''''
>> from ij import IJ, ImagePlus
>> from ij.plugin import ImageCalculator
>>
>> imp1 = ImagePlus(fImage).show()
>> imp2 = ImagePlus(dImage).show()
>>
>> imp3 = ImageCalculator().run("Subtract create", imp1, imp2)
>> imp3.show()
>>
>> '''''''''
>>
>> I get a NoneType error.
>>
>>
>>     imp3.show()
>> AttributeError: 'NoneType' object has no attribute 'show'
>>
>>
>> If I'm interpretting this correctly, then this
>>
>> https://imagej.nih.gov/ij/developer/api/ij/plugin/ImageCalculator.html#ImageCalculator--
>>
>>
>> suggests ImageCalculator should return an ImagePlus object (at least in
>> Java, and I'm using Jython).
>>
>> What am I doing wrong?  How can I get my Subtracted images to show in
>> python?
>>
>> Thanks
>> -Dan
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html