Java Code Examples for ij.process.ImageProcessor#createImage()

The following examples show how to use ij.process.ImageProcessor#createImage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Patch.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
final public Image createImage(final double min, final double max) {
	final ImageProcessor ip = target;
	ip.setMinAndMax(min, max);
	ByteProcessor alpha_mask = mask; // can be null;
	final ByteProcessor outside_mask = outside; // can be null
	if (null == alpha_mask) {
		alpha_mask = outside_mask;
	}
	if (null != alpha_mask) {
		return ImageSaver.createARGBImagePre(
				Loader.embedAlphaPre((int[])ip.convertToRGB().getPixels(),
						(byte[])alpha_mask.getPixels(),
						null == outside_mask ? null : (byte[])outside_mask.getPixels()),
						ip.getWidth(), ip.getHeight());
	} else {
		return ip.createImage();
	}
}
 
Example 2
Source File: GroupingMode.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
protected BufferedImage makeImage( final ImageProcessor ip, final FloatProcessor mask )
{
	final BufferedImage transformedImage = new BufferedImage( ip.getWidth(), ip.getHeight(), null == mask ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB );
	final Image img = ip.createImage();
	transformedImage.createGraphics().drawImage( img, 0, 0, null );
	img.flush();
	if (null != mask) {
		transformedImage.getAlphaRaster().setPixels( 0, 0, ip.getWidth(), ip.getHeight(), ( float[] )mask.getPixels() );
	}
	return transformedImage;
}
 
Example 3
Source File: ImageSaver.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
static public final boolean saveAsPNG(final ImageProcessor ip, final String path) {
	Image awt = null;
	try {
		awt = ip.createImage();
		return ImageSaver.saveAsPNG(awt, path);
	} catch (Exception e) {
		IJError.print(e);
		return false;
	} finally {
		if (null != awt) awt.flush();
	}
}
 
Example 4
Source File: Patch.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
/** @param c contains the current Display 'channels' value (the transparencies of each channel). This method creates a new color image in which each channel (R, G, B) has the corresponding alpha (in fact, opacity) specified in the 'c'. This alpha is independent of the alpha of the whole Patch. The method updates the Loader cache with the newly created image. The argument 'imp' is optional: if null, it will be retrieved from the loader.
 * <p>
 * For non-color images, a standard image is returned regardless of the given {@code c}.
 * </p>
 * @param c
 */
private Image adjustChannels(final int c, final boolean force, ImagePlus imp) {
	if (null == imp) imp = project.getLoader().fetchImagePlus(this);
	ImageProcessor ip = imp.getProcessor();
	if (null == ip) return null; // fixing synch problems when deleting a Patch
	Image awt = null;
	if (ImagePlus.COLOR_RGB == type) {
		if (imp.getType() != type ) {
			ip = Utils.convertTo(ip, type, false); // all other types need not be converted, since there are no alphas anyway
		}
		if ((c&0x00ffffff) == 0x00ffffff && !force) {
			// full transparency
			awt = ip.createImage(); //imp.getImage();
			// pixels array will be shared using ij138j and above
		} else {
			// modified from ij.process.ColorProcessor.createImage() by Wayne Rasband
			final int[] pixels = (int[])ip.getPixels();
			final float cr = ((c&0xff0000)>>16) / 255.0f;
			final float cg = ((c&0xff00)>>8) / 255.0f;
			final float cb = (c&0xff) / 255.0f;
			final int[] pix = new int[pixels.length];
			int p;
			for (int i=pixels.length -1; i>-1; i--) {
				p = pixels[i];
				pix[i] =  (((int)(((p&0xff0000)>>16) * cr))<<16)
					+ (((int)(((p&0xff00)>>8) * cg))<<8)
					+   (int) ((p&0xff) * cb);
			}
			final int w = imp.getWidth();
			final MemoryImageSource source = new MemoryImageSource(w, imp.getHeight(), DCM, pix, 0, w);
			source.setAnimated(true);
			source.setFullBufferUpdates(true);
			awt = Toolkit.getDefaultToolkit().createImage(source);
		}
	} else {
		awt = ip.createImage();
	}

	//Utils.log2("ip's min, max: " + ip.getMin() + ", " + ip.getMax());

	this.channels = c;

	return awt;
}