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; }
protected FloatProcessor convertToFloat( final ShortProcessor sp ) { final short[] pixS = (short[]) sp.getPixels(); loader.releaseToFit( pixS.length * 4 ); final float[] pixF = new float[pixS.length]; for ( int i=0; i<pixS.length; ++i) { pixF[i] = pixS[i] & 0xffff; } return new FloatProcessor( sp.getWidth(), sp.getHeight(), pixF ); }
/** Returns a FloatProcessor with the same image, no scaling or calibration * (pixel values 0 to 65535). * The roi, mask, lut (ColorModel), threshold, min&max are * also set for the FloatProcessor * @param channelNumber Ignored (needed for compatibility with ColorProcessor.toFloat) * @param fp Here a FloatProcessor can be supplied, or null. The FloatProcessor * is overwritten by this method (re-using its pixels array * improves performance). * @return A FloatProcessor with the converted image data */ public FloatProcessor toFloat(int channelNumber, FloatProcessor fp) { int size = width*height; if (fp == null || fp.getWidth()!=width || fp.getHeight()!=height) fp = new FloatProcessor(width, height, new float[size], cm); float[] fPixels = (float[])fp.getPixels(); for (int i=0; i<size; i++) fPixels[i] = pixels[i]&0xffff; fp.setRoi(getRoi()); fp.setMask(mask); fp.setMinAndMax(getMin(), getMax()); fp.setThreshold(minThreshold, maxThreshold, ImageProcessor.NO_LUT_UPDATE); return fp; }
/** Sets the foreground fill/draw color. */ public void setColor(Color color) { drawingColor = color; int bestIndex = getBestIndex(color); if (bestIndex>0 && getMin()==0.0 && getMax()==0.0) { setValue(bestIndex); setMinAndMax(0.0,255.0); } else if (bestIndex==0 && getMin()>0.0 && (color.getRGB()&0xffffff)==0) { if (isSigned16Bit()) setValue(32768); else setValue(0.0); } else fgColor = (int)(getMin() + (getMax()-getMin())*(bestIndex/255.0)); }
/** 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; }
double max = -Double.MAX_VALUE; ImageStack stack = new ImageStack(width, height); FileInfo fi = images[0].getOriginalFileInfo(); if (fi!=null && fi.directory==null) fi = null; Overlay overlay = new Overlay(); for (int i=0; i<count; i++) { ImageProcessor ip = images[i].getProcessor(); boolean invertedLut = ip.isInvertedLut(); if (ip.getMin()<min) min = ip.getMin(); if (ip.getMax()>max) max = ip.getMax(); String label = titlesAsLabels?images[i].getTitle():null; if (label!=null) { String info = (String)images[i].getProperty("Info"); ImageProcessor ip2 = null; switch (stackType) { case 8: ip2 = new ByteProcessor(width, height); break; case 16: ip2 = new ShortProcessor(width, height); break; case 32: ip2 = new FloatProcessor(width, height); break; case rgb: ip2 = new ColorProcessor(width, height); break;
int type = imagePlus.getType(); Roi roi = imagePlus.getRoi(); if (roi == null) throw new IllegalArgumentException("There's no point selected in the image."); point_roi_z = imagePlus.getCurrentSlice()-1; for (int z = 0; z < depth; ++z) { ByteProcessor bp = (ByteProcessor) stack.getProcessor(z+1); sliceDataBytes[z] = (byte[]) bp.getPixelsCopy(); for (int z = 0; z < depth; ++z) { FloatProcessor bp = (FloatProcessor) stack.getProcessor(z+1); sliceDataFloats[z] = (float[]) bp.getPixelsCopy(); allRegionsPixels = new short[depth][width*height]; for( int z = 0; z < depth; z++ ) { ShortProcessor sp = new ShortProcessor(width,height); sp.setPixels(allRegionsPixels[z]); allRegionsStack.addSlice("",sp); results.allRegions.updateAndDraw(); ByteProcessor bp = new ByteProcessor(width, height); bp.setPixels(sliceBytes); newStack.addSlice("", bp);
public ImagePlus makeShollCrossingsImagePlus(final ImagePlus original) { final int width = original.getWidth(); final int height = original.getHeight(); final int depth = original.getStackSize(); final Calibration c = original.getCalibration(); double x_spacing = 1; final ShortProcessor sp = new ShortProcessor(width, height); sp.setPixels(pixels); stack.addSlice("", sp); final ImageProcessor ip = result.getProcessor(); if (ip != null) { ip.setColorModel(icm); ip.setMinAndMax(0, maxCrossings); result.updateAndDraw();
boolean adjust_origin ) { int original_width = imp.getWidth(); int last_slice = max_z + 1; ImageStack stack=imp.getStack(); ImageStack new_stack=new ImageStack( new_width, new_height ); int type = imp.getType(); ByteProcessor bp = new ByteProcessor( new_width, new_height ); bp.setPixels( new_slice ); ShortProcessor sp = new ShortProcessor( new_width, new_height ); sp.setPixels( new_slice ); ColorProcessor cp = new ColorProcessor( new_width, new_height ); cp.setPixels( new_slice ); FloatProcessor fp = new FloatProcessor( new_width, new_height ); fp.setPixels( new_slice );
type = xy.getType(); bytesPerPixel = xy.getBitDepth() / 8; original_xy_canvas = imagePlus.getWindow().getCanvas(); ByteProcessor bp = new ByteProcessor( zy_width, zy_height ); bp.setPixels( sliceBytes ); zy_stack.addSlice( null, bp ); IJ.showProgress( x_in_original / (double)width ); ShortProcessor sp = new ShortProcessor( zy_width, zy_height ); sp.setPixels( sliceShorts ); zy_stack.addSlice( null, sp ); IJ.showProgress( x_in_original / (double)width ); ByteProcessor bp = new ByteProcessor( xz_width, xz_height ); ShortProcessor sp = new ShortProcessor( xz_width, xz_height ); sp.setPixels( sliceShorts ); xz_stack.addSlice( null, sp ); ColorProcessor cp = new ColorProcessor( xz_width, xz_height ); FloatProcessor fp = new FloatProcessor( xz_width, xz_height );
int originalImageType = imagePlus.getType(); int width = imagePlus.getWidth(); int height = imagePlus.getHeight(); ImageStack stack = imagePlus.getStack(); int depth = stack.getSize(); ShortProcessor sp=new ShortProcessor(width,height); sp.setPixels(newPixelsShort); newStack.addSlice("",sp); } else { ByteProcessor bp=new ByteProcessor(width,height); bp.setPixels(newPixelsByte); newStack.addSlice("",bp);
imp = IJ.openImage(url); if (imp!=null) { labels[n-1] = (new File(list[n-1])).getName()+"\n"+(String)imp.getProperty("Info"); ImageProcessor ip = imp.getProcessor(); int bitDepth = getBitDepth(); if (imp.getBitDepth()!=bitDepth) { switch (bitDepth) { case 8: ip=ip.convertToByte(true); break; case 16: ip=ip.convertToShort(true); break; case 24: ip=ip.convertToRGB(); break; case 32: ip=ip.convertToFloat(); break; ImageProcessor ip = null; switch (getBitDepth()) { case 8: ip=new ByteProcessor(imageWidth,imageHeight); break; case 16: ip=new ShortProcessor(imageWidth,imageHeight); break; case 24: ip=new ColorProcessor(imageWidth,imageHeight); break; case 32: ip=new FloatProcessor(imageWidth,imageHeight); break;
ImageStack stack = imp.createEmptyStack(); int inc = nSlices/40; if (inc<1) inc = 1; case GRAY8: pixels2 = new byte[width*height]; if (fill==FILL_NOISE) fillNoiseByte(new ByteProcessor(width,height,(byte[])pixels2)); break; case GRAY16: pixels2 = new short[width*height]; if (fill==FILL_NOISE) fillNoiseShort(new ShortProcessor(width,height,(short[])pixels2,null)); break; case GRAY32: pixels2 = new float[width*height]; if (fill==FILL_NOISE) fillNoiseFloat(new FloatProcessor(width,height,(float[])pixels2,null)); break; case RGB: pixels2 = new int[width*height]; if (fill==FILL_NOISE) fillNoiseRGB(new ColorProcessor(width,height,(int[])pixels2), false); break; System.arraycopy(ip.getPixels(), 0, pixels2, 0, width*height); stack.addSlice(null, pixels2); if (IJ.escapePressed()) {IJ.beep(); break;};
/** 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; }
pixels = readPixels(fi); if (pixels==null) return null; ip = new ByteProcessor(width, height, (byte[])pixels, cm); imp = new ImagePlus(fi.fileName, ip); break; case FileInfo.GRAY16_SIGNED: pixels = readPixels(fi); if (pixels==null) return null; ip = new ShortProcessor(width, height, (short[])pixels, cm); imp = new ImagePlus(fi.fileName, ip); break; case FileInfo.GRAY32_INT: pixels = readPixels(fi); if (pixels==null) return null; ip = new FloatProcessor(width, height, (float[])pixels, cm); imp = new ImagePlus(fi.fileName, ip); break; case FileInfo.RGB: imp.setDimensions(nChannels, 1, 1); if (planar) imp.getProcessor().resetMinAndMax(); imp.setFileInfo(fi); int mode = IJ.COMPOSITE;
Arrays.fill(result, flatColor); if (colorImage != null) { final ImageStack stack = colorImage.getStack(); final int width = colorImage.getWidth(); final int height = colorImage.getHeight(); colorImage.getProcessor().getCurrentColorModel(); final ColorProcessor cp = (ColorProcessor) stack.getProcessor(z + 1); final Color c = cp.getColor(x, y); result[i] = new Color3f(c); case ImagePlus.GRAY8: { final ByteProcessor bp = (ByteProcessor) stack.getProcessor(z + 1); final int v = bp.getPixel(x, y); if (cm == null) { final float fv = v / 255.0f; final ShortProcessor sp = (ShortProcessor) stack.getProcessor(z + 1); final int s = sp.getPixel(x, y); final int v = enrangeInteger((s - sp.getMin()) * 255.0f / (sp.getMax() - sp.getMin()), 0, 255); result[i] = new Color3f((reds[v] & 0xFF) / 255.0f,
final ImagePlus imp1 = new ImagePlus( "http://fly.mpi-cbg.de/~saalfeld/Pictures/norway.jpg"); final ArrayImg< FloatType, FloatArray > image1 = ArrayImgs.floats( ( float[] )imp1.getProcessor().convertToFloatProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< UnsignedByteType, ByteArray > image2 = ArrayImgs.unsignedBytes( ( byte[] )imp1.getProcessor().convertToByteProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< UnsignedShortType, ShortArray > image3 = ArrayImgs.unsignedShorts( ( short[] )imp1.getProcessor().convertToShortProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< ARGBType, IntArray > image4 = ArrayImgs.argbs( ( int[] )imp1.getProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() );
ij.process.ByteProcessor bp = (ij.process.ByteProcessor) ij.IJ.openImage(image_file_path).getProcessor(); byte[] pix = (byte[]) bp.getPixels(); double[] fii = doubleIntegralImage(pix, bp.getWidth(), bp.getHeight()); byte[] scaled = scaleAreaAverage(fii, bp.getWidth()+1, bp.getHeight()+1, bp.getWidth()/4, bp.getHeight()/4); new ij.ImagePlus("integral double", new ij.process.FloatProcessor(bp.getWidth()+1, bp.getHeight()+1, fpix, null)).show(); new ij.ImagePlus("scaled double", new ij.process.ByteProcessor(bp.getWidth()/4, bp.getHeight()/4, scaled, null)).show(); final float[] fpix = new float[lii.length]; for (int i=0; i<fpix.length; ++i) fpix[i] = (float)lii[i]; new ij.ImagePlus("integral long", new ij.process.FloatProcessor(bp.getWidth()+1, bp.getHeight()+1, fpix, null)).show(); new ij.ImagePlus("scaled long", new ij.process.ByteProcessor(bp.getWidth()/4, bp.getHeight()/4, scaled, null)).show(); ij.process.ShortProcessor bp = (ij.process.ShortProcessor) ij.IJ.openImage(image_file_path).getProcessor().convertToShort(true); short[] pix = (short[]) bp.getPixels(); for (int i=0; i<pix.length; ++i) pix[i] *= 255; // expand to 16-bit range: when doing so, the scaleAreaAverage fails long[] lii = longIntegralImage(pix, bp.getWidth(), bp.getHeight()); byte[] scaled = scaleAreaAverage(lii, bp.getWidth()+1, bp.getHeight()+1, bp.getWidth()/4, bp.getHeight()/4); final float[] fpix = new float[lii.length]; for (int i=0; i<fpix.length; ++i) fpix[i] = (float)lii[i]; new ij.ImagePlus("integral long of short", new ij.process.FloatProcessor(bp.getWidth()+1, bp.getHeight()+1, fpix, null)).show(); new ij.ImagePlus("scaled long of short", new ij.process.ByteProcessor(bp.getWidth()/4, bp.getHeight()/4, scaled, null)).show();
/** * Creates a 2D Sholl heatmap by applying measured values to the foreground * pixels of a copy of the analyzed image */ public ImageProcessor getMaskProcessor(final boolean floatProcessor, final double[] maskValues) { checkUnsetFields(); // Work on a stack projection when dealing with a volume final ImageProcessor ip = imp.getNSlices() > 1 ? projImp() : imp.getProcessor(); // NB: 16-bit image: Negative values will be set to 0 final ImageProcessor mp = floatProcessor ? new FloatProcessor(ip.getWidth(), ip.getHeight()) : new ShortProcessor(ip.getWidth(), ip.getHeight()); final int drawSteps = maskValues.length; final int sRadius = (int) Math.round(profile.startRadius() / voxelSize); final int drawWidth = (int) Math.round((profile.endRadius() - profile.startRadius()) / drawSteps); for (int i = 0; i < drawSteps; i++) { int drawRadius = sRadius + i * drawWidth; for (int j = 0; j < drawWidth; j++) { // this will already exclude pixels out of bounds final int[][] points = getCircumferencePoints(xc, yc, drawRadius++); for (final int[] point : points) { final double value = ip.getPixel(point[0], point[1]); if (withinThreshold(value)) { mp.putPixelValue(point[0], point[1], maskValues[i]); } } } } mp.resetMinAndMax(); return mp; }