problem extracting channels from composite image

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

problem extracting channels from composite image

Aryeh Weiss
I generate a composite image by converting RGB to CIE

csc = ColorSpaceConverter()
labImp = csc.RGBToLab(inputImpDup)

Later, I want to extract one of the channels for additional processing.
Here is the code that should  do it

     labCompositeImp = CompositeImage(labImp, CompositeImage.GRAYSCALE)
     labCompositeImp.setTitle("comp")
     labCompositeImp.show()

     tmpImp = []
     ip = []
     for i in range(1,nChannels+1):
         labCompositeImp.setC(i)
         labCompositeImp.updateAndDraw()
         ip.append(labCompositeImp.getProcessor())
         print ip[-1]
         tmpImp.append(ImagePlus("ch_"+str(i), ip[-1]))
         tmpImp[-1].show()
         print tmpImp[-1].getTitle()
         wd = WaitForUserDialog("check images")
         wd.show()


And this code appears  to work , in that the three channels are
displayed after extracting them in the loop.

However, if I remove the WaitForUser, as in :

     labCompositeImp = CompositeImage(labImp, CompositeImage.GRAYSCALE)
     labCompositeImp.setTitle("comp")
     labCompositeImp.show()
     tmpImp = []
     ip = []
     for i in range(1,nChannels+1):
         labCompositeImp.setC(i)
         labCompositeImp.updateAndDraw()
         ip.append(labCompositeImp.getProcessor())
         print ip[-1]
         tmpImp.append(ImagePlus("ch_"+str(i), ip[-1]))
         tmpImp[-1].show()
         print tmpImp[-1].getTitle()

Then it displays three identical channels , and if I  check the diff
between those channels, it will be zero.
Sometime, the three displayed images contain two of one channel and one
of another.

So it looks like something is time or delay dependent.

Aside from this, is that  a simple way to grab one channel out of a
composite image (besides IJ.run commands?)

Also, I could not figure out how to get the labels of the channels of a
composite image? How is that done?

Thanks in advance for any help.

--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Fwd: problem extracting channels from composite image

Aryeh Weiss
Update to my inquiry.
With the WaitForUser, the problem is still there, just the display looks
correct until I click on one of the windows.

The code will work if I duplicate the ImageProcessor, as in
        ip.append(labCompositeImp.getProcessor().duplicate())

So I guess the ImageProcessors were conflicting.

Interesting, labCompositeImp.getProcessor(i) returns None, so I hve to
firwt set the channel and then getProcessor()

--aryeh

PS -- sorry that this is not interleaved with the message below, but I do
not have access to my regular mail client right now, and I this web client
is a bit awkward.



---------- Forwarded message ----------
From: Aryeh Weiss <[hidden email]>
Date: Thu, Jul 26, 2018 at 8:23 AM
Subject: problem extracting channels from composite image
To: ImageJ Interest Group <[hidden email]>


I generate a composite image by converting RGB to CIE

csc = ColorSpaceConverter()
labImp = csc.RGBToLab(inputImpDup)

Later, I want to extract one of the channels for additional processing.
Here is the code that should  do it

    labCompositeImp = CompositeImage(labImp, CompositeImage.GRAYSCALE)
    labCompositeImp.setTitle("comp")
    labCompositeImp.show()

    tmpImp = []
    ip = []
    for i in range(1,nChannels+1):
        labCompositeImp.setC(i)
        labCompositeImp.updateAndDraw()
        ip.append(labCompositeImp.getProcessor())
        print ip[-1]
        tmpImp.append(ImagePlus("ch_"+str(i), ip[-1]))
        tmpImp[-1].show()
        print tmpImp[-1].getTitle()
        wd = WaitForUserDialog("check images")
        wd.show()


And this code appears  to work , in that the three channels are displayed
after extracting them in the loop.

However, if I remove the WaitForUser, as in :

    labCompositeImp = CompositeImage(labImp, CompositeImage.GRAYSCALE)
    labCompositeImp.setTitle("comp")
    labCompositeImp.show()
    tmpImp = []
    ip = []
    for i in range(1,nChannels+1):
        labCompositeImp.setC(i)
        labCompositeImp.updateAndDraw()
        ip.append(labCompositeImp.getProcessor())
        print ip[-1]
        tmpImp.append(ImagePlus("ch_"+str(i), ip[-1]))
        tmpImp[-1].show()
        print tmpImp[-1].getTitle()

Then it displays three identical channels , and if I  check the diff
between those channels, it will be zero.
Sometime, the three displayed images contain two of one channel and one of
another.

So it looks like something is time or delay dependent.

Aside from this, is that  a simple way to grab one channel out of a
composite image (besides IJ.run commands?)

Also, I could not figure out how to get the labels of the channels of a
composite image? How is that done?

Thanks in advance for any help.

--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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