byte[] greenArray = new byte[size]; byte[] blueArray = new byte[size]; ((ColorProcessor) image).getRGB(redArray, greenArray, blueArray);
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; }
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; }
/** 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); }
/** Splits the specified RGB stack into three 8-bit grayscale stacks. Deletes the source stack if keepSource is false. */ public static ImageStack[] splitRGB(ImageStack rgb, boolean keepSource) { int w = rgb.getWidth(); int h = rgb.getHeight(); ImageStack[] channels = new ImageStack[3]; for (int i=0; i<3; i++) channels[i] = new ImageStack(w,h); byte[] r,g,b; ColorProcessor cp; int slice = 1; int inc = keepSource?1:0; int n = rgb.getSize(); for (int i=1; i<=n; i++) { IJ.showStatus(i+"/"+n); r = new byte[w*h]; g = new byte[w*h]; b = new byte[w*h]; cp = (ColorProcessor)rgb.getProcessor(slice); slice += inc; cp.getRGB(r,g,b); if (!keepSource) rgb.deleteSlice(1); channels[0].addSlice(null,r); channels[1].addSlice(null,g); channels[2].addSlice(null,b); IJ.showProgress((double)i/n); } return channels; }
byte[] g = new byte[w*h]; byte[] b = new byte[w*h]; ((ColorProcessor)imp.getProcessor()).getRGB(r,g,b); byte[] pixels=null; if (channels==4)
byte[] g = new byte[w*h]; byte[] b = new byte[w*h]; ((ColorProcessor)imp.getProcessor()).getRGB(r,g,b); byte[] pixels=null; if (channels==4)
/** 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); }
/** Splits the specified RGB stack into three 8-bit grayscale stacks. Deletes the source stack if keepSource is false. */ public static ImageStack[] splitRGB(ImageStack rgb, boolean keepSource) { int w = rgb.getWidth(); int h = rgb.getHeight(); ImageStack[] channels = new ImageStack[3]; for (int i=0; i<3; i++) channels[i] = new ImageStack(w,h); byte[] r,g,b; ColorProcessor cp; int slice = 1; int inc = keepSource?1:0; int n = rgb.getSize(); for (int i=1; i<=n; i++) { IJ.showStatus(i+"/"+n); r = new byte[w*h]; g = new byte[w*h]; b = new byte[w*h]; cp = (ColorProcessor)rgb.getProcessor(slice); slice += inc; cp.getRGB(r,g,b); if (!keepSource) rgb.deleteSlice(1); channels[0].addSlice(null,r); channels[1].addSlice(null,g); channels[2].addSlice(null,b); IJ.showProgress((double)i/n); } return channels; }
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; }
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; }
void filterRGB(ImageProcessor ip) { ColorProcessor cp = (ColorProcessor)ip; int width = cp.getWidth(); int height = cp.getHeight(); int size = width*height; byte[] R = new byte[size]; byte[] G = new byte[size]; byte[] B = new byte[size]; IJ.showStatus("Kuwahara_Filter: red"); cp.getRGB(R, G, B); ImageProcessor red = new ByteProcessor(width, height, R, null); filter(red); IJ.showStatus("Kuwahara_Filter: green"); ImageProcessor green = new ByteProcessor(width, height, G, null); filter(green); IJ.showStatus("Kuwahara_Filter: blue"); ImageProcessor blue = new ByteProcessor(width, height, B, null); filter(blue); cp.setRGB((byte[])red.getPixels(), (byte[])green.getPixels(), (byte[])blue.getPixels()); }
/** Performs a convolution operation using the specified kernel. */ public void convolve(float[] kernel, int kernelWidth, int kernelHeight) { int size = width*height; byte[] r = new byte[size]; byte[] g = new byte[size]; byte[] b = new byte[size]; getRGB(r,g,b); ImageProcessor rip = new ByteProcessor(width, height, r, null); ImageProcessor gip = new ByteProcessor(width, height, g, null); ImageProcessor bip = new ByteProcessor(width, height, b, null); ImageProcessor ip2 = rip.convertToFloat(); Rectangle roi = getRoi(); ip2.setRoi(roi); ip2.convolve(kernel, kernelWidth, kernelHeight); ImageProcessor r2 = ip2.convertToByte(false); ip2 = gip.convertToFloat(); ip2.setRoi(roi); ip2.convolve(kernel, kernelWidth, kernelHeight); ImageProcessor g2 = ip2.convertToByte(false); ip2 = bip.convertToFloat(); ip2.setRoi(roi); ip2.convolve(kernel, kernelWidth, kernelHeight); ImageProcessor b2 = ip2.convertToByte(false); setRGB((byte[])r2.getPixels(), (byte[])g2.getPixels(), (byte[])b2.getPixels()); }
/** Performs a convolution operation using the specified kernel. */ public void convolve(float[] kernel, int kernelWidth, int kernelHeight) { int size = width*height; byte[] r = new byte[size]; byte[] g = new byte[size]; byte[] b = new byte[size]; getRGB(r,g,b); ImageProcessor rip = new ByteProcessor(width, height, r, null); ImageProcessor gip = new ByteProcessor(width, height, g, null); ImageProcessor bip = new ByteProcessor(width, height, b, null); ImageProcessor ip2 = rip.convertToFloat(); Rectangle roi = getRoi(); ip2.setRoi(roi); ip2.convolve(kernel, kernelWidth, kernelHeight); ImageProcessor r2 = ip2.convertToByte(false); ip2 = gip.convertToFloat(); ip2.setRoi(roi); ip2.convolve(kernel, kernelWidth, kernelHeight); ImageProcessor g2 = ip2.convertToByte(false); ip2 = bip.convertToFloat(); ip2.setRoi(roi); ip2.convolve(kernel, kernelWidth, kernelHeight); ImageProcessor b2 = ip2.convertToByte(false); setRGB((byte[])r2.getPixels(), (byte[])g2.getPixels(), (byte[])b2.getPixels()); }
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);
final byte[] bluePixels = (byte[]) blueBp.getPixels(); ((ColorProcessor)(originalImage.getProcessor().duplicate())).getRGB(redPixels, greenPixels, bluePixels);
final byte[] bluePixels = (byte[]) blueBp.getPixels(); ((ColorProcessor)(originalImage.getProcessor().duplicate())).getRGB(redPixels, greenPixels, bluePixels);
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; }
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; }
((ColorProcessor)(originalImage.getImageStack().getProcessor( n ).duplicate())).getRGB(redPixels, greenPixels, bluePixels);