/**Creates a ByteProcessor from a pixel array and IndexColorModel. */ public ByteProcessor(int width, int height, byte[] pixels, ColorModel cm) { if (pixels!=null && width*height!=pixels.length) throw new IllegalArgumentException(WRONG_LENGTH); this.width = width; this.height = height; resetRoi(); this.pixels = pixels; this.cm = cm; }
/**Creates a ByteProcessor from a pixel array and IndexColorModel. */ public ByteProcessor(int width, int height, byte[] pixels, ColorModel cm) { if (pixels!=null && width*height!=pixels.length) throw new IllegalArgumentException(WRONG_LENGTH); this.width = width; this.height = height; resetRoi(); this.pixels = pixels; this.cm = cm; }
/** Creates a ByteProcessor from a TYPE_BYTE_GRAY BufferedImage. */ public ByteProcessor(BufferedImage bi) { if (bi.getType()!=BufferedImage.TYPE_BYTE_GRAY) throw new IllegalArgumentException("Type!=TYPE_BYTE_GRAYY"); WritableRaster raster = bi.getRaster(); DataBuffer buffer = raster.getDataBuffer(); pixels = ((DataBufferByte) buffer).getData(); width = raster.getWidth(); height = raster.getHeight(); resetRoi(); }
/** Creates a ByteProcessor from a TYPE_BYTE_GRAY BufferedImage. */ public ByteProcessor(BufferedImage bi) { if (bi.getType()!=BufferedImage.TYPE_BYTE_GRAY) throw new IllegalArgumentException("Type!=TYPE_BYTE_GRAYY"); WritableRaster raster = bi.getRaster(); DataBuffer buffer = raster.getDataBuffer(); pixels = ((DataBufferByte) buffer).getData(); width = raster.getWidth(); height = raster.getHeight(); resetRoi(); }
private void fitEllipse(){ if(fittedEllipse==null){ fittedEllipse = new EllipseFitter(); Rectangle r = outerContour.getBounds(); ImagePlus help = NewImage.createByteImage("", r.width+1, r.height+1, 1, NewImage.FILL_WHITE); ByteProcessor ip = (ByteProcessor) help.getProcessor(); ip.setColor(Color.black); Polygon p = new Polygon(outerContour.xpoints, outerContour.ypoints, outerContour.npoints); p.translate(-r.x, -r.y); ip.resetRoi(); ip.setRoi(p); fittedEllipse.fit(ip, null); } }
/**Creates a ByteProcessor from an AWT Image. */ public ByteProcessor(Image img) { width = img.getWidth(null); height = img.getHeight(null); resetRoi(); pixels = new byte[width * height]; PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, false); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println(e); }; cm = pg.getColorModel(); if (cm instanceof IndexColorModel) pixels = (byte[])(pg.getPixels()); if ((cm instanceof IndexColorModel) && ((IndexColorModel)cm).getTransparentPixel()!=-1) { IndexColorModel icm = (IndexColorModel)cm; int mapSize = icm.getMapSize(); byte[] reds = new byte[mapSize]; byte[] greens = new byte[mapSize]; byte[] blues = new byte[mapSize]; icm.getReds(reds); icm.getGreens(greens); icm.getBlues(blues); cm = new IndexColorModel(8, mapSize, reds, greens, blues); } }
/**Creates a ByteProcessor from an AWT Image. */ public ByteProcessor(Image img) { width = img.getWidth(null); height = img.getHeight(null); resetRoi(); pixels = new byte[width * height]; PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, false); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println(e); }; cm = pg.getColorModel(); if (cm instanceof IndexColorModel) pixels = (byte[])(pg.getPixels()); if ((cm instanceof IndexColorModel) && ((IndexColorModel)cm).getTransparentPixel()!=-1) { IndexColorModel icm = (IndexColorModel)cm; int mapSize = icm.getMapSize(); byte[] reds = new byte[mapSize]; byte[] greens = new byte[mapSize]; byte[] blues = new byte[mapSize]; icm.getReds(reds); icm.getGreens(greens); icm.getBlues(blues); cm = new IndexColorModel(8, mapSize, reds, greens, blues); } }
/** Creates a ByteProcessor from an ImageProcessor. 16-bit and 32-bit * pixel data are scaled from min-max to 0-255 if 'scale' is true. * @see ImageProcessor#convertToByteProcessor * @see ImageProcessor#convertToShortProcessor * @see ImageProcessor#convertToFloatProcessor * @see ImageProcessor#convertToColorProcessor */ public ByteProcessor(ImageProcessor ip, boolean scale) { ImageProcessor bp; if (ip instanceof ByteProcessor) bp = ip.duplicate(); else bp = ip.convertToByte(scale); this.width = bp.getWidth(); this.height = bp.getHeight(); resetRoi(); this.pixels = (byte[])bp.getPixels(); this.cm = bp.getCurrentColorModel(); }
/** Creates a ByteProcessor from an ImageProcessor. 16-bit and 32-bit * pixel data are scaled from min-max to 0-255 if 'scale' is true. * @see ImageProcessor#convertToByteProcessor * @see ImageProcessor#convertToShortProcessor * @see ImageProcessor#convertToFloatProcessor * @see ImageProcessor#convertToColorProcessor */ public ByteProcessor(ImageProcessor ip, boolean scale) { ImageProcessor bp; if (ip instanceof ByteProcessor) bp = ip.duplicate(); else bp = ip.convertToByte(scale); this.width = bp.getWidth(); this.height = bp.getHeight(); resetRoi(); this.pixels = (byte[])bp.getPixels(); this.cm = bp.getCurrentColorModel(); }
private void eraseHeaderAreas (ByteProcessor buffer) { final int dmzDyMargin = sheet.getScale().toPixels(constants.staffVerticalMargin); buffer.setValue(255); for (SystemInfo system : sheet.getSystems()) { Staff firstStaff = system.getFirstStaff(); Staff lastStaff = system.getLastStaff(); int start = system.getBounds().x; int stop = firstStaff.getHeaderStop(); int top = firstStaff.getFirstLine().yAt(stop) - dmzDyMargin; int bot = lastStaff.getLastLine().yAt(stop) + dmzDyMargin; buffer.setRoi(start, top, stop - start + 1, bot - top + 1); buffer.fill(); buffer.resetRoi(); } buffer.setValue(0); }