Refine search
private void writeFourChannelsWithAlpha(ImagePlus imp, String path) throws Exception { ImageStack stack = imp.getStack(); int w=imp.getWidth(), h=imp.getHeight(); ImagePlus imp2 = new ImagePlus("", new ColorProcessor(w,h)); ColorProcessor cp = (ColorProcessor)imp2.getProcessor(); for (int channel=1; channel<=4; channel++) cp.setChannel(channel, (ByteProcessor)stack.getProcessor(channel)); BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); WritableRaster raster = bi.getRaster(); raster.setDataElements(0, 0, w, h, cp.getPixels()); ImageIO.write(bi, "png", new File(path)); }
private static void fillNoiseRGB(ColorProcessor ip, boolean sp) { int width = ip.getWidth(); int height = ip.getHeight(); ByteProcessor rr = new ByteProcessor(width, height); ByteProcessor gg = new ByteProcessor(width, height); ByteProcessor bb = new ByteProcessor(width, height); if (sp) IJ.showProgress(0.0); rr.add(127); if (sp) IJ.showProgress(0.05); gg.add(127); if (sp) IJ.showProgress(0.10); bb.add(127); if (sp) IJ.showProgress(0.15); rr.noise(31); if (sp) IJ.showProgress(0.40); gg.noise(31); if (sp) IJ.showProgress(0.65); bb.noise(31); if (sp) IJ.showProgress(0.90); if (sp) IJ.showProgress(1.0); ip.setChannel(1,rr); ip.setChannel(2,gg); ip.setChannel(3,bb); }
ImageStack getRGBStack(ImagePlus imp) { ImageProcessor ip = imp.getProcessor(); int w = ip.getWidth(); int h = ip.getHeight(); int size = w*h; byte[] r = new byte[size]; byte[] g = new byte[size]; byte[] b = new byte[size]; ((ColorProcessor)ip).getRGB(r, g, b); ImageStack stack = new ImageStack(w, h); stack.addSlice("Red", r); stack.addSlice("Green", g); stack.addSlice("Blue", b); stack.setColorModel(ip.getDefaultColorModel()); return stack; }
/** Returns a copy of this image as an 8-bit or RGB BufferedImage. * @see ij.process.ShortProcessor#get16BitBufferedImage */ public BufferedImage getBufferedImage() { if (isComposite()) return (new ColorProcessor(getImage())).getBufferedImage(); else return ip.getBufferedImage(); }
void filterIntensity(ImageProcessor ip) { ColorProcessor cp = (ColorProcessor)ip; int width = cp.getWidth(); int height = cp.getHeight(); int size = width*height; byte[] H = new byte[size]; byte[] S = new byte[size]; byte[] B = new byte[size]; cp.getHSB(H, S, B); ImageProcessor ip2 = new ByteProcessor(width, height, B, null); filter(ip2); cp.setHSB(H, S, (byte[])ip2.getPixels()); }
private static ImagePlus convertRGBToComposite(ImagePlus imp) { if (imp.getBitDepth()!=24) throw new IllegalArgumentException("RGB image or stack required"); if (imp.getStackSize()==1) return new CompositeImage(imp, IJ.COMPOSITE); int width = imp.getWidth(); int height = imp.getHeight(); ImageStack stack1 = imp.getStack(); int n = stack1.getSize(); ImageStack stack2 = new ImageStack(width, height); for (int i=0; i<n; i++) { ColorProcessor ip = (ColorProcessor)stack1.getProcessor(1); stack1.deleteSlice(1); byte[] R = new byte[width*height]; byte[] G = new byte[width*height]; byte[] B = new byte[width*height]; ip.getRGB(R, G, B); stack2.addSlice(null, R); stack2.addSlice(null, G); stack2.addSlice(null, B); } n *= 3; ImagePlus imp2 = new ImagePlus(imp.getTitle(), stack2); imp2.setDimensions(3, n/3, 1); imp2 = new CompositeImage(imp2, IJ.COMPOSITE); return imp2; }
public void run(String arg) { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null || imp.getStackSize()==1) { error("Stack required"); return; hyperstack = imp.isHyperStack(); if (hyperstack && imp.getNSlices()>1 && imp.getNFrames()>1) { error("5D hyperstacks are not supported"); return; if (mode==IJ.COMPOSITE) ci.setMode(IJ.COLOR); ImageStack stack = new ImageStack(imp.getWidth(), imp.getHeight()); for (int c=1; c<=channels; c++) { imp.setPosition(c, imp.getSlice(), imp.getFrame()); Image img = imp.getImage(); stack.addSlice(null, new ColorProcessor(img)); imp.updateImage(); saveID = imp.getID(); IJ.register(MontageMaker.class);
ImageProcessor straightenRGB(ImagePlus imp, int width) { int w=imp.getWidth(), h=imp.getHeight(); int size = w*h; byte[] r = new byte[size]; byte[] g = new byte[size]; byte[] b = new byte[size]; ColorProcessor cp = (ColorProcessor)imp.getProcessor(); cp.getRGB(r, g, b); ImagePlus imp2 = new ImagePlus("red", new ByteProcessor(w, h, r, null)); imp2.setRoi((Roi)imp.getRoi().clone()); ImageProcessor red = straightenLine(imp2, width); if (red==null) return null; imp2 = new ImagePlus("green", new ByteProcessor(w, h, g, null)); imp2.setRoi((Roi)imp.getRoi().clone()); ImageProcessor green = straightenLine(imp2, width); if (green==null) return null; imp2 = new ImagePlus("blue", new ByteProcessor(w, h, b, null)); imp2.setRoi((Roi)imp.getRoi().clone()); ImageProcessor blue = straightenLine(imp2, width); if (blue==null) return null; ColorProcessor cp2 = new ColorProcessor(red.getWidth(), red.getHeight()); red = red.convertToByte(false); green = green.convertToByte(false); blue = blue.convertToByte(false); cp2.setRGB((byte[])red.getPixels(), (byte[])green.getPixels(), (byte[])blue.getPixels()); imp.setRoi(imp2.getRoi()); return cp2; }
public void makeTransition(ImagePlus imp, int from, int num) { if(from > imp.getStackSize()) { IJ.error("Need a following slice to which to transit."); return; } num++; // so that really num slices are added ImageStack stack = imp.getStack(); int[] before = (int[])(stack.getProcessor(from). convertToRGB().getPixels()); int[] after = (int[])(stack.getProcessor(from+1). convertToRGB().getPixels()); for(int z = 1; z < num; z++) { ColorProcessor bp = new ColorProcessor( stack.getWidth(), stack.getHeight()); int[] pixels = (int[])bp.getPixels(); double dp = z; double dn = num - z; for(int i = 0; i < pixels.length; i++) { pixels[i] = interpolate( before[i], dp, after[i], dn); } new ImagePlus("slice + " + z, bp).show(); stack.addSlice("", bp, from + z - 1); } }
/** * 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; }
/** Converts an RGB image to an RGB (red, green and blue) stack. */ public void convertToRGBStack() { if (type!=ImagePlus.COLOR_RGB) throw new IllegalArgumentException("Image must be RGB"); //convert to RGB Stack ColorProcessor cp; if (imp.getType()==ImagePlus.COLOR_RGB) cp = (ColorProcessor)imp.getProcessor(); else cp = new ColorProcessor(imp.getImage()); int width = imp.getWidth(); int height = imp.getHeight(); byte[] R = new byte[width*height]; byte[] G = new byte[width*height]; byte[] B = new byte[width*height]; cp.getRGB(R, G, B); imp.trimProcessor(); // Create stack and select Red channel ColorModel cm = LookUpTable.createGrayscaleColorModel(false); ImageStack stack = new ImageStack(width, height, cm); stack.addSlice("Red", R); stack.addSlice("Green", G); stack.addSlice("Blue", B); imp.setStack(null, stack); imp.setDimensions(3, 1, 1); if (imp.isComposite()) ((CompositeImage)imp).setMode(IJ.GRAYSCALE); }
IJ.showStatus("classify..."); MergedClasses mergedClasses = new MergedClasses(); ImageStack resStack = new ImageStack(w,h); for(int d=1;d<=z;d++){ byte[] pixels = (byte[])image.getStack().getProcessor(d).getPixels(); int[] classes = new int[w * h]; int[] classesBefore = d > 1 ? (int[])resStack.getProcessor(d-1).getPixels() : null; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ IJ.showProgress(d,z); resStack.addSlice("",new ColorProcessor(w,h,classes)); ImagePlus tmp = new ImagePlus("Classified", resStack); tmp.setCalibration(image.getCalibration()); return tmp;
/** Converts an RGB or 8-bit color stack to 8-bit grayscale. */ void convertRGBToGray8() { ImageStack stack1 = imp.getStack(); if (stack1 instanceof PlotVirtualStack) { ((PlotVirtualStack)stack1).setBitDepth(8); imp.setStack(stack1); return; } ImageStack stack2 = new ImageStack(width, height); ImageProcessor ip; Image img; String label; int inc = nSlices/20; if (inc<1) inc = 1; for(int i=1; i<=nSlices; i++) { label = stack1.getSliceLabel(1); ip = stack1.getProcessor(1); stack1.deleteSlice(1); if (ip instanceof ByteProcessor) ip = new ColorProcessor(ip.createImage()); boolean scale = ImageConverter.getDoScaling(); stack2.addSlice(label, ip.convertToByte(scale)); if ((i%inc)==0) { IJ.showProgress((double)i/nSlices); IJ.showStatus("Converting to 8-bits: "+i+"/"+nSlices); } } imp.setStack(null, stack2); IJ.showProgress(1.0); }
/** Converts a 2 or 3 slice 8-bit stack to RGB. */ public void convertRGBStackToRGB() { int stackSize = imp.getStackSize(); if (stackSize<2 || stackSize>3 || type!=ImagePlus.GRAY8) throw new IllegalArgumentException("2 or 3 slice 8-bit stack required"); int width = imp.getWidth(); int height = imp.getHeight(); ImageStack stack = imp.getStack(); byte[] R = (byte[])stack.getPixels(1); byte[] G = (byte[])stack.getPixels(2); byte[] B; if (stackSize>2) B = (byte[])stack.getPixels(3); else B = new byte[width*height]; imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setRGB(R, G, B); if (imp.isInvertedLut()) cp.invert(); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }
private ImageStack shrinkZ(ImageStack stack, int zshrink) { int w = stack.getWidth(); int h = stack.getHeight(); int d = stack.getSize(); int d2 = d/zshrink; ImageStack stack2 = new ImageStack (w, h, stack.getColorModel()); for (int z=1; z<=d2; z++) stack2.addSlice(stack.getProcessor(z).duplicate()); boolean rgb = stack.getBitDepth()==24; ImageProcessor ip = rgb?new ColorProcessor(d, h):new FloatProcessor(d, h); for (int x=0; x<w; x++) { IJ.showProgress(x+1, w); for (int y=0; y<h; y++) { float value; for (int z=0; z<d; z++) { value = (float)stack.getVoxel(x, y, z); ip.setf(z, y, value); } } ImageProcessor ip2 = shrink(ip, zshrink, 1, method); for (int x2=0; x2<d2; x2++) { for (int y2=0; y2<h; y2++) { stack2.setVoxel(x, y2, x2, ip2.getf(x2,y2)); } } } return stack2; }
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (!isDataFlavorSupported(flavor)) throw new UnsupportedFlavorException(flavor); ImagePlus imp = WindowManager.getCurrentImage(); if (imp!=null) { imp = flatten(imp); ImageProcessor ip; if (imp.isComposite()) { ip = new ColorProcessor(imp.getImage()); ip.setRoi(imp.getRoi()); } else ip = imp.getProcessor(); ip = ip.crop(); int w = ip.getWidth(); int h = ip.getHeight(); IJ.showStatus(w+"x"+h+ " image copied to system clipboard"); Image img = IJ.getInstance().createImage(w, h); Graphics g = img.getGraphics(); g.drawImage(ip.createImage(), 0, 0, null); g.dispose(); return img; } else { //IJ.noImage(); return null; } }
final int width = originalImage.getWidth(); final int height = originalImage.getHeight(); ImagePlus[] channels; if( originalImage.getType() == ImagePlus.COLOR_RGB ) final ByteProcessor redBp = new ByteProcessor(width, height); final ByteProcessor greenBp = new ByteProcessor(width, height); final ByteProcessor blueBp = new ByteProcessor(width, height); final byte[] redPixels = (byte[]) redBp.getPixels(); final byte[] bluePixels = (byte[]) blueBp.getPixels(); ((ColorProcessor)(originalImage.getProcessor().duplicate())).getRGB(redPixels, greenPixels, bluePixels); channels = new ImagePlus[]{new ImagePlus("red", redBp.convertToFloat()), channels[0] = new ImagePlus(originalImage.getTitle(), originalImage.getProcessor().duplicate().convertToFloat() );
/** Converts a 3-slice (hue, saturation, brightness) 8-bit stack to RGB. */ public void convertHSBToRGB() { if (imp.getStackSize()!=3) throw new IllegalArgumentException("3-slice 8-bit stack required"); ImageStack stack = imp.getStack(); byte[] H = (byte[])stack.getPixels(1); byte[] S = (byte[])stack.getPixels(2); byte[] B = (byte[])stack.getPixels(3); int width = imp.getWidth(); int height = imp.getHeight(); imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setHSB(H, S, B); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }
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);