Java Code Examples for ij.process.ByteProcessor#getHeight()
The following examples show how to use
ij.process.ByteProcessor#getHeight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SheetDiff.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * Count the number of foreground pixels in the provided image. * * @param filter the binary image * @return the number of foreground pixels */ private int getForeCount (ByteProcessor filter) { final int width = filter.getWidth(); final int height = filter.getHeight(); int count = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (filter.get(x, y) == 0) { count++; } } } return count; }
Example 2
Source File: SectionCompound.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * Build a (fixed) glyph, based on current content of this section compound. * * @param group targeted group, perhaps null * @return a glyph made of compound pixels */ public Glyph toGlyph (GlyphGroup group) { // Fill buffer with section pixels final ByteProcessor buffer = toBuffer(); // Allocate and populate properly oriented run table final RunTableFactory factory = new RunTableFactory((buffer.getWidth() > buffer.getHeight()) ? HORIZONTAL : VERTICAL, null); final RunTable runTable = factory.createTable(buffer); // Allocate glyph with proper offset final Glyph glyph = new Glyph(bounds.x, bounds.y, runTable); glyph.addGroup(group); return glyph; }
Example 3
Source File: AdaptiveFilter.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
@Override public ByteProcessor filteredImage () { ByteProcessor ip = new ByteProcessor(source.getWidth(), source.getHeight()); for (int x = 0, w = ip.getWidth(); x < w; x++) { for (int y = 0, h = ip.getHeight(); y < h; y++) { if (isFore(x, y)) { ip.set(x, y, FOREGROUND); } else { ip.set(x, y, BACKGROUND); } } } return ip; }
Example 4
Source File: Patch.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
/** Must call updateMipMaps() afterwards. Set it to null to remove it. * @return true if the alpha mask file was written successfully. */ public synchronized boolean setAlphaMask(final ByteProcessor bp) throws IllegalArgumentException { if (null == bp) { alpha_mask_id = 0; return true; } // Check that the alpha mask represented by argument bp // has the appropriate dimensions: if (o_width != bp.getWidth() || o_height != bp.getHeight()) { throw new IllegalArgumentException("Need a mask of identical dimensions as the original image."); } final long amID = project.getLoader().getNextBlobId(); if (writeAlphaMask(bp, amID)) { this.alpha_mask_id = amID; return true; } else { Utils.log("Could NOT write the alpha mask file for patch #" + id); } return false; }
Example 5
Source File: TableUtil.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * Print out a ByteProcessor. * * @param title a title for the print * @param buf the input buffer */ public static void dump (String title, ByteProcessor buf) { final int width = buf.getWidth(); final int height = buf.getHeight(); if (title != null) { System.out.println(title); } final String yFormat = printAbscissae(width, height, 4); for (int y = 0; y < height; y++) { System.out.printf(yFormat, y); for (int x = 0; x < width; x++) { System.out.printf("%4d", buf.get(x, y)); } System.out.println(); } }
Example 6
Source File: Template.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Collect the image foreground pixels located under the template foreground areas. * * @param box absolute positioning of template box in global image * @param image global image to be read * @return the collection of foreground pixels, relative to template box. */ public List<Point> getForegroundPixels (Rectangle box, ByteProcessor image) { final int imgWidth = image.getWidth(); final int imgHeight = image.getHeight(); final List<Point> fores = new ArrayList<>(); for (PixelDistance pix : keyPoints) { if (pix.d != 0) { continue; } int nx = box.x + pix.x; int ny = box.y + pix.y; if ((nx >= 0) && (nx < imgWidth) && (ny >= 0) && (ny < imgHeight)) { // Check if we have some image foreground there int val = image.get(nx, ny); if (val == 0) { fores.add(new Point(pix.x, pix.y)); } } } return fores; }
Example 7
Source File: Utils.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
static public final BufferedImage convertToBufferedImage(final ByteProcessor bp) { bp.setMinAndMax(0, 255); // TODO what is this doing here? The ByteProcessor.setMinAndMax is destructive, it expands the pixel values to the desired range. final Image img = bp.createImage(); if (img instanceof BufferedImage) return (BufferedImage)img; //else: final BufferedImage bi = new BufferedImage(bp.getWidth(), bp.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, Loader.GRAY_LUT); bi.createGraphics().drawImage(img, 0, 0, null); return bi; }
Example 8
Source File: Utils.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** 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 ByteProcessor ip) { final byte[] pix = (byte[])ip.getPixels(); final float[] data = new float[pix.length]; for (int i=0; i<pix.length; i++) data[i] = pix[i]&0xff; final FloatProcessor fp = new FloatProcessorT2(ip.getWidth(), ip.getHeight(), data, ip.getColorModel(), ip.getMin(), ip.getMax()); return fp; }
Example 9
Source File: ImagePlusMatConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
/** * Duplicates {@link ByteProcessor} to the corresponding OpenCV image of * type {@link Mat}. * * @param bp The {@link ByteProcessor} to be converted * @return The OpenCV image (of type {@link Mat}) */ public static Mat toMat(ByteProcessor bp) { final int w = bp.getWidth(); final int h = bp.getHeight(); final byte[] pixels = (byte[]) bp.getPixels(); // version A - copies the pixel data to a new array // Size size = new Size(w, h); // Mat mat = new Mat(size, opencv_core.CV_8UC1); // mat.data().put(bData); // version 2 - reuses the existing pixel array return new Mat(h, w, opencv_core.CV_8UC1, new BytePointer(pixels)); }
Example 10
Source File: WatershedGrayLevelTest.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
private void merge (ByteProcessor img, boolean[][] lines) { for (int y = 0, h = img.getHeight(); y < h; y++) { for (int x = 0, w = img.getWidth(); x < w; x++) { if (lines[x][y]) { img.set(x, y, PixelSource.BACKGROUND); } } } }
Example 11
Source File: RunTableFactory.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Report the RunTable created with the runs retrieved from the provided source. * * @param source the source to read runs from. * @return a populated RunTable */ public RunTable createTable (ByteProcessor source) { // ROI is defined as the whole source final Rectangle roi = new Rectangle(0, 0, source.getWidth(), source.getHeight()); return createTable(source, roi); }
Example 12
Source File: AbstractGrayFilter.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Apply this filter on a given input image. * * @param input the input image * @return the filtered image */ public ByteProcessor filter (final ByteProcessor input) { final ByteProcessor output = new ByteProcessor(input.getWidth(), input.getHeight()); StopWatch watch = new StopWatch(getClass().getSimpleName()); watch.start("filter"); filter(input, output); ///watch.print(); return output; }
Example 13
Source File: ExportUnsignedByte.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
static public final Pair< ByteProcessor, ByteProcessor > makeFlatImage( final List<Patch> patches, final Rectangle roi, final double backgroundValue, final double scale, final ImageSource fetcher) { final ByteProcessor target = new ByteProcessor((int)(roi.width * scale), (int)(roi.height * scale)); target.setInterpolationMethod( ImageProcessor.BILINEAR ); final ByteProcessor targetMask = new ByteProcessor( target.getWidth(), target.getHeight() ); targetMask.setInterpolationMethod( ImageProcessor.NEAREST_NEIGHBOR ); for (final Patch patch : patches) { final ImageData imgd = fetcher.fetch( patch, scale ); // The affine to apply to the MipMap.image final AffineTransform atc = new AffineTransform(); atc.scale( scale, scale ); atc.translate( -roi.x, -roi.y ); final AffineTransform at = new AffineTransform(); at.preConcatenate( atc ); at.concatenate( patch.getAffineTransform() ); at.scale( imgd.scaleX, imgd.scaleY ); final AffineModel2D aff = new AffineModel2D(); aff.set( at ); final CoordinateTransformMesh mesh = new CoordinateTransformMesh( aff, patch.getMeshResolution(), imgd.bp.getWidth(), imgd.bp.getHeight() ); final TransformMeshMappingWithMasks< CoordinateTransformMesh > mapping = new TransformMeshMappingWithMasks< >( mesh ); imgd.bp.setInterpolationMethod( ImageProcessor.BILINEAR ); imgd.alpha.setInterpolationMethod( ImageProcessor.NEAREST_NEIGHBOR ); mapping.map( imgd.bp, imgd.alpha, target, targetMask ); } return new Pair< >( target, targetMask ); }
Example 14
Source File: AreaMask.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
ForeCounter (ByteProcessor filter, Wrapper<Integer> fore) { this.filter = filter; this.fore = fore; filterWidth = filter.getWidth(); filterHeight = filter.getHeight(); }
Example 15
Source File: ChamferDistance.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
private void initializeToFore (ByteProcessor input, DistanceTable output) { for (int i = (input.getWidth() * input.getHeight()) - 1; i >= 0; i--) { if (input.get(i) == 0) { output.setValue(i, VALUE_TARGET); // reference pixel -> distance=0 } else { output.setValue(i, VALUE_UNKNOWN); // non-reference pixel -> to be computed } } }
Example 16
Source File: ElasticMontage.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
final static protected FloatProcessor scaleByte( final ByteProcessor bp ) { final FloatProcessor fp = new FloatProcessor( bp.getWidth(), bp.getHeight() ); final byte[] bytes = ( byte[] )bp.getPixels(); final float[] floats = ( float[] )fp.getPixels(); for ( int i = 0; i < bytes.length; ++i ) floats[ i ] = ( bytes[ i ] & 0xff ) / 255.0f; return fp; }
Example 17
Source File: MedianGrayFilter.java From audiveris with GNU Affero General Public License v3.0 | 4 votes |
@Override public void filter (final ByteProcessor input, final ByteProcessor output) { final int width = input.getWidth(); final int height = input.getHeight(); final int[] histogram = new int[256]; Arrays.fill(histogram, 0); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // To address specific behavior at image boundaries, // reduce radius to not use pixels outside the image. int rad = radius; if ((x - rad) < 0) { rad = x; } if ((y - rad) < 0) { rad = y; } if ((x + rad) >= width) { rad = width - 1 - x; } if ((y + rad) >= height) { rad = height - 1 - y; } Arrays.fill(histogram, 0); // Brute force! for (int i = x - rad; i <= (x + rad); i++) { for (int j = y - rad; j <= (y + rad); j++) { int val = input.get(i, j); histogram[val]++; } } // Pick up the median value final int side = (2 * rad) + 1; final int medianCount = ((side * side) + 1) / 2; int median = 255; int sum = 0; while (sum < medianCount) { sum += histogram[median]; median--; } output.set(x, y, median + 1); } } }
Example 18
Source File: IntegralImageMipMaps.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings({ "unused", "unchecked", "null" }) private static final BufferedImage[] createGRAY8( final Patch patch, final ByteProcessor ip, final ByteProcessor mask) { final int w = ip.getWidth(); final int h = ip.getHeight(); final int[] dims = new int[]{w, h}; final ScaleAreaAveraging2d<LongType, UnsignedByteType> saai, saam; { // Integral of the image final IntegralImage<UnsignedByteType, LongType> oa = new IntegralImage<UnsignedByteType, LongType>( wrap((byte[])ip.getPixels(), dims), new LongType(), new IntegerTypeConverter<UnsignedByteType, LongType>()); oa.process(); saai = new ScaleAreaAveraging2d<LongType, UnsignedByteType>( oa.getResult(), new UnsignedByteType(), dims); // Integral of the mask, if any if (null != mask) { final IntegralImage<UnsignedByteType, LongType> ma = new IntegralImage<UnsignedByteType, LongType>( wrap((byte[])mask.getPixels(), dims), new LongType(), new IntegerTypeConverter<UnsignedByteType, LongType>()); ma.process(); saam = new ScaleAreaAveraging2d<LongType, UnsignedByteType>(ma.getResult(), new UnsignedByteType(), dims); } else { saam = null; } } // Generate images final BufferedImage[] bis = new BufferedImage[Loader.getHighestMipMapLevel(patch) + 1]; // if (null == saam) { // mask is null // Save images as grayscale bis[0] = ImageSaver.createGrayImage((byte[])ip.getPixels(), w, h); // sharing the byte[] for (int i=1; i<bis.length; i++) { final int K = (int) Math.pow(2, i), wk = w / K, hk = h / K; // An image of the scaled size saai.setOutputDimensions(wk, hk); saai.process(); bis[i] = ImageSaver.createGrayImage(((Array<UnsignedByteType,ByteArray>) saai.getResult().getContainer()).update(null).getCurrentStorageArray(), wk, hk); } } else { // Save images as RGBA, where all 3 color channels are the same bis[0] = ImageSaver.createARGBImage(blend((byte[])ip.getPixels(), (byte[])mask.getPixels()), w, h); for (int i=1; i<bis.length; i++) { final int K = (int) Math.pow(2, i), wk = w / K, hk = h / K; // An image of the scaled size saai.setOutputDimensions(wk, hk); saai.process(); // A mask of the scaled size saam.setOutputDimensions(wk, hk); saam.process(); // bis[i] = ImageSaver.createARGBImage( blend( ((Array<UnsignedByteType,ByteArray>) saai.getResult().getContainer()).update(null).getCurrentStorageArray(), ((Array<UnsignedByteType,ByteArray>) saam.getResult().getContainer()).update(null).getCurrentStorageArray()), wk, hk); } } return bis; }
Example 19
Source File: DownsamplerMipMaps.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
static private final ImageBytes asBytes(final ByteProcessor bp, final ByteProcessor mask) { return new ImageBytes(new byte[][]{(byte[])bp.getPixels(), (byte[])mask.getPixels()}, bp.getWidth(), bp.getHeight()); }
Example 20
Source File: DownsamplerMipMaps.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
static private final ImageBytes asBytes(final ByteProcessor bp) { return new ImageBytes(new byte[][]{(byte[])bp.getPixels()}, bp.getWidth(), bp.getHeight()); }