Refine search
private ImagePlus createBinary(ImagePlus image, int value) { int w = image.getWidth(), h = image.getWidth(); int d = image.getStackSize(); ImageStack stack = new ImageStack(w, h); for(int z = 0; z < d; z++) { byte[] f = new byte[w*h]; byte[] p = (byte[])image.getStack() .getProcessor(z+1).getPixels(); for(int i = 0; i < w*h; i++) f[i] = (int)(p[i]&0xff) == value ? (byte)255 : 0; stack.addSlice("", new ByteProcessor(w, h, f, null)); } return new ImagePlus("Label_" + (int)(value&0xff), stack); }
/** * Merge three image stack into a color stack (no scaling) * * @param redChannel image stack representing the red channel * @param greenChannel image stack representing the green channel * @param blueChannel image stack representing the blue channel * @return RGB merged stack */ ImageStack mergeStacks(ImageStack redChannel, ImageStack greenChannel, ImageStack blueChannel) { final ImageStack colorStack = new ImageStack( redChannel.getWidth(), redChannel.getHeight()); for(int n=1; n<=redChannel.getSize(); n++) { final ByteProcessor red = (ByteProcessor) redChannel.getProcessor(n).convertToByte(false); final ByteProcessor green = (ByteProcessor) greenChannel.getProcessor(n).convertToByte(false); final ByteProcessor blue = (ByteProcessor) blueChannel.getProcessor(n).convertToByte(false); final ColorProcessor cp = new ColorProcessor(redChannel.getWidth(), redChannel.getHeight()); cp.setRGB((byte[]) red.getPixels(), (byte[]) green.getPixels(), (byte[]) blue.getPixels() ); colorStack.addSlice(redChannel.getSliceLabel(n), cp); } return colorStack; }
Roi getRoiNonBackground( ByteProcessor bp ) { bp.setThreshold(1,255,ImageProcessor.NO_LUT_UPDATE); // bp.threshold(0); ImageStack tempStack = new ImageStack(bp.getWidth(),bp.getHeight()); tempStack.addSlice(null,bp); ImagePlus imp = new ImagePlus("example stack",tempStack); ThresholdToSelection tts = new ThresholdToSelection(); tts.setup( "", imp ); tts.run(bp); // imp.show(); return imp.getRoi(); }
/** Returns the specified plane (1=red, 2=green, 3=blue, 4=alpha) as a ByteProcessor. */ public ByteProcessor getChannel(int channel, ByteProcessor bp) { int size = width*height; if (bp == null || bp.getWidth()!=width || bp.getHeight()!=height) bp = new ByteProcessor(width, height); byte[] bPixels = (byte[])bp.getPixels(); int shift = 16 - 8*(channel-1); if (channel==4) shift=24; for (int i=0; i<size; i++) bPixels[i] = (byte)(pixels[i]>>shift); return bp; }
private void applyShortOrFloatThreshold(ImagePlus imp) { if (!imp.lock()) return; int width = imp.getWidth(); int height = imp.getHeight(); int size = width*height; boolean isFloat = imp.getType()==ImagePlus.GRAY32; IJ.showStatus("Converting to mask"); for (int i=1; i<=nSlices; i++) { IJ.showProgress(i, nSlices); String label = stack1.getSliceLabel(i); ip1 = stack1.getProcessor(i); ip2 = new ByteProcessor(width, height); for (int j=0; j<size; j++) { value = ip1.getf(j); imp.getProcessor().setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); if (IJ.debugMode) IJ.log("Thresholder16: 255-255 ("+(Prefs.blackBackground?"black":"white")+" background)"); IJ.showStatus(""); imp.unlock();
int sizeY) final int maxPoolWidth = input.getWidth() / sizeX; final int maxPoolHeight = input.getHeight() / sizeY; final int inputWidth = input.getWidth(); final int inputHeight = input.getHeight(); ImageStack isMaxPoolInput = new ImageStack(maxPoolWidth, maxPoolHeight); ImageStack isMaxPoolLabel = new ImageStack(maxPoolWidth, maxPoolHeight); for(int slice = 1; slice <= input.getImageStackSize(); slice ++) IJ.log("Processing slice " + slice + "..."); double val = ((float[]) input.getImageStack().getProcessor( slice ).getPixels())[pos]; labelPix[ pos2 ] = ((byte[]) label.getImageStack().getProcessor( slice ).getPixels())[ pos ]; isMaxPoolInput.addSlice( new FloatProcessor( maxPoolWidth, maxPoolHeight, inputPix)); isMaxPoolLabel.addSlice( new ByteProcessor( maxPoolWidth, maxPoolHeight, labelPix, null ));
public void run(ImagePlus image, Roi[] rois) { w = image.getWidth(); h = image.getHeight(); ImageStack stack = new ImageStack(w, h); int firstIndex = -1, lastIndex = -1; for(int i = 1; i < rois.length; i++) { IJ.error("There must be at least one selection in order to interpolate."); return; ByteProcessor bp = new ByteProcessor(w, h); if(rois[i] != null) { bp.copyBits(rois[i].getMask(), rois[i].getBounds().x, rois[i].getBounds().y, ij.process.Blitter.ADD); stack.addSlice("", bp); ImagePlus roiImage = new ImagePlus("bla", stack); ImageProcessor bp = stack.getProcessor(1); stack.deleteSlice(1); int threshold = 255; bp.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE); ts.run(bp); rois[i] = roiImage.getRoi();
if( colourImage.getType() != ImagePlus.COLOR_RGB ) { return null; int depth = colourImage.getStackSize(); int width = colourImage.getWidth(); int height = colourImage.getHeight(); Calibration calibration = colourImage.getCalibration(); ImageStack stack=colourImage.getStack(); ImageStack luminanceStack=new ImageStack(width,height); byte [][] luminancePixels = new byte[depth][]; for( int z = 0; z < depth; ++z ) { int [] intPixels = (int[])stack.getPixels(z+1); luminancePixels[z] = new byte[width*height]; int valuesInSlice = intPixels.length; luminancePixels[z][i] = (byte)luminance; ByteProcessor bp = new ByteProcessor(width,height); bp.setPixels(luminancePixels[z]); luminanceStack.addSlice("", bp); IJ.showProgress( z / (float)depth ); ImagePlus result = new ImagePlus("luminance of "+colourImage.getTitle(),luminanceStack); result.setCalibration(calibration); IJ.showProgress(1.0); return result;
public ImagePlus dilate(ImagePlus image, int threshold, boolean newWin){ w = image.getWidth(); h = image.getHeight(); d = image.getStackSize(); pixels_in[z] = (byte[])image.getStack().getPixels(z+1); pixels_out[z] = new byte[w*h]; IJ.showProgress(z, d-1); for(int y = 0; y < h; y++) { for(int x = 0; x < w; x++) { ColorModel cm = image.getStack().getColorModel(); ImageStack stack = new ImageStack(w, h); for(int z = 0; z < d; z++) { stack.addSlice("", new ByteProcessor( w, h, pixels_out[z], cm));
public static ImagePlus rebin(ImagePlus imp, float min, float max, int nbins) { float delta = (max - min) / nbins; int w = imp.getWidth(), h = imp.getHeight(); int d = imp.getStackSize(); ImageStack res = new ImageStack(w, h); for(int z = 0; z < d; z++) { float[] f = (float[])imp.getStack().getProcessor(z+1). getPixels(); byte[] b = new byte[w*h]; for(int i = 0; i < w*h; i++) { b[i] = (byte)((f[i] - min) / delta); } res.addSlice("", new ByteProcessor(w, h, b, null)); } ImagePlus result = new ImagePlus("Rebinned", res); result.setCalibration(imp.getCalibration()); return result; }
@Test public final void testDistanceMap_UntilCorners_CityBlock() { ByteProcessor image = new ByteProcessor(7, 7); image.setValue(255); image.fill(); image.set(4, 4, 0); short[] weights = ChamferWeights.CITY_BLOCK.getShortWeights(); DistanceTransform3x3Short algo = new DistanceTransform3x3Short(weights, false); ImageProcessor result = algo.distanceMap(image); assertNotNull(result); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(8, result.get(0, 0)); assertEquals(6, result.get(6, 0)); assertEquals(6, result.get(0, 6)); assertEquals(4, result.get(6, 6)); }
if (ip==null) return; int width = ip.getWidth(); int height = ip.getHeight(); if (width!=2 || height<3) { IJ.showMessage("XY Reader", "Two column text file required"); return; double length = 0.0; for (int i=0; i<height; i++) { x[i] = ip.getf(0, i); y[i] = ip.getf(1, i); if ((int)x[i]!=x[i] || (int)y[i]!=y[i]) Rectangle r = roi.getBoundingRect(); ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null || imp.getWidth()<r.x+r.width || imp.getHeight()<r.y+r.height) { new ImagePlus(tr.getName(), new ByteProcessor(Math.abs(r.x)+r.width+10, Math.abs(r.y)+r.height+10)).show(); imp = WindowManager.getCurrentImage();
frameHeight = pp.height - (topMargin + bottomMargin); boolean isColored = isColored(); //color, not grayscale required? if (ip == null || pp.width != ip.getWidth() || pp.height != ip.getHeight() || (isColored != (ip instanceof ColorProcessor))) { if (isColored) { ip = new ColorProcessor(pp.width, pp.height); } else { ip = new ByteProcessor(pp.width, pp.height); invertedLut = Prefs.useInvertingLut && !Interpreter.isBatchMode() && IJ.getInstance()!=null; if (invertedLut) ip.invertLut(); if (imp != null) imp.setProcessor(ip);
/** * Returns the part of the original picture which * belongs to the specified class * * @param classlabel id number of the class * @param label title for the new image * @return New image of the particle(s) in the given class */ public ImagePlus imageForClass(int classlabel, String label){ ImageStack stack = new ImageStack(w,h); for(int d=1;d<=z;d++){ int[] result_pixels = (int[])result.getStack().getProcessor(d). getPixels(); byte[] new_pixels = new byte[result_pixels.length]; for(int i=0;i<result_pixels.length;i++){ new_pixels[i] = result_pixels[i] == classlabel ? (byte)255 : (byte)0; } stack.addSlice("", new ByteProcessor(w,h,new_pixels,null)); } if(label == null || label.trim().equals("")) label = "Class " + classlabel; ImagePlus tmp = new ImagePlus(label, stack); tmp.setCalibration(result.getCalibration()); return tmp; }
/** 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; }
if (ip.getWidth()!=imageWidth || ip.getHeight()!=imageHeight) ip = ip.resize(imageWidth, imageHeight); IJ.redirectErrorMessages(false); return ip; } else { 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;
public void openRoi(String dir, String name) throws IOException { String path = dir+name; RoiDecoder rd = new RoiDecoder(path); Roi roi = rd.getRoi(); Rectangle r = roi.getBounds(); ImagePlus img = WindowManager.getCurrentImage(); if (img==null || img.getWidth()<(r.x+r.width) || img.getHeight()<(r.y+r.height)) { ImageProcessor ip = new ByteProcessor(r.x+r.width+10, r.y+r.height+10); img = new ImagePlus(name, ip); img.show(); } img.setRoi(roi); }
public ImagePlus getResultAsByteImage() { ImageStack stack = new ImageStack(w, h); for(int d = 0; d < z; d++) { int[] p = (int[])result.getStack().getPixels(d+1); byte[] b = new byte[w*h]; for(int i = 0; i < b.length; i++) { if(p[i] == -1) b[i] = (byte)255; else b[i] = (byte)p[i]; } stack.addSlice("", new ByteProcessor(w, h, b, null)); } ImagePlus res = new ImagePlus("Classified", stack); res.setCalibration(image.getCalibration()); return res; }