public ImageProcessor open16bitRawImage(InputStream is, int width, int height) throws IOException { int size = width * height * 2; byte[] bytes = new byte[size]; int count = 0; while (count < size && count >= 0) count = is.read(bytes, count, size - count); short[] pixels = new short[size / 2]; for (int i = 0, j = 0; i < size / 2; i++, j += 2) pixels[i] = (short) (((bytes[j] & 0xff) << 8) | (bytes[j + 1] & 0xff)); //big endian return new ShortProcessor(width, height, pixels, null); }
public ImageProcessor open16bitRawImage(InputStream is, int width, int height) throws IOException { int size = width * height * 2; byte[] bytes = new byte[size]; int count = 0; while (count < size && count >= 0) count = is.read(bytes, count, size - count); short[] pixels = new short[size / 2]; for (int i = 0, j = 0; i < size / 2; i++, j += 2) pixels[i] = (short) (((bytes[j] & 0xff) << 8) | (bytes[j + 1] & 0xff)); //big endian return new ShortProcessor(width, height, pixels, null); }
public static ImageProcessor openRaw(String path, int w, int h) { byte[] bytes = new byte[w * h * 2]; short[] pixels = new short[w * h]; FileInputStream in = null; try { in = new FileInputStream(path); int read = 0; while(read < bytes.length) read += in.read(bytes, read, bytes.length - read); in.close(); } catch(IOException e) { throw new RuntimeException("Cannot load " + path, e); } for(int i = 0; i < pixels.length; i++) { int low = 0xff & bytes[2 * i]; int high = 0xff & bytes[2 * i + 1]; pixels[i] = (short)((high << 8) | low); } return new ShortProcessor(w, h, pixels, null); }
/** 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()); }
public ImageProcessor open16bitAsciiImage(StreamTokenizer tok, int width, int height) throws IOException { int i = 0; int size = width * height; int inc = size/20; // Progress update interval if (inc==0) inc = 1; short[] pixels = new short[size]; while (tok.nextToken() != tok.TT_EOF) { if (tok.ttype == tok.TT_NUMBER) { pixels[i++] = (short) (((int) tok.nval) & 65535); if (i%inc==0) IJ.showProgress(0.5 + ((double) i / size) / 2.0); } } IJ.showProgress(1.0); return new ShortProcessor(width, height, pixels, null); }
/** 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()); }
public ImageProcessor open16bitAsciiImage(StreamTokenizer tok, int width, int height) throws IOException { int i = 0; int size = width * height; int inc = size/20; // Progress update interval if (inc==0) inc = 1; short[] pixels = new short[size]; while (tok.nextToken() != tok.TT_EOF) { if (tok.ttype == tok.TT_NUMBER) { pixels[i++] = (short) (((int) tok.nval) & 65535); if (i%inc==0) IJ.showProgress(0.5 + ((double) i / size) / 2.0); } } IJ.showProgress(1.0); return new ShortProcessor(width, height, pixels, null); }
/** * Create an ImageJ ImageStack out of a float matrix. width is the width of each image. * @param a a float[][] matrix with the images as column vectors. * @param width the width of each image in pixels. * @return an ImageStack. */ public static ImageStack imageStackFromMatrix(short [][] a, int width) { ImageStack is = new ImageStack(width, a[0].length / width); for (int j = 0; j < a.length; j++) is.addSlice(""+j, new ShortProcessor(width, a[0].length / width, a[j], null)); return is; } /**
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; }
final static protected ShortProcessor mapIntensities( final PatchIntensityRange pir, final double min, final double max ) { final double a = 65535.0 / ( max - min ); final ImageProcessor source = pir.patch.getImageProcessor(); final short[] targetPixels = new short[ source.getWidth() * source.getHeight() ]; for ( int i = 0; i < targetPixels.length; ++i ) { targetPixels[ i ] = ( short )Math.max( 0, Math.min( 65535, Math.round( ( ( source.getf( i ) - pir.patch.getMin() ) / pir.a - min ) * a ) ) ); } final ShortProcessor target = new ShortProcessor( source.getWidth(), source.getHeight(), targetPixels, null ); target.setMinAndMax( -min * a, ( 1.0 - min ) * a ); return target; }
/** 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; }
public ImagePlus composeImages(ArrayList<ImagePlus> imageList){ int sumWidth = 0; int maxHeight = 0; for(ImagePlus imp : imageList){ sumWidth = sumWidth +imp.getWidth(); if(imp.getHeight() > maxHeight) maxHeight = imp.getWidth(); } ImagePlus impComposite = new ImagePlus(); ImageProcessor ipComposite = new ShortProcessor(sumWidth, maxHeight); for(int i=0; i<sumWidth; i++){ for(int j=0; j<sumWidth; j++){ ipComposite.putPixelValue(i, j, figureOutThis); } } impComposite.setProcessor(ipComposite); return impComposite; }
private ShortProcessor initialize(ImageProcessor marker) { // size of image sizeX = marker.getWidth(); sizeY = marker.getHeight(); ShortProcessor distMap = new ShortProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (foreground) or Inf (background) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int val = marker.get(x, y) & 0x00ff; distMap.set(x, y, val == 0 ? Short.MAX_VALUE : 0); } } return distMap; }
private ShortProcessor initialize(ImageProcessor marker) { // size of image sizeX = marker.getWidth(); sizeY = marker.getHeight(); ShortProcessor distMap = new ShortProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (foreground) or Inf (background) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int val = marker.get(x, y) & 0x00ff; distMap.set(x, y, val == 0 ? Short.MAX_VALUE : 0); } } return distMap; }
static public final ShortProcessor median( final ShortProcessor sp, final int nBins, final double min, final double max, final int radius) { final long[] hist = integralHistogram2d((short[])sp.getPixels(), sp.getWidth(), sp.getHeight(), nBins, min, max); final short[] median = median(sp.getWidth(), sp.getHeight(), hist, nBins, min, max, radius); return new ShortProcessor(sp.getWidth(), sp.getHeight(), median, null); }
/** This method has been replaced by IJ.createHyperStack(). */ public ImagePlus createHyperStack(String title, int channels, int slices, int frames, int bitDepth) { int size = channels*slices*frames; ImageStack stack2 = new ImageStack(width, height, size); // create empty stack ImageProcessor ip2 = null; switch (bitDepth) { case 8: ip2 = new ByteProcessor(width, height); break; case 16: ip2 = new ShortProcessor(width, height); break; case 24: ip2 = new ColorProcessor(width, height); break; case 32: ip2 = new FloatProcessor(width, height); break; default: throw new IllegalArgumentException("Invalid bit depth"); } stack2.setPixels(ip2.getPixels(), 1); // can't create ImagePlus will null 1st image ImagePlus imp2 = new ImagePlus(title, stack2); stack2.setPixels(null, 1); imp2.setDimensions(channels, slices, frames); imp2.setCalibration(getCalibration()); imp2.setOpenAsHyperStack(true); return imp2; }
private ShortProcessor initializeResult(ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Initialization")); // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // create new empty image, and fill it with black ShortProcessor distMap = new ShortProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (background) or Inf (foreground) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int label = (int) labelImage.getf(x, y); distMap.set(x, y, label == 0 ? 0 : Short.MAX_VALUE); } } return distMap; }
private ShortProcessor initializeResult(ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Initialization")); // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // create new empty image, and fill it with black ShortProcessor distMap = new ShortProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (background) or Inf (foreground) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int label = (int) labelImage.getf(x, y); distMap.set(x, y, label == 0 ? 0 : Short.MAX_VALUE); } } return distMap; }
/** This method has been replaced by IJ.createHyperStack(). */ public ImagePlus createHyperStack(String title, int channels, int slices, int frames, int bitDepth) { int size = channels*slices*frames; ImageStack stack2 = new ImageStack(width, height, size); // create empty stack ImageProcessor ip2 = null; switch (bitDepth) { case 8: ip2 = new ByteProcessor(width, height); break; case 16: ip2 = new ShortProcessor(width, height); break; case 24: ip2 = new ColorProcessor(width, height); break; case 32: ip2 = new FloatProcessor(width, height); break; default: throw new IllegalArgumentException("Invalid bit depth"); } stack2.setPixels(ip2.getPixels(), 1); // can't create ImagePlus will null 1st image ImagePlus imp2 = new ImagePlus(title, stack2); stack2.setPixels(null, 1); imp2.setDimensions(channels, slices, frames); imp2.setCalibration(getCalibration()); imp2.setOpenAsHyperStack(true); return imp2; }