Alpha-Channel-PlugIn as Macro

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

Alpha-Channel-PlugIn as Macro

Marie Rasta
Dear all,
By using the Alpha_Channel_Plugin as PlugIn it works perfectly.
But I got Problems by using the PlugIn Alpha Channel
(http://imagejdocu.tudor.lu/doku.php?id=plugin:utilities:alpha_channel:start)
in my own PlugIn. There is no error-message, exception...but it seems the
plugIn can't change the fresh copied forground image, but he think he can
Some ideas, experience?
Here my method:

         /**
         * Make transparent
         *
         */
        public static ImagePlus TransparentOverlay(ImagePlus imp, ImagePlus imp2) {
                IJ.selectWindow("background");
                IJ.run("RGB Color");
                //IJ.run("8-bit Color", "number=256");
                IJ.run("32-bit");
                IJ.selectWindow("forground");
                IJ.run("RGB Color");
                IJ.run("8-bit Color", "number=256");

                for (int i = 1; i <= imp.getStackSize(); i++) {
                        ImageWindow win = (ImageWindow) WindowManager
                                        .getWindow("forground");
                        imp = win.getImagePlus();
                        imp.setSlice(i);
                        imp.setRoi(0, 0, imp.getWidth(), imp.getHeight());
                        imp.copy(true);
                        //imp.copy();
                        win = (ImageWindow) WindowManager.getWindow("background");
                        imp2 = win.getImagePlus();
                        imp2.setSlice(i);
                        imp2.paste();
                        IJ.run("Alpha Channel",
                                        "alpha=forground range=50 enlarge=0 smooth=2.0");

                        imp2.updateAndRepaintWindow();

                }

                return imp2;
        }


Greetings and thank you in advance
 Marie

 --
 --

 Dipl. Ing. (FH) Marie-Alexandra Rastädter
 Institut für Medizinische Physik und Strahlenschutz
 Technische Hochschule Mittelhessen

 Arbeitsgruppe: Biomedizinische Bildverarbeitung

 Büro: Q 0.02
 Gutfleischstr. 3, 35390 Gießen
 Telefon: 0641 309 2568

 www.thm.de/imps

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

Re: Alpha-Channel-PlugIn as Macro

Michael Schmid
Hi Marie,

are you sure that you want to use the same image ("forground" in your plugin) as a source of copying and as the alpha channel, i.e., as the value determining the transparency? The latter image is determined by "alpha=..." when running the plugin.

Usually, one has one image that gets copied and pasted onto the original (the background), and a separate one that determines the transparency.

Also, please note that the Alpha Channel plugin won't work correctly with 8-bit Color images. It needs either RGB or grayscale (A color lookup table is fine as long as you are happy with having the same LUT for both images that should be combined).

Michael
________________________________________________________________
On Sep 4, 2014, at 15:06, Marie-Alexandra Rastädter wrote:

> Dear all,
> By using the Alpha_Channel_Plugin as PlugIn it works perfectly.
> But I got Problems by using the PlugIn Alpha Channel
> (http://imagejdocu.tudor.lu/doku.php?id=plugin:utilities:alpha_channel:start)
> in my own PlugIn. There is no error-message, exception...but it seems the
> plugIn can't change the fresh copied forground image, but he think he can
> Some ideas, experience?
> Here my method:
>
>         /**
> * Make transparent
> *
> */
> public static ImagePlus TransparentOverlay(ImagePlus imp, ImagePlus imp2) {
> IJ.selectWindow("background");
> IJ.run("RGB Color");
> //IJ.run("8-bit Color", "number=256");
> IJ.run("32-bit");
> IJ.selectWindow("forground");
> IJ.run("RGB Color");
> IJ.run("8-bit Color", "number=256");
>
> for (int i = 1; i <= imp.getStackSize(); i++) {
> ImageWindow win = (ImageWindow) WindowManager
> .getWindow("forground");
> imp = win.getImagePlus();
> imp.setSlice(i);
> imp.setRoi(0, 0, imp.getWidth(), imp.getHeight());
> imp.copy(true);
> //imp.copy();
> win = (ImageWindow) WindowManager.getWindow("background");
> imp2 = win.getImagePlus();
> imp2.setSlice(i);
> imp2.paste();
> IJ.run("Alpha Channel",
> "alpha=forground range=50 enlarge=0 smooth=2.0");
>
> imp2.updateAndRepaintWindow();
>
> }
>
> return imp2;
> }
>
>
> Greetings and thank you in advance
> Marie

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

Re: Alpha-Channel-PlugIn as Macro

Marie Rasta
In reply to this post by Marie Rasta
Hi Michael,

thank you for the fast reply. I used your PlugIn manually to fuse a Grayscale CT-stack with a PET-stack(where LUT is applied).
and it really works perfectly.
I followed your advice and converted the images in RGB and used a duplicate of the PET-stack (converted it to 8bit) to determine the transparency...the following
error shows up:  "No previous filter/paste operation that could be modified by an alpha channel."
 
Here is the modified code:

public static ImagePlus TransparentOverlay(ImagePlus imp, ImagePlus imp2) {

                IJ.selectWindow("background");
                IJ.run("RGB Color");
                IJ.selectWindow("forground");
                IJ.run("RGB Color");
               
                ImagePlus imp1 = new Duplicator().run(imp);
                imp1.show();
                //IJ.setPasteMode("Transparent-white");

                for (int i = 1; i <= imp.getStackSize(); i++) {
                        ImageWindow win = (ImageWindow) WindowManager
                                        .getWindow("forground");
                        imp = win.getImagePlus();
                        imp.setSlice(i);  
                        imp.setRoi(0, 0, imp.getWidth(), imp.getHeight());
                        imp.copy(true);
                        //imp.copy();
                        win = (ImageWindow) WindowManager.getWindow("background");
                        imp2 = win.getImagePlus();
                        imp2.setSlice(i);
                        imp2.paste();
                        IJ.wait(10000);
                        IJ.run("Alpha Channel",
                                        "alpha=DUP_forground range=50 enlarge=0 smooth=2.0");
                        imp2.updateImage();
                }

                return imp2;
        }

Thanks in advance for any advice

Marie

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

Re: Alpha-Channel-PlugIn as Macro

Michael Schmid
Hi Marie,

IJ.run without ImagePlus Argument works on the currently active image, which is your "forground".
You paste onto the "background" image, so you want to run the plugin on that image.

You can use the IJ.run command to tell which ImagePlus the command should act on:
  IJ.run(ImagePlus imp, String command, String options)

In the current case,
  IJ.run(imp2,"Alpha Channel",
         "alpha=DUP_forground range=50 enlarge=0 smooth=2.0");

This assumes that there is an image named "DUP_forground" where the alpha (transparency) is given. "DUP_forground" must have the same size as imp2. It must be an 8-bit or 32-bit image.

Michael
________________________________________________________________
On Sep 4, 2014, at 20:05, Marie Rasta wrote:

> Hi Michael,
>
> thank you for the fast reply. I used your PlugIn manually to fuse a Grayscale CT-stack with a PET-stack(where LUT is applied).
> and it really works perfectly.
> I followed your advice and converted the images in RGB and used a duplicate of the PET-stack (converted it to 8bit) to determine the transparency...the following
> error shows up:  "No previous filter/paste operation that could be modified by an alpha channel."
>
> Here is the modified code:
>
> public static ImagePlus TransparentOverlay(ImagePlus imp, ImagePlus imp2) {
>
> IJ.selectWindow("background");
> IJ.run("RGB Color");
> IJ.selectWindow("forground");
> IJ.run("RGB Color");
>
> ImagePlus imp1 = new Duplicator().run(imp);
> imp1.show();
> //IJ.setPasteMode("Transparent-white");
>
> for (int i = 1; i <= imp.getStackSize(); i++) {
> ImageWindow win = (ImageWindow) WindowManager
> .getWindow("forground");
> imp = win.getImagePlus();
> imp.setSlice(i);  
> imp.setRoi(0, 0, imp.getWidth(), imp.getHeight());
> imp.copy(true);
> //imp.copy();
> win = (ImageWindow) WindowManager.getWindow("background");
> imp2 = win.getImagePlus();
> imp2.setSlice(i);
> imp2.paste();
> IJ.wait(10000);
> IJ.run("Alpha Channel",
> "alpha=DUP_forground range=50 enlarge=0 smooth=2.0");
> imp2.updateImage();
> }
>
> return imp2;
> }
>
> Thanks in advance for any advice
>
> Marie
>
> --
> 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
|

Re: Alpha-Channel-PlugIn as Macro

Marie Rasta
In reply to this post by Marie Rasta
Dear Michael,

Thank you so much, now it works!I just didn't know the command IJ.run(ImagePlus, String, String). I could minimize my method now.

Here is the final method I use in my littl PlugIn:
/**
         * Make transparent
         *
         */
        public static ImagePlus TransparentOverlay(ImagePlus imp, ImagePlus imp2) {
                IJ.run(imp2,"RGB Color",null);
                IJ.run(imp,"RGB Color",null);
                ImagePlus imp9 = new Duplicator().run(imp);
                imp9.show();
                IJ.run(imp9,"8-bit Color", "number=256");

                for (int i = 1; i <= imp.getStackSize(); i++) {
                        imp.setSlice(i); //PET
                        imp.copy();
                        imp2.setSlice(i);
                        imp9.setSlice(i);
                        imp2.paste();
                        IJ.run(imp2,"Alpha Channel",
                                        "alpha=DUP_forground range=50 enlarge=0 smooth=2.0");
                        imp2.updateImage();
                }
                return imp2;
        }


Greetings,
Marie