public void snapshot() { snapshotWidth=width; snapshotHeight=height; snapshotMin=(int)getMin(); snapshotMax=(int)getMax(); if (snapshotPixels==null || (snapshotPixels!=null && snapshotPixels.length!=pixels.length)) snapshotPixels = new short[width * height]; System.arraycopy(pixels, 0, snapshotPixels, 0, width*height); }
public void snapshot() { snapshotWidth=width; snapshotHeight=height; snapshotMin=(int)getMin(); snapshotMax=(int)getMax(); if (snapshotPixels==null || (snapshotPixels!=null && snapshotPixels.length!=pixels.length)) snapshotPixels = new short[width * height]; System.arraycopy(pixels, 0, snapshotPixels, 0, width*height); }
private byte[] create8BitImage(boolean thresholding) { int size = width*height; if (pixels8==null) pixels8 = new byte[size]; int value; int min2=(int)getMin(), max2=(int)getMax(); int maxValue = 255; double scale = 256.0/(max2-min2+1); if (thresholding) { maxValue = 254; scale = 255.0/(max2-min2+1); } for (int i=0; i<size; i++) { value = (pixels[i]&0xffff)-min2; if (value<0) value = 0; value = (int)(value*scale+0.5); if (value>maxValue) value = maxValue; pixels8[i] = (byte)value; } return pixels8; }
private byte[] create8BitImage(boolean thresholding) { int size = width*height; if (pixels8==null) pixels8 = new byte[size]; int value; int min2=(int)getMin(), max2=(int)getMax(); int maxValue = 255; double scale = 256.0/(max2-min2+1); if (thresholding) { maxValue = 254; scale = 255.0/(max2-min2+1); } for (int i=0; i<size; i++) { value = (pixels[i]&0xffff)-min2; if (value<0) value = 0; value = (int)(value*scale+0.5); if (value>maxValue) value = maxValue; pixels8[i] = (byte)value; } return pixels8; }
@Override final public void apply( final int cellXMin, final int cellYMin, final int cellXMax, final int cellYMax ) { final int xMin = Math.max( boxXMin, cellXMin ); final int yMin = Math.max( boxYMin, cellYMin ); final int xMax = Math.min( boxXMax, cellXMax ); final int yMax = Math.min( boxYMax, cellYMax ); final int min = ( int )ip.getMin(); for ( int y = yMin; y < yMax; ++y ) { int i = y * width + xMin; for ( int x = xMin; x < xMax; ++x ) { final float m = ( maskPixels[ i ] & 0xff ) / 255.0f; final int v = ipPixels[ i ] & 0xffff; final float vSrc = srcPixels[ i ] & 0xff; final float a; if ( vSrc == 0 ) a = 1.0f; else a = ( float )( dstPixels[ i ] & 0xff ) / vSrc; final float b = m * ( a * ( v - min ) + min - v ) + v; ipPixels[ i ] = ( short )Math.max( 0, Math.min( 65535, mpicbg.util.Util.roundPos( b ) ) ); ++i; } } } }
@Override final public void apply( final int cellXMin, final int cellYMin, final int cellXMax, final int cellYMax ) { final int xMin = Math.max( boxXMin, cellXMin ); final int yMin = Math.max( boxYMin, cellYMin ); final int xMax = Math.min( boxXMax, cellXMax ); final int yMax = Math.min( boxYMax, cellYMax ); final int min = ( int )ip.getMin(); for ( int y = yMin; y < yMax; ++y ) { int i = y * width + xMin; for ( int x = xMin; x < xMax; ++x ) { final float m = ( maskPixels[ i ] & 0xff ) / 255.0f; final int v = ipPixels[ i ] & 0xffff; final float vSrc = srcPixels[ i ] & 0xff; final float a; if ( vSrc == 0 ) a = 1.0f; else a = ( float )( dstPixels[ i ] & 0xff ) / vSrc; final float b = m * ( a * ( v - min ) + min - v ) + v; ipPixels[ i ] = ( short )Math.max( 0, Math.min( 65535, mpicbg.util.Util.roundPos( b ) ) ); ++i; } } } }
/** Sets the foreground fill/draw color. */ public void setColor(Color color) { drawingColor = color; int bestIndex = getBestIndex(color); if (bestIndex>0 && getMin()==0.0 && getMax()==0.0) { setValue(bestIndex); setMinAndMax(0.0,255.0); } else if (bestIndex==0 && getMin()>0.0 && (color.getRGB()&0xffffff)==0) { if (isSigned16Bit()) setValue(32768); else setValue(0.0); } else fgColor = (int)(getMin() + (getMax()-getMin())*(bestIndex/255.0)); }
/** Sets the foreground fill/draw color. */ public void setColor(Color color) { drawingColor = color; int bestIndex = getBestIndex(color); if (bestIndex>0 && getMin()==0.0 && getMax()==0.0) { setValue(bestIndex); setMinAndMax(0.0,255.0); } else if (bestIndex==0 && getMin()>0.0 && (color.getRGB()&0xffffff)==0) { if (isSigned16Bit()) setValue(32768); else setValue(0.0); } else fgColor = (int)(getMin() + (getMax()-getMin())*(bestIndex/255.0)); }
/** Returns a new, blank ShortProcessor with the specified width and height. */ public ImageProcessor createProcessor(int width, int height) { ImageProcessor ip2 = new ShortProcessor(width, height, new short[width*height], getColorModel()); ip2.setMinAndMax(getMin(), getMax()); ip2.setInterpolationMethod(interpolationMethod); return ip2; }
/** Returns a new, blank ShortProcessor with the specified width and height. */ public ImageProcessor createProcessor(int width, int height) { ImageProcessor ip2 = new ShortProcessor(width, height, new short[width*height], getColorModel()); ip2.setMinAndMax(getMin(), getMax()); ip2.setInterpolationMethod(interpolationMethod); return ip2; }
/** A method that circumvents the findMinAndMax when creating a float processor from an existing processor. Ignores color calibrations and does no scaling at all. */ static public final FloatProcessor fastConvertToFloat(final ShortProcessor ip) { final short[] pix = (short[])ip.getPixels(); final float[] data = new float[pix.length]; for (int i=0; i<pix.length; i++) data[i] = pix[i]&0xffff; final FloatProcessor fp = new FloatProcessorT2(ip.getWidth(), ip.getHeight(), data, ip.getColorModel(), ip.getMin(), ip.getMax()); return fp; } /** A method that circumvents the findMinAndMax when creating a float processor from an existing processor. Ignores color calibrations and does no scaling at all. */
ip2 = new ShortProcessor(getWidth(), getHeight(), pixels2, null); boolean checkCoordinates = (xScale < 1.0) || (yScale < 1.0); short min2 = (short)getMin(); int index1, index2, xsi, ysi; double ys, xs;
ip2 = new ShortProcessor(getWidth(), getHeight(), pixels2, null); boolean checkCoordinates = (xScale < 1.0) || (yScale < 1.0); short min2 = (short)getMin(); int index1, index2, xsi, ysi; double ys, xs;
/** Returns a FloatProcessor with the same image, no scaling or calibration * (pixel values 0 to 65535). * The roi, mask, lut (ColorModel), threshold, min&max are * also set for the FloatProcessor * @param channelNumber Ignored (needed for compatibility with ColorProcessor.toFloat) * @param fp Here a FloatProcessor can be supplied, or null. The FloatProcessor * is overwritten by this method (re-using its pixels array * improves performance). * @return A FloatProcessor with the converted image data */ public FloatProcessor toFloat(int channelNumber, FloatProcessor fp) { int size = width*height; if (fp == null || fp.getWidth()!=width || fp.getHeight()!=height) fp = new FloatProcessor(width, height, new float[size], cm); float[] fPixels = (float[])fp.getPixels(); for (int i=0; i<size; i++) fPixels[i] = pixels[i]&0xffff; fp.setRoi(getRoi()); fp.setMask(mask); fp.setMinAndMax(getMin(), getMax()); fp.setThreshold(minThreshold, maxThreshold, ImageProcessor.NO_LUT_UPDATE); return fp; }
/** Returns a FloatProcessor with the same image, no scaling or calibration * (pixel values 0 to 65535). * The roi, mask, lut (ColorModel), threshold, min&max are * also set for the FloatProcessor * @param channelNumber Ignored (needed for compatibility with ColorProcessor.toFloat) * @param fp Here a FloatProcessor can be supplied, or null. The FloatProcessor * is overwritten by this method (re-using its pixels array * improves performance). * @return A FloatProcessor with the converted image data */ public FloatProcessor toFloat(int channelNumber, FloatProcessor fp) { int size = width*height; if (fp == null || fp.getWidth()!=width || fp.getHeight()!=height) fp = new FloatProcessor(width, height, new float[size], cm); float[] fPixels = (float[])fp.getPixels(); for (int i=0; i<size; i++) fPixels[i] = pixels[i]&0xffff; fp.setRoi(getRoi()); fp.setMask(mask); fp.setMinAndMax(getMin(), getMax()); fp.setThreshold(minThreshold, maxThreshold, ImageProcessor.NO_LUT_UPDATE); return fp; }
final int wa2 = wa + wa; final double min = a.getMin(); final double max = a.getMax(); final double scale = 255.0 / ( max - min );