private void updateImp(final ImagePlus imp, final FileInfo fi, final String name, final String directory, final int fileFormat) { imp.changes = false; if (name != null) { fi.fileFormat = fileFormat; fi.fileName = name; fi.directory = directory; // TiffEncoder.IMAGE_START is not visible, just use current value (768) if (fileFormat == FileInfo.TIFF) fi.offset = 768; fi.description = null; imp.setTitle(name); imp.setFileInfo(fi); } }
private void updateImp(FileInfo fi, int fileFormat) { imp.changes = false; if (name!=null) { fi.fileFormat = fileFormat; FileInfo ofi = imp.getOriginalFileInfo(); if (ofi!=null) { if (ofi.openNextName==null) { fi.openNextName = ofi.fileName; fi.openNextDir = ofi.directory; } else { fi.openNextName = ofi.openNextName; fi.openNextDir = ofi.openNextDir ; } } fi.fileName = name; fi.directory = directory; //if (fileFormat==fi.TIFF) // fi.offset = TiffEncoder.IMAGE_START; fi.description = null; imp.setTitle(name); imp.setFileInfo(fi); } }
private void updateImp(FileInfo fi, int fileFormat) { imp.changes = false; if (name!=null) { fi.fileFormat = fileFormat; FileInfo ofi = imp.getOriginalFileInfo(); if (ofi!=null) { if (ofi.openNextName==null) { fi.openNextName = ofi.fileName; fi.openNextDir = ofi.directory; } else { fi.openNextName = ofi.openNextName; fi.openNextDir = ofi.openNextDir ; } } fi.fileName = name; fi.directory = directory; //if (fileFormat==fi.TIFF) // fi.offset = TiffEncoder.IMAGE_START; fi.description = null; imp.setTitle(name); imp.setFileInfo(fi); } }
ImagePlus openJpegOrGif(String dir, String name) { ImagePlus imp = null; Image img = Toolkit.getDefaultToolkit().createImage(dir+name); if (img!=null) { try { imp = new ImagePlus(name, img); } catch (IllegalStateException e) { IJ.error("Opener", e.getMessage()+"\n(Note: IJ cannot open CMYK JPEGs)\n \n"+dir+name); return null; // error loading image } if (imp.getType()==ImagePlus.COLOR_RGB) convertGrayJpegTo8Bits(imp); FileInfo fi = new FileInfo(); fi.fileFormat = fi.GIF_OR_JPG; fi.fileName = name; fi.directory = dir; imp.setFileInfo(fi); } return imp; }
ImagePlus openJpegOrGif(String dir, String name) { ImagePlus imp = null; Image img = Toolkit.getDefaultToolkit().createImage(dir+name); if (img!=null) { try { imp = new ImagePlus(name, img); } catch (IllegalStateException e) { IJ.error("Opener", e.getMessage()+"\n(Note: IJ cannot open CMYK JPEGs)\n \n"+dir+name); return null; // error loading image } if (imp.getType()==ImagePlus.COLOR_RGB) convertGrayJpegTo8Bits(imp); FileInfo fi = new FileInfo(); fi.fileFormat = fi.GIF_OR_JPG; fi.fileName = name; fi.directory = dir; imp.setFileInfo(fi); } return imp; }
static void setMetadata( Dataset ds, ImagePlus imp ) { imp.setOpenAsHyperStack(imp.getNDimensions() > 3); final FileInfo fileInfo = getFileInfo( ds, imp ); imp.setFileInfo(fileInfo); setSliceLabels( imp, fileInfo ); fillInfo(imp, ds.getImgPlus()); }
private ImagePlus[] splitRGBStack(ImagePlus rgb) { Calibration cal = rgb.getCalibration(); FileInfo fi = rgb.getOriginalFileInfo(); RGBStackSplitter splitter = new RGBStackSplitter(); splitter.split(rgb.getStack(), false); rgb.close(); ImagePlus[] ret = new ImagePlus[3]; ret[0] = new ImagePlus(rgb.getTitle(), splitter.red); ret[0].setCalibration(cal); ret[0].setFileInfo(fi); ret[1] = new ImagePlus(rgb.getTitle(), splitter.green); ret[1].setCalibration(cal); ret[1].setFileInfo(fi); ret[2] = new ImagePlus(rgb.getTitle(), splitter.blue); ret[2].setCalibration(cal); ret[2].setFileInfo(fi); return ret; } }
public ImagePlus openWithHandleExtraFileTypes(String path, int[] fileType) { ImagePlus imp = null; if (path.endsWith(".db")) { // skip hidden Thumbs.db files on Windows fileType[0] = CUSTOM; return null; } imp = (ImagePlus)IJ.runPlugIn("HandleExtraFileTypes", path); if (imp==null) return null; FileInfo fi = imp.getOriginalFileInfo(); if (fi==null) { fi = new FileInfo(); fi.width = imp.getWidth(); fi.height = imp.getHeight(); fi.directory = getDir(path); fi.fileName = getName(path); imp.setFileInfo(fi); } if (imp.getWidth()>0 && imp.getHeight()>0) { fileType[0] = CUSTOM; return imp; } else { if (imp.getWidth()==-1) fileType[0] = CUSTOM; // plugin opened image so don't display error return null; } }
/** Returns a new ImagePlus with this image's attributes (e.g. spatial scale), but no image. */ public ImagePlus createImagePlus() { ImagePlus imp2 = new ImagePlus(); imp2.setType(getType()); imp2.setCalibration(getCalibration()); String info = (String)getProperty("Info"); if (info!=null) imp2.setProperty("Info", info); FileInfo fi = getOriginalFileInfo(); if (fi!=null) { fi = (FileInfo)fi.clone(); fi.directory = null; fi.url = null; imp2.setFileInfo(fi); } return imp2; }
/** Returns a new ImagePlus with this image's attributes (e.g. spatial scale), but no image. */ public ImagePlus createImagePlus() { ImagePlus imp2 = new ImagePlus(); imp2.setType(getType()); imp2.setCalibration(getCalibration()); String info = (String)getProperty("Info"); if (info!=null) imp2.setProperty("Info", info); FileInfo fi = getOriginalFileInfo(); if (fi!=null) { fi = (FileInfo)fi.clone(); fi.directory = null; fi.url = null; imp2.setFileInfo(fi); } return imp2; }
/** Copies attributes (name, ID, calibration, path, plot) of the specified image to this image. */ public void copyAttributes(ImagePlus imp) { if (IJ.debugMode) IJ.log("copyAttributes: "+imp.getID()+" "+this.getID()+" "+imp+" "+this); if (imp==null || imp.getWindow()!=null) throw new IllegalArgumentException("Source image is null or displayed"); ID = imp.getID(); setTitle(imp.getTitle()); setCalibration(imp.getCalibration()); FileInfo fi = imp.getOriginalFileInfo(); if (fi!=null) setFileInfo(fi); Object info = imp.getProperty("Info"); if (info!=null) setProperty("Info", imp.getProperty("Info")); Object plot = imp.getProperty(Plot.PROPERTY_KEY); if (plot != null) setProperty(Plot.PROPERTY_KEY, plot); }
/** Copies attributes (name, ID, calibration, path, plot) of the specified image to this image. */ public void copyAttributes(ImagePlus imp) { if (IJ.debugMode) IJ.log("copyAttributes: "+imp.getID()+" "+this.getID()+" "+imp+" "+this); if (imp==null || imp.getWindow()!=null) throw new IllegalArgumentException("Source image is null or displayed"); ID = imp.getID(); setTitle(imp.getTitle()); setCalibration(imp.getCalibration()); FileInfo fi = imp.getOriginalFileInfo(); if (fi!=null) setFileInfo(fi); Object info = imp.getProperty("Info"); if (info!=null) setProperty("Info", imp.getProperty("Info")); Object plot = imp.getProperty(Plot.PROPERTY_KEY); if (plot != null) setProperty(Plot.PROPERTY_KEY, plot); }
/** * This can be used to clone one stack into another. * * @param infileImage * @param target */ private void cloneStack(ImagePlus infileImage, ImagePlus target, boolean hyperStack) { // Now, 'clone' this image plus back to the one implemented // by this plugin. target.setStack(infileImage.getTitle(), infileImage.getStack()); target.setCalibration(infileImage.getCalibration()); Object objInfo = infileImage.getProperty(INFO_PROPERTY); if (objInfo != null) { target.setProperty(INFO_PROPERTY, objInfo); } target.setFileInfo(infileImage.getFileInfo()); if (hyperStack) { target.setDimensions(infileImage.getNChannels(), infileImage.getNSlices(), infileImage.getNFrames()); } target.setOpenAsHyperStack(hyperStack); }
/** Constructs an ImagePlus from a TIFF, BMP, DICOM, FITS, PGM, GIF or JPRG specified by a path or from a TIFF, DICOM, GIF or JPEG specified by a URL. */ public ImagePlus(String pathOrURL) { Opener opener = new Opener(); ImagePlus imp = null; boolean isURL = pathOrURL.indexOf("://")>0; if (isURL) imp = opener.openURL(pathOrURL); else imp = opener.openImage(pathOrURL); if (imp!=null) { if (imp.getStackSize()>1) setStack(imp.getTitle(), imp.getStack()); else setProcessor(imp.getTitle(), imp.getProcessor()); setCalibration(imp.getCalibration()); properties = imp.getProperties(); setFileInfo(imp.getOriginalFileInfo()); setDimensions(imp.getNChannels(), imp.getNSlices(), imp.getNFrames()); setOverlay(imp.getOverlay()); setRoi(imp.getRoi()); if (isURL) this.url = pathOrURL; setID(); } }
private ImagePlus extractZSlice(ImagePlus imp, int zslice) { int width = imp.getWidth(); int height = imp.getHeight(); int channels = imp.getNChannels(); int frames = imp.getNFrames(); FileInfo fileInfo = imp.getOriginalFileInfo(); // create empty stack ImageStack stack2 = new ImageStack(width, height); // create new ImagePlus for selected frame ImagePlus imp2 = new ImagePlus(); imp2.setTitle("Z" + zslice + "-" + imp.getTitle()); // copy slices for (int f = 1; f <= frames; f++) for (int c = 1; c <= channels; c++) { int slice = imp.getStackIndex(c, zslice, f); stack2.addSlice("", imp.getStack().getProcessor(slice)); } imp2.setStack(stack2); imp2.setDimensions(channels, 1, frames); if (channels*frames > 1) imp2.setOpenAsHyperStack(true); imp2.setFileInfo(fileInfo); return imp2; }
/** Reorder the given ImagePlus's stack. */ public static ImagePlus reorder(ImagePlus imp, String origOrder, String newOrder) { ImageStack s = imp.getStack(); ImageStack newStack = new ImageStack(s.getWidth(), s.getHeight()); int z = imp.getNSlices(); int c = imp.getNChannels(); int t = imp.getNFrames(); int stackSize = s.getSize(); for (int i=0; i<stackSize; i++) { int ndx = FormatTools.getReorderedIndex( origOrder, newOrder, z, c, t, stackSize, i); newStack.addSlice(s.getSliceLabel(ndx + 1), s.getProcessor(ndx + 1)); } ImagePlus p = new ImagePlus(imp.getTitle(), newStack); p.setDimensions(c, z, t); p.setCalibration(imp.getCalibration()); p.setFileInfo(imp.getOriginalFileInfo()); return p; }
/** Constructs an ImagePlus from a TIFF, BMP, DICOM, FITS, PGM, GIF or JPRG specified by a path or from a TIFF, DICOM, GIF or JPEG specified by a URL. */ public ImagePlus(String pathOrURL) { Opener opener = new Opener(); ImagePlus imp = null; boolean isURL = pathOrURL.indexOf("://")>0; if (isURL) imp = opener.openURL(pathOrURL); else imp = opener.openImage(pathOrURL); if (imp!=null) { if (imp.getStackSize()>1) setStack(imp.getTitle(), imp.getStack()); else setProcessor(imp.getTitle(), imp.getProcessor()); setCalibration(imp.getCalibration()); properties = imp.getProperties(); setFileInfo(imp.getOriginalFileInfo()); setDimensions(imp.getNChannels(), imp.getNSlices(), imp.getNFrames()); setOverlay(imp.getOverlay()); setRoi(imp.getRoi()); if (isURL) this.url = pathOrURL; setID(); } }
private ImagePlus extractChannel(ImagePlus imp, int channel) { int width = imp.getWidth(); int height = imp.getHeight(); int zslices = imp.getNSlices(); int frames = imp.getNFrames(); FileInfo fileInfo = imp.getOriginalFileInfo(); // create empty stack ImageStack stack2 = new ImageStack(width, height); // create new ImagePlus for selected channel ImagePlus imp2 = new ImagePlus(); imp2.setTitle("C" + channel + "-" + imp.getTitle()); // copy slices for (int t = 1; t <= frames; t++) for (int z = 1; z <= zslices; z++) { int slice = imp.getStackIndex(channel, z, t); stack2.addSlice("", imp.getStack().getProcessor(slice)); } imp2.setStack(stack2); imp2.setDimensions(1, zslices, frames); if (zslices*frames > 1) imp2.setOpenAsHyperStack(true); imp2.setFileInfo(fileInfo); return imp2; }
/** Reorder the given ImagePlus's stack. */ public static ImagePlus reorder(ImagePlus imp, String origOrder, String newOrder) { ImageStack s = imp.getStack(); ImageStack newStack = new ImageStack(s.getWidth(), s.getHeight()); int z = imp.getNSlices(); int c = imp.getNChannels(); int t = imp.getNFrames(); int stackSize = s.getSize(); for (int i=0; i<stackSize; i++) { int ndx = FormatTools.getReorderedIndex( origOrder, newOrder, z, c, t, stackSize, i); newStack.addSlice(s.getSliceLabel(ndx + 1), s.getProcessor(ndx + 1)); } ImagePlus p = new ImagePlus(imp.getTitle(), newStack); p.setDimensions(c, z, t); p.setCalibration(imp.getCalibration()); p.setFileInfo(imp.getOriginalFileInfo()); return p; }
@Override public ImagePlus next() { if (nextFrame == nFrames) return null; final ImageStack oldStack = image.getStack(); final String oldTitle = image.getTitle(); final FileInfo fi = image.getFileInfo(); final ImageStack newStack = new ImageStack(w, h); newStack.setColorModel(oldStack.getColorModel()); for (int j = 0; j < nSlices; j++) { final int index = image.getStackIndex(1, j + 1, nextFrame + 1); Object pixels; if (nChannels > 1) { image.setPositionWithoutUpdate(1, j + 1, nextFrame + 1); pixels = new ColorProcessor(image.getImage()).getPixels(); } else { pixels = oldStack.getPixels(index); } newStack.addSlice(oldStack.getSliceLabel(index), pixels); } final ImagePlus ret = new ImagePlus(oldTitle + " (frame " + nextFrame + ")", newStack); ret.setCalibration(image.getCalibration().copy()); ret.setFileInfo((FileInfo) fi.clone()); nextFrame++; return ret; } }