public void setFromFloatArrays(float[][] arrays) { ImageProcessor ip2 = new FloatProcessor(roiWidth, roiHeight, arrays[0], null); ip2 = ip2.convertToByte(false); setPixels(ip2.getPixels()); //insert(ip2, roiX, roiY); }
/** 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.convertToByte(true); new ByteBlitter(this).copyBits(ip, xloc, yloc, mode); } }
static public final ImageProcessor createProcessor(final int type, final int width, final int height) { switch (type) { case ImagePlus.GRAY8: return new ByteProcessor(width, height); case ImagePlus.GRAY16: return new ShortProcessor(width, height); case ImagePlus.GRAY32: return new FloatProcessor(width, height); case ImagePlus.COLOR_RGB: return new ColorProcessor(width, height); } return null; }
private void byteFromFloat(ImageProcessor ip, FloatProcessor floatEdm) { int width = ip.getWidth(); int height = ip.getHeight(); byte[] bPixels = (byte[])ip.getPixels(); float[] fPixels = (float[])floatEdm.getPixels(); for (int i=0; i<width*height; i++) { float v = fPixels[i]; bPixels[i] = v<255f ? (byte)(v+0.5) : (byte)255; } }
/** Converts a ByteProcessor to a ShortProcessor. */ ShortProcessor convertByteToShort() { byte[] pixels8 = (byte[])ip.getPixels(); short[] pixels16 = new short[width * height]; for (int i=0,j=0; i<width*height; i++) pixels16[i] = (short)(pixels8[i]&0xff); return new ShortProcessor(width, height, pixels16, ip.getColorModel()); }
/** Returns a new, blank FloatProcessor with the specified width and height. */ public ImageProcessor createProcessor(int width, int height) { ImageProcessor ip2 = new FloatProcessor(width, height, new float[width*height], getColorModel()); ip2.setMinAndMax(getMin(), getMax()); ip2.setInterpolationMethod(interpolationMethod); return ip2; }
/** Returns a new, blank ByteProcessor with the specified width and height. */ public ImageProcessor createProcessor(int width, int height) { ImageProcessor ip2; ip2 = new ByteProcessor(width, height, new byte[width*height], getColorModel()); if (baseCM!=null) ip2.setMinAndMax(min, max); ip2.setInterpolationMethod(interpolationMethod); return ip2; }
/** Converts processor to a ColorProcessor. */ public ImageProcessor convertToRGB() { if (type==RGB) return ip; else { ImageProcessor ip2 = ip.convertToByte(doScaling); return new ColorProcessor(ip2.createImage()); } }
public float[][] toFloatArrays() { float[][] a = new float[1][]; //ImageProcessor fp = crop(); ImageProcessor fp = convertToFloat(); a[0] = (float[])fp.getPixels(); return a; }
public ImageProcessor crop() { ImageProcessor ip2 = createProcessor(roiWidth, roiHeight); byte[] pixels2 = (byte[])ip2.getPixels(); for (int ys=roiY; ys<roiY+roiHeight; ys++) { int offset1 = (ys-roiY)*roiWidth; int offset2 = ys*width+roiX; for (int xs=0; xs<roiWidth; xs++) pixels2[offset1++] = pixels[offset2++]; } return ip2; }
public void setLut(LUT lut) { if (lut==null) setColorModel(null); else { setColorModel(lut.getColorModel()); if (lut.min!=0.0 || lut.max!=0.0) setMinAndMax(lut.min, lut.max); } }
/** Returns a new, blank ColorProcessor with the specified width and height. */ public ImageProcessor createProcessor(int width, int height) { ImageProcessor ip2 = new ColorProcessor(width, height); ip2.setInterpolationMethod(interpolationMethod); return ip2; }
ImageProcessor calculateAmplitude(float[] fht, int maxN) { float[] amp = new float[maxN*maxN]; for (int row=0; row<maxN; row++) { amplitude(row, maxN, fht, amp); } ImageProcessor ip = new FloatProcessor(maxN, maxN, amp, null); swapQuadrants(ip); return ip; }
/** Sets the display range of specified channels in an RGB image, where 4=red, 2=green, 1=blue, 6=red+green, etc. With non-RGB images, this method is identical to setDisplayRange(min, max). This method is used by the Image/Adjust/Color Balance tool . */ public void setDisplayRange(double min, double max, int channels) { if (ip instanceof ColorProcessor) ((ColorProcessor)ip).setMinAndMax(min, max, channels); else ip.setMinAndMax(min, max); }
/** 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); } }
/** Fits an ellipse to the current ROI. The 'stats' argument, currently not used, can be null. The fit parameters are returned in public fields. */ public void fit(ImageProcessor ip, ImageStatistics stats) { this.ip = ip; mask = ip.getMaskArray(); Rectangle r = ip.getRoi(); left = r.x; top = r.y; width = r.width; height = r.height; getEllipseParam(); }
void setThreshold(ImageProcessor ip) { if (!(ip instanceof ByteProcessor)) return; if (((ByteProcessor)ip).isInvertedLut()) ip.setThreshold(max, 255, ImageProcessor.NO_LUT_UPDATE); else ip.setThreshold(0, max, ImageProcessor.NO_LUT_UPDATE); }
/** Uses Heckbert's median-cut algorithm to divide the color space defined by "hist" into "maxcubes" cubes. The centroids (average value) of each cube are are used to create a color table. "hist" is then updated to function as an inverse color map that is used to generate an 8-bit image. */ public Image convert(int maxcubes) { ImageProcessor ip = convertToByte(maxcubes); return ip.createImage(); }