Java Code Examples for ij.process.ByteProcessor#getPixels()
The following examples show how to use
ij.process.ByteProcessor#getPixels() .
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: ByteUtil.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Fill the ByteProcessor with provided value. * * @param bp buffer * @param val value to fill buffer with */ public static void fill (ByteProcessor bp, int val) { final byte[] pixels = (byte[]) bp.getPixels(); Arrays.fill(pixels, (byte) val); }
Example 2
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 3
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 4
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 5
Source File: IntegralImageMipMaps.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** WARNING modifies the {@code outside} array when both {@code alpha} and {@code outside} are not null, * and when {@code ip} is a {@link ColorProcessor}, will also modify ints int[] pixels * if {@code alpha} or {@code outside} are not null (the alpha channel is or'ed in). * * @param patch * @param ip * @param alpha * @param outside * @param type * @return An array of images represented by an array of byte[], where each is a channel of the image. */ static public final ImageBytes[] create( final Patch patch, ImageProcessor ip, final ByteProcessor alpha, final ByteProcessor outside, final int type) { // Combine alpha and outside // WARNING modifies alpha array final ByteProcessor mask; if (null == alpha) { mask = null == outside ? null : outside; } else if (null == outside) { mask = alpha; } else { final byte[] b1 = (byte[])alpha.getPixels(), b2 = (byte[])outside.getPixels(); for (int i=0; i<b1.length; ++i) { b2[i] = (byte)((b2[i]&0xff) != 255 ? 0 : (b1[i]&0xff)); // 'outside' is a binary mask, qualitative } mask = outside; } // Set min and max /** // No NEED, taken care of by the FSLoader callee function switch (type) { case ImagePlus.COLOR_256: ip = ip.convertToRGB(); //$FALL-THROUGH$ case ImagePlus.GRAY8: case ImagePlus.COLOR_RGB: if (0 != patch.getMin() || 255 != patch.getMax()) { ip = ip.duplicate(); // min,max is destructive on 8-bit channels, so make a copy ip.setMinAndMax(patch.getMin(), patch.getMax()); } break; default: ip.setMinAndMax(patch.getMin(), patch.getMax()); break; } */ // Generate pyramid switch (type) { case ImagePlus.GRAY16: case ImagePlus.GRAY32: ip = ip.convertToByte(true); //$FALL-THROUGH$ case ImagePlus.GRAY8: return fastCreateGRAY8(patch, (ByteProcessor)ip, mask); case ImagePlus.COLOR_256: // Already converted to RGB above case ImagePlus.COLOR_RGB: return fastCreateRGB(patch, (ColorProcessor)ip, mask); } return null; }
Example 6
Source File: IntegralImageMipMaps.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
private static final ImageBytes[] fastCreateGRAY8( final Patch patch, final ByteProcessor ip, final ByteProcessor mask) { final int w = ip.getWidth(); final int h = ip.getHeight(); // Integrals final long[] ii = FastIntegralImage.longIntegralImage((byte[])ip.getPixels(), w, h); final long[] mi = null == mask ? null : FastIntegralImage.longIntegralImage((byte[])mask.getPixels(), w, h); // Generate images final ImageBytes[] bis = new ImageBytes[Loader.getHighestMipMapLevel(patch) + 1]; // if (null == mask) { // mask is null // Save images as grayscale bis[0] = new ImageBytes(new byte[][]{(byte[])ip.getPixels()}, ip.getWidth(), ip.getHeight()); 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 bis[i] = new ImageBytes(new byte[][]{FastIntegralImage.scaleAreaAverage(ii, w+1, h+1, wk, hk)}, wk, hk); } } else { // Save images as RGBA, where all 3 color channels are the same bis[0] = new ImageBytes(new byte[][]{(byte[])ip.getPixels(), (byte[])mask.getPixels()}, ip.getWidth(), ip.getHeight()); for (int i=1; i<bis.length; i++) { final int K = (int) Math.pow(2, i), wk = w / K, hk = h / K; // bis[i] = new ImageBytes( new byte[][]{FastIntegralImage.scaleAreaAverage(ii, w+1, h+1, wk, hk), FastIntegralImage.scaleAreaAverage(mi, w+1, h+1, wk, hk)}, wk, hk); } } return bis; }
Example 7
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()); }
Example 8
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()); }