ij.io.FileInfo Java Examples
The following examples show how to use
ij.io.FileInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FSLoader.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
/** Returns the path where the imp is saved to: the storage folder plus a name. */ public String handlePathlessImage(final ImagePlus imp) { FileInfo fi = imp.getOriginalFileInfo(); if (null == fi) fi = imp.getFileInfo(); if (null == fi.fileName || fi.fileName.equals("")) { fi.fileName = "img_" + System.currentTimeMillis() + ".tif"; } if (!fi.fileName.endsWith(".tif")) fi.fileName += ".tif"; fi.directory = dir_storage; if (imp.getNSlices() > 1) { new FileSaver(imp).saveAsTiffStack(dir_storage + fi.fileName); } else { new FileSaver(imp).saveAsTiff(dir_storage + fi.fileName); } Utils.log2("Saved a copy into the storage folder:\n" + dir_storage + fi.fileName); return dir_storage + fi.fileName; }
Example #2
Source File: Graph_Cut.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
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; }
Example #3
Source File: Graph_Cut.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
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; }
Example #4
Source File: ShollAnalysisDialog.java From SNT with GNU General Public License v3.0 | 5 votes |
public String getOriginalFilename() { final FileInfo originalFileInfo = originalImage.getOriginalFileInfo(); if (originalFileInfo.directory == null) return "[unknown]"; else return new File(originalFileInfo.directory, originalFileInfo.fileName).getAbsolutePath(); }
Example #5
Source File: ShollAnalysisDialog.java From SNT with GNU General Public License v3.0 | 5 votes |
/** * @return the path to save current profile */ private String getExportPath() { if (this.exportPath == null && originalImage != null) { final FileInfo fi = originalImage.getOriginalFileInfo(); if (fi != null && fi.directory != null) this.exportPath = fi.directory; } return this.exportPath; }
Example #6
Source File: Cache.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** Returns null if the ImagePlus was preprocessed or doesn't have an original FileInfo * (which means the image does not come from a file). */ static public final String getPath(final ImagePlus imp) { final FileInfo fi = imp.getOriginalFileInfo(); if (null == fi || Loader.PREPROCESSED == fi.fileFormat) return null; final String dir = fi.directory; if (null == dir) { return fi.url; } return dir + fi.fileName; }
Example #7
Source File: ImageSaver.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** Returns true on success. * <p> * Core functionality adapted from {@code ij.io.FileSaver} class by Wayne Rasband. * </p> */ static public final boolean saveAsZip(final ImagePlus imp, String path) { // safety checks if (null == imp) { Utils.log("Null imp, can't saveAsZip"); return false; } if (!checkPath(path)) return false; // ok, onward: FileInfo fi = imp.getFileInfo(); if (!path.endsWith(".zip")) path = path+".zip"; String name = imp.getTitle(); if (name.endsWith(".zip")) name = name.substring(0,name.length()-4); if (!name.endsWith(".tif")) name = name+".tif"; fi.description = ImageSaver.getDescriptionString(imp, fi); Object info = imp.getProperty("Info"); if (info!=null && (info instanceof String)) fi.info = (String)info; fi.sliceLabels = imp.getStack().getSliceLabels(); try { ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(path)); DataOutputStream out = new DataOutputStream(new BufferedOutputStream(zos)); zos.putNextEntry(new ZipEntry(name)); TiffEncoder te = new TiffEncoder(fi); te.write(out); out.close(); } catch (IOException e) { IJError.print(e); return false; } return true; }
Example #8
Source File: AmiraImporter.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** Returns the array of AreaList or null if the file dialog is canceled. The xo,yo is the pivot of reference. */ static public Collection<AreaList> importAmiraLabels(Layer first_layer, double xo, double yo, final String default_dir) { // open file OpenDialog od = new OpenDialog("Choose Amira Labels File", default_dir, ""); String filename = od.getFileName(); if (null == filename || 0 == filename.length()) return null; String dir = od.getDirectory(); if (IJ.isWindows()) dir = dir.replace('\\', '/'); if (!dir.endsWith("/")) dir += "/"; String path = dir + filename; AmiraMeshDecoder dec = new AmiraMeshDecoder(); if (!dec.open(path)) { YesNoDialog yn = new YesNoDialog("Error", "File was not an Amira labels file.\nChoose another one?"); if (yn.yesPressed()) return importAmiraLabels(first_layer, xo, yo, default_dir); return null; } ImagePlus imp = null; if (dec.isTable()) { Utils.showMessage("Select the other file (the labels)!"); return null; } else { FileInfo fi = new FileInfo(); fi.fileName = filename; fi.directory = dir; imp = new ImagePlus("Amira", dec.getStack()); dec.parameters.setParameters(imp); } return extractAmiraLabels(imp, dec.parameters, first_layer, xo, yo); }
Example #9
Source File: PatchStack.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
public void setFileInfo(FileInfo fi) { Utils.log("PatchStack: can't setFileInfo"); }
Example #10
Source File: PatchStack.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
public FileInfo getFileInfo() { ImagePlus imp = patch[currentSlice-1].getProject().getLoader().fetchImagePlus(patch[currentSlice-1]); return imp.getFileInfo(); }
Example #11
Source File: Loader.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
protected final ImagePlus preProcess(final Patch p, ImagePlus imp, final long image_n_bytes) { if (null == p) return imp; try { final String path = preprocessors.get(p); boolean update = false; if (null != path) { final File f = new File(path); if (!f.exists()) { Utils.log("ERROR: preprocessor script file does NOT exist: " + path); return imp; } else if (!f.canRead()) { Utils.log("ERROR: can NOT read preprocessor script file at: " + path); return imp; } if (null == imp) { imp = new ImagePlus(); // uninitialized: the script may generate its data } else { // Prepare image for pre-processing imp.getProcessor().setMinAndMax(p.getMin(), p.getMax()); // for 8-bit and RGB images, your problem: setting min and max will expand the range. } // Free 10 times the memory taken by the image, as a gross estimate of memory consumption by the script releaseToFit(Math.min(10 * image_n_bytes, MAX_MEMORY / 4)); // Run the script ini.trakem2.scripting.PatchScript.run(p, imp, path); // Update Patch image properties: if (null != imp.getProcessor() && null != imp.getProcessor().getPixels() && imp.getWidth() > 0 && imp.getHeight() > 0) { update = true; } else { Utils.log("ERROR: preprocessor script failed to create a valid image:" + "\n ImageProcessor: " + imp.getProcessor() + "\n pixel array: " + (null == imp.getProcessor() ? null : imp.getProcessor().getPixels()) + "\n width: " + imp.getWidth() + "\n height: " + imp.getHeight()); } } // Now apply the Patch filters, if any final IFilter[] fs = p.getFilters(); if (null != fs && fs.length > 0) { ImageProcessor ip = imp.getProcessor(); for (final IFilter filter : fs) { ip = filter.process(ip); } if (ip != imp.getProcessor()) { imp.setProcessor(ip); } update = true; } // Now apply intensity correction if available update |= mapIntensities(p, imp); if (update) { // 1: Tag the ImagePlus as altered (misuses fileFormat field, which is unused in any case) final FileInfo fi = imp.getOriginalFileInfo(); if (null != fi) fi.fileFormat = Loader.PREPROCESSED; // otherwise, the null original FileInfo is a valid tag by itself in the persistence.Cache // 2: cache cache(p, imp); // 3: update properties of the Patch p.updatePixelProperties(imp); } } catch (final Exception e) { IJError.print(e); } return imp; }
Example #12
Source File: ImageSaver.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** Returns a string containing information about the specified image. */ static public final String getDescriptionString(final ImagePlus imp, final FileInfo fi) { final Calibration cal = imp.getCalibration(); final StringBuilder sb = new StringBuilder(100); sb.append("ImageJ="+ImageJ.VERSION+"\n"); if (fi.nImages>1 && fi.fileType!=FileInfo.RGB48) sb.append("images="+fi.nImages+"\n"); int channels = imp.getNChannels(); if (channels>1) sb.append("channels="+channels+"\n"); int slices = imp.getNSlices(); if (slices>1) sb.append("slices="+slices+"\n"); int frames = imp.getNFrames(); if (frames>1) sb.append("frames="+frames+"\n"); if (fi.unit!=null) sb.append("unit="+fi.unit+"\n"); if (fi.valueUnit!=null && fi.calibrationFunction!=Calibration.CUSTOM) { sb.append("cf="+fi.calibrationFunction+"\n"); if (fi.coefficients!=null) { for (int i=0; i<fi.coefficients.length; i++) sb.append("c"+i+"="+fi.coefficients[i]+"\n"); } sb.append("vunit="+fi.valueUnit+"\n"); if (cal.zeroClip()) sb.append("zeroclip=true\n"); } // get stack z-spacing and fps if (fi.nImages>1) { if (fi.pixelDepth!=0.0 && fi.pixelDepth!=1.0) sb.append("spacing="+fi.pixelDepth+"\n"); if (cal.fps!=0.0) { if ((int)cal.fps==cal.fps) sb.append("fps="+(int)cal.fps+"\n"); else sb.append("fps="+cal.fps+"\n"); } sb.append("loop="+(cal.loop?"true":"false")+"\n"); if (cal.frameInterval!=0.0) { if ((int)cal.frameInterval==cal.frameInterval) sb.append("finterval="+(int)cal.frameInterval+"\n"); else sb.append("finterval="+cal.frameInterval+"\n"); } if (!cal.getTimeUnit().equals("sec")) sb.append("tunit="+cal.getTimeUnit()+"\n"); } // get min and max display values final ImageProcessor ip = imp.getProcessor(); final double min = ip.getMin(); final double max = ip.getMax(); final int type = imp.getType(); final boolean enhancedLut = (type==ImagePlus.GRAY8 || type==ImagePlus.COLOR_256) && (min!=0.0 || max !=255.0); if (enhancedLut || type==ImagePlus.GRAY16 || type==ImagePlus.GRAY32) { sb.append("min="+min+"\n"); sb.append("max="+max+"\n"); } // get non-zero origins if (cal.xOrigin!=0.0) sb.append("xorigin="+cal.xOrigin+"\n"); if (cal.yOrigin!=0.0) sb.append("yorigin="+cal.yOrigin+"\n"); if (cal.zOrigin!=0.0) sb.append("zorigin="+cal.zOrigin+"\n"); if (cal.info!=null && cal.info.length()<=64 && cal.info.indexOf('=')==-1 && cal.info.indexOf('\n')==-1) sb.append("info="+cal.info+"\n"); sb.append((char)0); return new String(sb); }
Example #13
Source File: Utils.java From render with GNU General Public License v2.0 | 3 votes |
/** * Writes a {@link BufferedImage} to the specified {@link OutputStream} using ImageJ's {@link TiffEncoder}. * * @param bufferedImage image to write. * @param outputStream target stream. * * @throws IOException * if any errors occur. */ public static void writeTiffImage(final BufferedImage bufferedImage, final OutputStream outputStream) throws IOException { final ImagePlus ip = new ImagePlus("", bufferedImage); final FileInfo fileInfo = ip.getFileInfo(); final TiffEncoder tiffEncoder = new TiffEncoder(fileInfo); tiffEncoder.write(outputStream); }