/** Returns the specified plane (1=red, 2=green, 3=blue, 4=alpha) as a byte array. */ public byte[] getChannel(int channel) { ByteProcessor bp = getChannel(channel, null); return (byte[])bp.getPixels(); }
/** Returns the specified plane (1=red, 2=green, 3=blue, 4=alpha) as a byte array. */ public byte[] getChannel(int channel) { ByteProcessor bp = getChannel(channel, null); return (byte[])bp.getPixels(); }
private ImageProcessor shrinkRGB(ColorProcessor cp, ColorProcessor cp2, int method) { ByteProcessor bp = cp.getChannel(1, null); cp2.setChannel(1, (ByteProcessor)shrink(bp, method)); cp2.setChannel(2, (ByteProcessor)shrink(cp.getChannel(2,bp), method)); cp2.setChannel(3, (ByteProcessor)shrink(cp.getChannel(3,bp), method)); return cp2; }
private ImageProcessor shrinkRGB(ColorProcessor cp, ColorProcessor cp2, int method) { ByteProcessor bp = cp.getChannel(1, null); cp2.setChannel(1, (ByteProcessor)shrink(bp, method)); cp2.setChannel(2, (ByteProcessor)shrink(cp.getChannel(2,bp), method)); cp2.setChannel(3, (ByteProcessor)shrink(cp.getChannel(3,bp), method)); return cp2; }
alpha = new ColorProcessor( mipMap.image ).getChannel( 4, null ); } else {
byte[] getPixels(ImageStack stack, int slice, int color) { if (stack==null) return blank; Object pixels = stack.getPixels(slice); if (!(pixels instanceof int[])) { if (pixels instanceof byte[]) return (byte[])pixels; else { ImageProcessor ip = stack.getProcessor(slice); ip = ip.convertToByte(true); return (byte[])ip.getPixels(); } } else { //RGB ColorProcessor cp = (ColorProcessor)stack.getProcessor(slice); return ((ColorProcessor)cp).getChannel(color+1); } }
byte[] getPixels(ImageStack stack, int slice, int color) { if (stack==null) return blank; Object pixels = stack.getPixels(slice); if (!(pixels instanceof int[])) { if (pixels instanceof byte[]) return (byte[])pixels; else { ImageProcessor ip = stack.getProcessor(slice); ip = ip.convertToByte(true); return (byte[])ip.getPixels(); } } else { //RGB ColorProcessor cp = (ColorProcessor)stack.getProcessor(slice); return ((ColorProcessor)cp).getChannel(color+1); } }
private ImageStatistics RGBHistogram(ImagePlus imp, int bins, double histMin, double histMax) { ImageProcessor ip = (ColorProcessor)imp.getProcessor(); ip = ip.crop(); int w = ip.getWidth(); int h = ip.getHeight(); ImageProcessor ip2 = new ByteProcessor(w*3, h); ByteProcessor temp = null; for (int i=0; i<3; i++) { temp = ((ColorProcessor)ip).getChannel(i+1,temp); ip2.insert(temp, i*w, 0); } ImagePlus imp2 = new ImagePlus("imp2", ip2); return imp2.getStatistics(AREA+MEAN+MODE+MIN_MAX, bins, histMin, histMax); }
return crop(); if (interpolationMethod!=NONE && (width==1||height==1)) { ByteProcessor r2 = (ByteProcessor)getChannel(1,null).resizeLinearly(dstWidth, dstHeight); ByteProcessor g2 = (ByteProcessor)getChannel(2,null).resizeLinearly(dstWidth, dstHeight); ByteProcessor b2 = (ByteProcessor)getChannel(3,null).resizeLinearly(dstWidth, dstHeight); ColorProcessor ip2 = new ColorProcessor(dstWidth, dstHeight); ip2.setChannel(1, r2); ip2.setChannel(2, g2); ip2.setChannel(3, b2);
private ImageStatistics RGBHistogram(ImagePlus imp, int bins, double histMin, double histMax) { ImageProcessor ip = (ColorProcessor)imp.getProcessor(); ip = ip.crop(); int w = ip.getWidth(); int h = ip.getHeight(); ImageProcessor ip2 = new ByteProcessor(w*3, h); ByteProcessor temp = null; for (int i=0; i<3; i++) { temp = ((ColorProcessor)ip).getChannel(i+1,temp); ip2.insert(temp, i*w, 0); } ImagePlus imp2 = new ImagePlus("imp2", ip2); return imp2.getStatistics(AREA+MEAN+MODE+MIN_MAX, bins, histMin, histMax); }
return crop(); if (interpolationMethod!=NONE && (width==1||height==1)) { ByteProcessor r2 = (ByteProcessor)getChannel(1,null).resizeLinearly(dstWidth, dstHeight); ByteProcessor g2 = (ByteProcessor)getChannel(2,null).resizeLinearly(dstWidth, dstHeight); ByteProcessor b2 = (ByteProcessor)getChannel(3,null).resizeLinearly(dstWidth, dstHeight); ColorProcessor ip2 = new ColorProcessor(dstWidth, dstHeight); ip2.setChannel(1, r2); ip2.setChannel(2, g2); ip2.setChannel(3, b2);
/** Draws the histogram using the specified title, number of bins and histogram range. Currently, the number of bins must be 256 and the histogram range range must be the same as the image range expect for 32 bit images. */ public void showHistogram(ImagePlus imp, int bins, double histMin, double histMax) { boolean limitToThreshold = (Analyzer.getMeasurements()&LIMIT)!=0; ImageProcessor ip = imp.getProcessor(); if (ip.getMinThreshold()!=ImageProcessor.NO_THRESHOLD && ip.getLutUpdateMode()==ImageProcessor.NO_LUT_UPDATE) limitToThreshold = false; // ignore invisible thresholds if (imp.getBitDepth()==24 && rgbMode<INTENSITY1) rgbMode=INTENSITY1; if (rgbMode==RED||rgbMode==GREEN||rgbMode==BLUE) { int channel = rgbMode - 2; ColorProcessor cp = (ColorProcessor)imp.getProcessor(); ip = cp.getChannel(channel, null); ImagePlus imp2 = new ImagePlus("", ip); imp2.setRoi(imp.getRoi()); stats = imp2.getStatistics(AREA+MEAN+MODE+MIN_MAX, bins, histMin, histMax); } else if (rgbMode==RGB) stats = RGBHistogram(imp, bins, histMin, histMax); else stats = imp.getStatistics(AREA+MEAN+MODE+MIN_MAX+(limitToThreshold?LIMIT:0), bins, histMin, histMax); showHistogram(imp, stats); }
/** Draws the histogram using the specified title, number of bins and histogram range. Currently, the number of bins must be 256 and the histogram range range must be the same as the image range expect for 32 bit images. */ public void showHistogram(ImagePlus imp, int bins, double histMin, double histMax) { boolean limitToThreshold = (Analyzer.getMeasurements()&LIMIT)!=0; ImageProcessor ip = imp.getProcessor(); if (ip.getMinThreshold()!=ImageProcessor.NO_THRESHOLD && ip.getLutUpdateMode()==ImageProcessor.NO_LUT_UPDATE) limitToThreshold = false; // ignore invisible thresholds if (imp.getBitDepth()==24 && rgbMode<INTENSITY1) rgbMode=INTENSITY1; if (rgbMode==RED||rgbMode==GREEN||rgbMode==BLUE) { int channel = rgbMode - 2; ColorProcessor cp = (ColorProcessor)imp.getProcessor(); ip = cp.getChannel(channel, null); ImagePlus imp2 = new ImagePlus("", ip); imp2.setRoi(imp.getRoi()); stats = imp2.getStatistics(AREA+MEAN+MODE+MIN_MAX, bins, histMin, histMax); } else if (rgbMode==RGB) stats = RGBHistogram(imp, bins, histMin, histMax); else stats = imp.getStatistics(AREA+MEAN+MODE+MIN_MAX+(limitToThreshold?LIMIT:0), bins, histMin, histMax); showHistogram(imp, stats); }
public Pair<ColorProcessor, ByteProcessor> makeFlatColorImage() { if ( canUseAWTImage() ) { // less than 0.5 GB array size final ColorProcessor cp = new ColorProcessor( createAWTImage( ImagePlus.COLOR_RGB ) ); final ByteProcessor alpha = new ByteProcessor( cp.getWidth(), cp.getHeight(), cp.getChannel( 4 ) ); return new Pair<ColorProcessor, ByteProcessor>( cp, alpha ); } if ( !isSmallerThan2GB() ) { Utils.log("Cannot create an image larger than 2 GB."); return null; } if ( loader.isMipMapsRegenerationEnabled() ) { return ExportARGB.makeFlatImageARGBFromMipMaps( patches, finalBox, 0, scale ); } // No mipmaps: create an image as large as possible, then downsample it final Pair<ColorProcessor, ByteProcessor> pair = ExportARGB.makeFlatImageARGBFromOriginals( patches, finalBox, 0, scaleUP ); final double sigma = computeSigma( pair.a.getWidth(), pair.a.getHeight()); new GaussianBlur().blurGaussian( pair.a, sigma, sigma, 0.0002 ); new GaussianBlur().blurGaussian( pair.b, sigma, sigma, 0.0002 ); return pair; }