Re: Retrieving channel Image Processors from Hyperstack

Posted by Wayne Rasband-2 on
URL: http://imagej.273.s1.nabble.com/Retrieving-channel-Image-Processors-from-Hyperstack-tp5020342p5020348.html

> On Mar 27, 2018, at 4:57 AM, Greg <[hidden email]> wrote:
>
> Hello,
>
> I found some odd/surprising behavior when trying to extract the image
> processors from a Hyperstack, in jython:

It appears the ImageProcessors are sharing a pixel array. You can work around this problem by changing

   “ip = orig.getProcessor()"

to

   ip = orig.getProcessor().duplicate()

-wayne


> from ij import IJ,ImagePlus
>
> orig = IJ.getImage()
>
> imps = []
> for chan in range(1,4):
>    print chan
>    orig.setPosition(chan,1,1)
>    ip = orig.getProcessor()
>    print ip.getPixel(100,100)
>    imps.append( ImagePlus(str(chan),ip))
>
> for imp in imps:
>    ip2 = imp.getProcessor()
>    print ip2.getPixel(100,100)
>    imp.show()
>
> With this I get three times exactly the same extracted ImagePlus, as opposed
> to the expected three different images: one for each channel. The first
> 'ip.getPixel' first shows different values indicating that I work indeed on
> different processors, the 2nd 'ip2.getPixel' shows that it is the same for
> every Image Plus; could that be a jython issue? I attach a minimal example
> stack.  IPChannelTest.tif
> <http://imagej.1557.x6.nabble.com/file/t380220/IPChannelTest.tif>  
>
> Best,
> Greg
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/

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