Quantcast

Jython/Python and ImageCalculator returning NoneType

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Jython/Python and ImageCalculator returning NoneType

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jython/Python and ImageCalculator returning NoneType

Herbie
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jython/Python and ImageCalculator returning NoneType

J. Daniel Fenn
In reply to this post by J. Daniel Fenn
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Jython/Python and ImageCalculator returning NoneType

Michael Entrup
Hi Dan,

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

The problem is quite simple to explain. The return type of show() is
void [1] and this results in imp1 and imp2 still contain None.

 > imp1 = ImagePlus(fImage)

This line uses the constructor of ImagePlus [2] (like new
ImagePlus(fImage) in Java) and the returned object is the newly created
ImagePlus. Therefore imp1 contains an ImagePlus instance.

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

This line is Ok, as you want to collect the result of the run() method.
The object, that is created by the constructor, is only used once to
call the run() method.

Best regards
Michael


[1]:
<a href="http://javadoc.imagej.net/ImageJ1/ij/ImagePlus.html#show()http://javadoc.imagej.net/ImageJ1/ij/ImagePlus.html#show(">http://javadoc.imagej.net/ImageJ1/ij/ImagePlus.html#show()http://javadoc.imagej.net/ImageJ1/ij/ImagePlus.html#show()
[2]:
http://javadoc.imagej.net/ImageJ1/ij/ImagePlus.html#ImagePlus(java.lang.String)


On 13.02.2017 19:04, J. Daniel Fenn wrote:

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

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