private ImagePlus makeComposite(ImagePlus imp, FileInfo fi) { int c = imp.getNChannels(); boolean composite = c>1 && fi.description!=null && fi.description.indexOf("mode=")!=-1; if (c>1 && (imp.getOpenAsHyperStack()||composite) && !imp.isComposite() && imp.getType()!=ImagePlus.COLOR_RGB) { int mode = IJ.COLOR; if (fi.description!=null) { if (fi.description.indexOf("mode=composite")!=-1) mode = IJ.COMPOSITE; else if (fi.description.indexOf("mode=gray")!=-1) mode = IJ.GRAYSCALE; } imp = new CompositeImage(imp, mode); } return imp; }
private static ImagePlus optionalMakeComposite( Dataset ds, ImagePlus imp ) { /* * ImageJ 1.x will use a StackWindow *only* if there is more than one channel. * So unfortunately, we cannot consistently return a composite image here. We * have to continue to deliver different data types that require specific case * logic in any handler. */ // NB: ColorTableHarmonizer crashes, if it gets a CompositeImage but the Dataset has no CHANNEL axis. if ( imp.getType() != ImagePlus.COLOR_RGB && imp.getStackSize() > 1 && ds.axis( Axes.CHANNEL ).isPresent() ) return new CompositeImage(imp, CompositeImage.COMPOSITE); return imp; } }
private ImagePlus makeComposite(ImagePlus imp, FileInfo fi) { int c = imp.getNChannels(); boolean composite = c>1 && fi.description!=null && fi.description.indexOf("mode=")!=-1; if (c>1 && (imp.getOpenAsHyperStack()||composite) && !imp.isComposite() && imp.getType()!=ImagePlus.COLOR_RGB) { int mode = IJ.COLOR; if (fi.description!=null) { if (fi.description.indexOf("mode=composite")!=-1) mode = IJ.COMPOSITE; else if (fi.description.indexOf("mode=gray")!=-1) mode = IJ.GRAYSCALE; } imp = new CompositeImage(imp, mode); } return imp; }
void openRGB48(ImagePlus imp) { isRGB48 = false; int stackSize = imp.getStackSize(); imp.setDimensions(3, stackSize/3, 1); imp = new CompositeImage(imp, IJ.COMPOSITE); imp.show(); }
/** Creates a new hyperstack. * @param title image name * @param type "8-bit", "16-bit", "32-bit" or "RGB". May also * contain "white" , "black" (the default), "ramp", "composite-mode", * "color-mode", "grayscale-mode or "label". * @param width image width in pixels * @param height image height in pixels * @param channels number of channels * @param slices number of slices * @param frames number of frames */ public static ImagePlus createImage(String title, String type, int width, int height, int channels, int slices, int frames) { if (type.contains("label")) type += "ramp"; if (!(type.contains("white")||type.contains("ramp"))) type += "black"; ImagePlus imp = IJ.createImage(title, type, width, height, channels*slices*frames); imp.setDimensions(channels, slices, frames); int mode = IJ.COLOR; if (type.contains("composite")) mode = IJ.COMPOSITE; if (type.contains("grayscale")) mode = IJ.GRAYSCALE; if (channels>1 && imp.getBitDepth()!=24) imp = new CompositeImage(imp, mode); imp.setOpenAsHyperStack(true); if (type.contains("label")) HyperStackMaker.labelHyperstack(imp); return imp; }
void openRGB48(ImagePlus imp) { isRGB48 = false; int stackSize = imp.getStackSize(); imp.setDimensions(3, stackSize/3, 1); imp = new CompositeImage(imp, IJ.COMPOSITE); imp.show(); }
/** Creates a new hyperstack. * @param title image name * @param width image width in pixels * @param height image height in pixels * @param channels number of channels * @param slices number of slices * @param frames number of frames * @param bitdepth 8, 16, 32 (float) or 24 (RGB) */ public static ImagePlus createHyperStack(String title, int width, int height, int channels, int slices, int frames, int bitdepth) { ImagePlus imp = createImage(title, width, height, channels*slices*frames, bitdepth); imp.setDimensions(channels, slices, frames); if (channels>1 && bitdepth!=24) imp = new CompositeImage(imp, IJ.COMPOSITE); imp.setOpenAsHyperStack(true); return imp; }
/** Creates a new hyperstack. * @param title image name * @param width image width in pixels * @param height image height in pixels * @param channels number of channels * @param slices number of slices * @param frames number of frames * @param bitdepth 8, 16, 32 (float) or 24 (RGB) */ public static ImagePlus createHyperStack(String title, int width, int height, int channels, int slices, int frames, int bitdepth) { ImagePlus imp = createImage(title, width, height, channels*slices*frames, bitdepth); imp.setDimensions(channels, slices, frames); if (channels>1 && bitdepth!=24) imp = new CompositeImage(imp, IJ.COMPOSITE); imp.setOpenAsHyperStack(true); return imp; }
/** * -- HACK -- * <p> * Workaround for the fact that if there are less than 7 slices in an * ImagePlus, the CompositeImage constructor will convert those slices * to channels. * </p> * <p> * This method will always construct a CompositeImage with the same * dimensions as the input ImagePlus. * </p> */ public static CompositeImage makeComposite(ImagePlus imp, int mode) { // cache the (correct) channel, frame and slice counts final int channels = imp.getNChannels(); final int frames = imp.getNFrames(); final int slices = imp.getNSlices(); // construct the composite image final CompositeImage cmp = new CompositeImage(imp, mode); // reset the correct dimension counts cmp.setDimensions(channels, slices, frames); return cmp; } }
ImagePlus convertRGBToCompositeImage(ImagePlus imp) { ImageWindow win = imp.getWindow(); Point loc = win!=null?win.getLocation():null; ImagePlus imp2 = new CompositeImage(imp, CompositeImage.COMPOSITE); if (loc!=null) ImageWindow.setNextLocation(loc); imp2.show(); imp.hide(); WindowManager.setCurrentWindow(imp2.getWindow()); return imp2; }
return new CompositeImage( imp, CompositeImage.COMPOSITE );
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; }
newimp = I5DResource.convert(newimp,true); } else if (imptype == COMPOSITEIMAGE && newimp.getNChannels() > 1) { newimp = new CompositeImage(newimp); } else { newimp.setOpenAsHyperStack(true);
imp.setCalibration(cal); imp.setDimensions(3, nSlices, 1); CompositeImage ci = new CompositeImage(imp, IJ.GRAYSCALE); ci.show(); imp.hide();
/** Converts an RGB image into a Lab stack. */ public ImagePlus RGBToLab(ImagePlus img) { ColorProcessor cp = (ColorProcessor)img.getProcessor(); ColorSpaceConverter converter = new ColorSpaceConverter(); int[] pixels = (int[])cp.getPixels(); int w = cp.getWidth(); int h = cp.getHeight(); ImageStack stack = new ImageStack(w,h); FloatProcessor L = new FloatProcessor(w,h); FloatProcessor a = new FloatProcessor(w,h); FloatProcessor b = new FloatProcessor(w,h); stack.addSlice("L*",L); stack.addSlice("a*",a); stack.addSlice("b*",b); for (int i=0; i<pixels.length; i++) { double[] values = converter.RGBtoLAB(pixels[i]); L.setf(i,(float)values[0]); a.setf(i,(float)values[1]); b.setf(i,(float)values[2]); } ImagePlus img2 = new ImagePlus("Lab_"+img.getTitle(),stack); CompositeImage img3 = new CompositeImage(img2,IJ.GRAYSCALE); img3.resetDisplayRanges(); return img3; }
/** Converts an RGB image into a Lab stack. */ public ImagePlus RGBToLab(ImagePlus img) { ColorProcessor cp = (ColorProcessor)img.getProcessor(); ColorSpaceConverter converter = new ColorSpaceConverter(); int[] pixels = (int[])cp.getPixels(); int w = cp.getWidth(); int h = cp.getHeight(); ImageStack stack = new ImageStack(w,h); FloatProcessor L = new FloatProcessor(w,h); FloatProcessor a = new FloatProcessor(w,h); FloatProcessor b = new FloatProcessor(w,h); stack.addSlice("L*",L); stack.addSlice("a*",a); stack.addSlice("b*",b); for (int i=0; i<pixels.length; i++) { double[] values = converter.RGBtoLAB(pixels[i]); L.setf(i,(float)values[0]); a.setf(i,(float)values[1]); b.setf(i,(float)values[2]); } ImagePlus img2 = new ImagePlus("Lab_"+img.getTitle(),stack); CompositeImage img3 = new CompositeImage(img2,IJ.GRAYSCALE); img3.resetDisplayRanges(); return img3; }
imp2.setDimensions(3, n/3, 1); int mode = CompositeImage.COMPOSITE; imp2 = new CompositeImage(imp2, mode); if (loc!=null) ImageWindow.setNextLocation(loc); imp2.show();
imp3.setDimensions(dim1[2],dim1[3],dim1[4]); if (imp1.isComposite()) { imp3 = new CompositeImage(imp3, imp1.getCompositeMode()); imp3.setDimensions(dim1[2],dim1[3],dim1[4]);
if (imp2!=imp) { if (imp.isComposite()) { imp2 = new CompositeImage(imp2, ((CompositeImage)imp).getMode()); ((CompositeImage)imp2).copyLuts(imp); } else