Login  Register

How to color differently each slice of a stack or each ImageProcessor

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

How to color differently each slice of a stack or each ImageProcessor

thehobbit
Hello everyone,

I'm new to ImageJ and I'm trying to write a plugin that colors each slice of an ImageStack differently one from another.
I'm working with DICOM images.
In particular, I need to select an area of a slice and change the color of it, adding transparency.
I tried different solutions, but I was able only to color all the slices of the stack in the same way.
I tried also to work with ImageProcessors, and they works fine for my problem; but here comes another one:
as I said in the subject, I need a color transparency, in such a way that the selected area is colored and at the same time I can see what there is behind it. But ImageProcessors seems to work at a very low level, and I'm able only to change the colours of the pixels(without transparency), losing previous data.

Can you help me with this please?
Thanks in advance.
 
 
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to color differently each slice of a stack or each ImageProcessor

ctrueden
Hi Ferdinando,

> I'm new to ImageJ and I'm trying to write a plugin that colors each
> slice of an ImageStack differently one from another.

You can use RGB Color images to color each slice however you like.

> In particular, I need to select an area of a slice and change the
> color of it, adding transparency.

ImageJ does not support alpha channels directly. To replicate the
appearance of an alpha channel you would have to do the math yourself.
Michael Schmid's Alpha Channel plugin [1] may be useful to you for that.

If what you want is to read or write PNG data with an alpha channel, but
don't care so much about visualizing the transparency in ImageJ
specifically, then see this thread [2].

Regards,
Curtis

[1]
http://imagejdocu.tudor.lu/doku.php?id=plugin:utilities:alpha_channel:start
[2] http://permalink.gmane.org/gmane.comp.java.imagej/20228


On Sun, Nov 4, 2012 at 10:36 AM, thehobbit <[hidden email]> wrote:

> Hello everyone,
>
> I'm new to ImageJ and I'm trying to write a plugin that colors each slice
> of
> an ImageStack differently one from another.
> I'm working with DICOM images.
> In particular, I need to select an area of a slice and change the color of
> it, adding transparency.
> I tried different solutions, but I was able only to color all the slices of
> the stack in the same way.
> I tried also to work with ImageProcessors, and they works fine for my
> problem; but here comes another one:
> as I said in the subject, I need a color transparency, in such a way that
> the selected area is colored and at the same time I can see what there is
> behind it. But ImageProcessors seems to work at a very low level, and I'm
> able only to change the colours of the pixels(without transparency), losing
> previous data.
>
> Can you help me with this please?
> Thanks in advance.
>
>
>
>
>
> --
> View this message in context:
> http://imagej.1557.n6.nabble.com/How-to-color-differently-each-slice-of-a-stack-or-each-ImageProcessor-tp5000664.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> 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
| More
Print post
Permalink

Re: How to color differently each slice of a stack or each ImageProcessor

thehobbit
Hi, thanks for the replay.
Probably I did not explain the problem well, sorry, my english is not that good.
I have problems to draw on each single slice using JAVA.
When I draw some ROI on an image, all other images on the stack suffer the same modification, but I need only to draw on that specific slice.
I try to write here an example:


//This is a function I found on the internet and which I modified to my own needs
//the value of the variable imp is passed as IJ.getImage();

void labeltmp(ImagePlus imp, int x, int y) {
                Roi roi = imp.getRoi();
                if (roi != null) {
                        if (!(roi instanceof ShapeRoi))
                                roi = new ShapeRoi(roi);
                        ShapeRoi roiShape = (ShapeRoi) roi;
                        roiShape.or(getBrushRoi(x, y, brushWidth));
                } else
                        roi = getBrushRoi(x, y, brushWidth);
               
                roi.setFillColor(fillColor);
                imp.setRoi(roi);
                imp.updateAndDraw();
               
}

ShapeRoi getBrushRoi(int x, int y, int width) {
        return new ShapeRoi(new OvalRoi(x - width / 2, y - width / 2, width, width));
    }

This function works well, and draws a roi like a brush tool.
The problem, as explained before, is that this type of solution draws a Roi on all the images of the stack, even if I'm working on the 30th slice of 60.
I tried several functions like roi.setPosition(...) ecc.
I don't know if there is something wrong with using IJ.getImage(), or if there are some functions that get a single slice and automatically set the modifications on the ImageStack.

I hope the problem is clear now.
Thank you for your support.

Ferdinando
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to color differently each slice of a stack or each ImageProcessor

Rasband, Wayne (NIH/NIMH) [E]
On Nov 5, 2012, at 1:45 PM, thehobbit wrote:

> Hi, thanks for the replay.
> Probably I did not explain the problem well, sorry, my english is not that
> good.
> I have problems to draw on each single slice using JAVA.
> When I draw some ROI on an image, all other images on the stack suffer the
> same modification, but I need only to draw on that specific slice.

You need to use an Overlay. Here is a JavaScript example that adds a differently colored transparent ROI to each image in a stack:

  imp = IJ.openImage("http://imagej.nih.gov/ij/images/mri-stack.zip");
  n = imp.getStackSize();
  width = imp.getWidth();
  alpha = 0.4;
  ran = new Random();
  overlay = new Overlay();
  x=0; y=0; w=50; h=50;
  for (i=1; i<=n; i++) {
     imp.setSlice(i);
     roi = new OvalRoi(x, y, w, h);
     roi.setPosition(i);
     r = ran.nextDouble();
     g = ran.nextDouble();
     b = ran.nextDouble();
     roi.setFillColor(new Color(r,g,b,alpha));
     overlay.add(roi);
     x+=width/n; y+=width/n;
  }
  imp.setOverlay(overlay);
  imp.setSlice(1);
  imp.show();

-wayne


> I try to write here an example:
>
>
> //This is a function I found on the internet and which I modified to my own
> needs
> //the value of the variable imp is passed as IJ.getImage();
>
> void labeltmp(ImagePlus imp, int x, int y) {
> Roi roi = imp.getRoi();
> if (roi != null) {
> if (!(roi instanceof ShapeRoi))
> roi = new ShapeRoi(roi);
> ShapeRoi roiShape = (ShapeRoi) roi;
> roiShape.or(getBrushRoi(x, y, brushWidth));
> } else
> roi = getBrushRoi(x, y, brushWidth);
>
> roi.setFillColor(fillColor);
> imp.setRoi(roi);
> imp.updateAndDraw();
>
> }
>
> ShapeRoi getBrushRoi(int x, int y, int width) {
>        return new ShapeRoi(new OvalRoi(x - width / 2, y - width / 2, width,
> width));
>    }
>
> This function works well, and draws a roi like a brush tool.
> The problem, as explained before, is that this type of solution draws a Roi
> on all the images of the stack, even if I'm working on the 30th slice of 60.
> I tried several functions like roi.setPosition(...) ecc.
> I don't know if there is something wrong with using IJ.getImage(), or if
> there are some functions that get a single slice and automatically set the
> modifications on the ImageStack.
>
> I hope the problem is clear now.
> Thank you for your support.
>
> Ferdinando
>
>
>
>
> --
> View this message in context: http://imagej.1557.n6.nabble.com/How-to-color-differently-each-slice-of-a-stack-or-each-ImageProcessor-tp5000664p5000680.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> 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
| More
Print post
Permalink

Re: How to color differently each slice of a stack or each ImageProcessor

thehobbit
Thank you very much! It works good!
I figured out that the real problem was also related to Orthogonal_Views(which I used for my work), as it seems to refresh each time the whole image, so the Roi selection, also with your solution, continued to disappear.
Thank you again!

Ferdinando