public void addSlice(ImageProcessor ip) { if(!(ip instanceof ShortProcessor)) ip = ip.convertToShort(true); super.addSlice("", ip); } }
/** Returns a 16-bit version of this image as a ShortProcessor. 32-bit * pixel data are scaled from min-max to 0-255 if 'scale' is true. */ public ShortProcessor convertToShortProcessor(boolean scale) { ShortProcessor sp; if (this instanceof ShortProcessor) sp = (ShortProcessor)this.duplicate(); else sp = (ShortProcessor)this.convertToShort(scale); return sp; }
@Override public ImageProcessor convertToShort(boolean doScaling) { record("convertToShort", new Boolean(doScaling), boolean.class); return proc.convertToShort(doScaling); }
/** Returns a 16-bit version of this image as a ShortProcessor. 32-bit * pixel data are scaled from min-max to 0-255 if 'scale' is true. */ public ShortProcessor convertToShortProcessor(boolean scale) { ShortProcessor sp; if (this instanceof ShortProcessor) sp = (ShortProcessor)this.duplicate(); else sp = (ShortProcessor)this.convertToShort(scale); return sp; }
@Override public ImageProcessor convertToShort(boolean doScaling) { record("convertToShort", new Boolean(doScaling), boolean.class); return proc.convertToShort(doScaling); }
/** * Returns an ImageProcessor for the specified slice, * were 1<=n<=nslices. Returns null if the stack is empty. */ public ImageProcessor getProcessor(int n) { ImageProcessor ip = null; try { ip = SPIMExperiment.openRaw(paths.get(n - 1), orgW, orgH, x0, x1, y0, y1); } catch(Exception e) { e.printStackTrace(); return null; } if(!(ip instanceof ShortProcessor)) ip = ip.convertToShort(true); return ip; }
private ImageProcessor convertToOriginalDepth(ImagePlus imp, ImageProcessor ip) { if (imp.getBitDepth()==8) ip = ip.convertToByte(false); else if (imp.getBitDepth()==16) ip = ip.convertToShort(false); return ip; }
private ImageProcessor convertToOriginalDepth(ImagePlus imp, ImageProcessor ip) { if (imp.getBitDepth()==8) ip = ip.convertToByte(false); else if (imp.getBitDepth()==16) ip = ip.convertToShort(false); return ip; }
/** Returns the histogram of the image or ROI, using the specified number of bins. */ public int[] getHistogram(int nBins) { ImageProcessor ip; if (((this instanceof ByteProcessor)||(this instanceof ColorProcessor)) && nBins!=256) ip = convertToShort(false); else ip = this; ip.setHistogramSize(nBins); ip.setHistogramRange(0.0, 0.0); ImageStatistics stats = ImageStatistics.getStatistics(ip); ip.setHistogramSize(256); return stats.histogram; }
/** Performs a convolution operation using the specified kernel. */ public void convolve(float[] kernel, int kernelWidth, int kernelHeight) { ImageProcessor ip2 = convertToFloat(); ip2.setRoi(getRoi()); new ij.plugin.filter.Convolver().convolve(ip2, kernel, kernelWidth, kernelHeight); ip2 = ip2.convertToShort(false); short[] pixels2 = (short[])ip2.getPixels(); System.arraycopy(pixels2, 0, pixels, 0, pixels.length); }
/** Performs a convolution operation using the specified kernel. */ public void convolve(float[] kernel, int kernelWidth, int kernelHeight) { ImageProcessor ip2 = convertToFloat(); ip2.setRoi(getRoi()); new ij.plugin.filter.Convolver().convolve(ip2, kernel, kernelWidth, kernelHeight); ip2 = ip2.convertToShort(false); short[] pixels2 = (short[])ip2.getPixels(); System.arraycopy(pixels2, 0, pixels, 0, pixels.length); }
/** Returns the histogram of the image or ROI, using the specified number of bins. */ public int[] getHistogram(int nBins) { ImageProcessor ip; if (((this instanceof ByteProcessor)||(this instanceof ColorProcessor)) && nBins!=256) ip = convertToShort(false); else ip = this; ip.setHistogramSize(nBins); ip.setHistogramRange(0.0, 0.0); ImageStatistics stats = ImageStatistics.getStatistics(ip); ip.setHistogramSize(256); return stats.histogram; }
@Override public void run() { setPriority( Thread.NORM_PRIORITY ); for ( int i = ai.getAndIncrement(); i < ( sp.applyCorrection ? sp.names.length : ( sp.firstImageIndex + sp.numberOfImages ) ); i = ai.getAndIncrement() ) { IJ.log( "Correcting image " + sp.names[ i ] ); final ImagePlus imps = new Opener().openImage( sp.source_dir + sp.names[ i ] ); imps.setProcessor( imps.getTitle(), imps.getProcessor().convertToShort( false ) ); final ImageProcessor[] transErg = nlt.transform( imps.getProcessor() ); imps.setProcessor( imps.getTitle(), transErg[ 0 ] ); if ( !sp.applyCorrection ) new File( sp.target_dir + sp.names[ i ] ).deleteOnExit(); new FileSaver( imps ).saveAsTiff( sp.target_dir + sp.names[ i ] ); } } };
/** Copies the image contained in 'ip' to (xloc, yloc) using one of the transfer modes defined in the Blitter interface. */ public void copyBits(ImageProcessor ip, int xloc, int yloc, int mode) { boolean temporaryFloat = ip.getBitDepth()==32 && (mode==Blitter.MULTIPLY || mode==Blitter.DIVIDE); if (temporaryFloat) { FloatProcessor ipFloat = this.convertToFloatProcessor(); new FloatBlitter(ipFloat).copyBits(ip, xloc, yloc, mode); setPixels(1, ipFloat); } else { ip = ip.convertToShort(false); new ShortBlitter(this).copyBits(ip, xloc, yloc, mode); } }
/** Copies the image contained in 'ip' to (xloc, yloc) using one of the transfer modes defined in the Blitter interface. */ public void copyBits(ImageProcessor ip, int xloc, int yloc, int mode) { boolean temporaryFloat = ip.getBitDepth()==32 && (mode==Blitter.MULTIPLY || mode==Blitter.DIVIDE); if (temporaryFloat) { FloatProcessor ipFloat = this.convertToFloatProcessor(); new FloatBlitter(ipFloat).copyBits(ip, xloc, yloc, mode); setPixels(1, ipFloat); } else { ip = ip.convertToShort(false); new ShortBlitter(this).copyBits(ip, xloc, yloc, mode); } }
/** Converts this ImagePlus to 16-bit grayscale. */ public void convertToGray16() { if (type==ImagePlus.GRAY16) return; if (!(type==ImagePlus.GRAY8||type==ImagePlus.GRAY32||type==ImagePlus.COLOR_RGB)) throw new IllegalArgumentException("Unsupported conversion"); if (imp.getStackSize()>1) { new StackConverter(imp).convertToGray16(); return; } ImageProcessor ip = imp.getProcessor(); if (type==ImagePlus.GRAY32) record(); imp.trimProcessor(); imp.setProcessor(null, ip.convertToShort(doScaling)); imp.setCalibration(imp.getCalibration()); //update calibration }
/** Converts this ImagePlus to 16-bit grayscale. */ public void convertToGray16() { if (type==ImagePlus.GRAY16) return; if (!(type==ImagePlus.GRAY8||type==ImagePlus.GRAY32||type==ImagePlus.COLOR_RGB)) throw new IllegalArgumentException("Unsupported conversion"); if (imp.getStackSize()>1) { new StackConverter(imp).convertToGray16(); return; } ImageProcessor ip = imp.getProcessor(); if (type==ImagePlus.GRAY32) record(); imp.trimProcessor(); imp.setProcessor(null, ip.convertToShort(doScaling)); imp.setCalibration(imp.getCalibration()); //update calibration }
/** Converts this Stack to 16-bit grayscale. */ public void convertToGray16() { if (type==ImagePlus.GRAY16) return; if (!(type==ImagePlus.GRAY8 || type==ImagePlus.GRAY32)) throw new IllegalArgumentException("Unsupported conversion"); ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(width, height); String label; int inc = nSlices/20; if (inc<1) inc = 1; boolean scale = type==ImagePlus.GRAY32 && ImageConverter.getDoScaling(); ImageProcessor ip1, ip2; for(int i=1; i<=nSlices; i++) { label = stack1.getSliceLabel(1); ip1 = stack1.getProcessor(1); ip2 = ip1.convertToShort(scale); stack1.deleteSlice(1); stack2.addSlice(label, ip2); if ((i%inc)==0) { IJ.showProgress((double)i/nSlices); IJ.showStatus("Converting to 16-bits: "+i+"/"+nSlices); } } IJ.showProgress(1.0); imp.setStack(null, stack2); }
/** Converts the ImageProcessor to an ImageProcessor of the given type, or the same if of equal type. */ static final public ImageProcessor convertTo(final ImageProcessor ip, final int type, final boolean scaling) { switch (type) { case ImagePlus.GRAY8: return ip.convertToByte(scaling); case ImagePlus.GRAY16: return ip.convertToShort(scaling); case ImagePlus.GRAY32: return ip.convertToFloat(); case ImagePlus.COLOR_RGB: return ip.convertToRGB(); case ImagePlus.COLOR_256: final ImagePlus imp = new ImagePlus("", ip.convertToRGB()); new ImageConverter(imp).convertRGBtoIndexedColor(256); return imp.getProcessor(); default: return null; } }
void doInverseTransform(FHT fht, ImageProcessor ip) { showStatus("Inverse transform"); fht.inverseTransform(); //if (fht.quadrantSwapNeeded) // fht.swapQuadrants(); fht.resetMinAndMax(); ImageProcessor ip2 = fht; fht.setRoi(rect.x, rect.y, rect.width, rect.height); ip2 = fht.crop(); int bitDepth = fht.originalBitDepth>0?fht.originalBitDepth:imp.getBitDepth(); switch (bitDepth) { case 8: ip2 = ip2.convertToByte(true); break; case 16: ip2 = ip2.convertToShort(true); break; case 24: showStatus("Setting brightness"); fht.rgb.setBrightness((FloatProcessor)ip2); ip2 = fht.rgb; fht.rgb = null; break; case 32: break; } ip.insert(ip2, 0, 0); }