On Mar 29, 2012, at 3:58 AM, Johannes Hermen wrote:
> Hi there,
>
> i have an imagePlus (16bit bw) which i want to draw onto another image as
> an overlay. Therefore i want to set the black background of the image to
> transparent to not cover the background in this region.
>
> Any hints how to do this, i a a bit stuck here.
This example plugin draws one image (the "CT" sample image) onto another ("Boats") as an overlay,
with the black background transparent.
Replace
boats.setOverlay(overlay);
with
boats.setRoi(imageOverlay);
and you will be able to move the CT image by dragging it.
-wayne
[cid:
[hidden email]]
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import java.awt.image.*;
public class Image_Overlay_Demo implements PlugIn {
public void run(String arg) {
ImagePlus ct = IJ.openImage("
http://imagej.nih.gov/ij/images/ct.dcm.zip");
ImageProcessor ip = ct.getProcessor();
int width = ip.getWidth()/2;
int height = ip.getHeight()/2;
ip = ip.convertToByte(true);
ip = ip.resize(width, height, true);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.getGraphics();
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
int v = ip.get(x, y);
if (v>1) {
g.setColor(new Color(v,v,v));
g.drawRect(x, y, 1, 1);
}
}
}
Roi imageOverlay = new ImageRoi(100, 25, bi);
ImagePlus boats = IJ.openImage("
http://imagej.nih.gov/ij/images/boats.gif");
Overlay overlay = new Overlay(imageOverlay);
boats.setOverlay(overlay);
boats.show();
}
}