User Tools

Site Tools


documents:101029imagej_cui_lifconversion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
documents:101029imagej_cui_lifconversion [2010/10/29 15:54] – added macro kotadocuments:101029imagej_cui_lifconversion [2020/11/26 09:11] (current) – external edit 127.0.0.1
Line 67: Line 67:
 </sxh> </sxh>
  
 +===== ImpProps.java =====
 +
 +Accessing Image Physical Properties. Compiled class should be copied to the imageJ plugin folder. [[http://rsbweb.nih.gov/ij/plugins/imp-props.html|Original java code]] was modified to access image properties scales and dimensions. 
 +
 +<sxh java>
 +import ij.*;
 +import ij.measure.Calibration;
 +//import java.lang.Double;
 +/**
 + * This simple class can be called from an ImageJ macro via the "call" mechanism to
 + * get and set the (string) properties of the active image (ImagePlus). 
 + *
 + * call("ImpProps.setProperty", "<key>", "<value>");
 + * set property <key> to <value>, returns <value> if successful, 
 + * "" otherwise (no active image)
 + *
 + * call("ImpProps.getProperty", "<key>");
 + * returns value of property <key> if set, "" otherwise (not found or no active image)
 + *
 + * @see    ij.ImagePlus#setProperty
 + * @see    ij.ImagePlus#getProperty
 + *
 + * @author Joachim Wesner
 + * @author Leica Microsystems CMS GmbH
 + * @author joachim.wesner@leica-microsystems.com
 + * @version 2008-3-15
 + 
 + * @author Kota Miura
 + * cmci, embl
 + * added methods for setting image dimension sizes and pixel scales. 
 + * this was done for setting these values in headless mode. 
 + * @version 2010-10-28
 + * This class can be compiled with ImageJ's Plugins>Compile and Run command.
 + */
 +
 +public class ImpProps {
 +
 + //kota
 + public static String getProperties() {
 + ImagePlus imp = WindowManager.getCurrentImage();
 + if (imp == null)
 + return "";
 + Object prop = imp.getProperties();
 + if (prop != null && prop instanceof String)
 + return (String)prop;
 + else
 + return "";
 + }
 +
 + public static String setProperty(String arg1, String arg2) {
 + ImagePlus imp = WindowManager.getCurrentImage();
 + if (imp == null)
 + return "";
 + imp.setProperty(arg1, arg2);
 + imp.updateAndDraw();
 + return arg2;
 + }
 +
 + public static String getProperty(String arg1) {
 + ImagePlus imp = WindowManager.getCurrentImage();
 + if (imp == null)
 + return "";
 + Object prop = imp.getProperty(arg1);
 + if (prop != null && prop instanceof String)
 + return (String)prop;
 + else
 + return "";
 + }
 +
 + //kota
 + public static int setCalibration(String unit, String spixelWidth, String spixelHeight, String spixelDepth){
 + double pixelWidth = java.lang.Double.parseDouble(spixelWidth);
 + double pixelHeight = java.lang.Double.parseDouble(spixelHeight);
 + double pixelDepth = java.lang.Double.parseDouble(spixelDepth);
 + ImagePlus imp = WindowManager.getCurrentImage();
 + if (imp == null)
 + return -1;
 + Calibration cal = imp.getCalibration();
 + cal.setUnit(unit);
 + cal.pixelWidth = pixelWidth;
 + cal.pixelHeight = pixelHeight;
 + cal.pixelDepth = pixelDepth;
 + imp.setCalibration(cal);
 + WindowManager.repaintImageWindows();
 + return 1;
 + }
 +
 + //kota
 + public static int setCalibration(
 + String schannels, String sslices, 
 + String sframes, String unit, 
 + String spixelWidth, String spixelHeight, 
 + String spixelDepth) {
 + int channels = java.lang.Integer.parseInt(schannels);
 + int slices   = java.lang.Integer.parseInt(sslices);
 + int frames   = java.lang.Integer.parseInt(sframes);
 + double pixelWidth  = java.lang.Double.parseDouble(spixelWidth);
 + double pixelHeight = java.lang.Double.parseDouble(spixelHeight);
 + double pixelDepth  = java.lang.Double.parseDouble(spixelDepth);
 +
 + ImagePlus imp = WindowManager.getCurrentImage();
 + if (imp == null)
 + return -1;
 + int stackSize = imp.getImageStackSize();
 + if (channels*slices*frames==stackSize)
 +  imp.setDimensions(channels, slices, frames);
 +  else
 +  IJ.error("Properties", "The product of channels ("+channels+"), slices ("+slices
 +  +")\n and frames ("+frames+") must equal the stack size ("+stackSize+").");
 + Calibration cal = imp.getCalibration();
 + cal.setUnit(unit);
 + //cal.setTimeUnit(IJ.micronSymbol + "sec");
 + cal.pixelWidth = pixelWidth;
 + cal.pixelHeight = pixelHeight;
 + cal.pixelDepth = pixelDepth;
 + imp.setCalibration(cal);
 + WindowManager.repaintImageWindows();
 + return 1;
 + }
 +}
 +</sxh>
 ===== bfconvert help ===== ===== bfconvert help =====
  
-<quote>+<blockquote>
 To convert a file between formats, run: To convert a file between formats, run:
   bfconvert [-debug] [-stitch] [-separate] [-merge] [-expand]   bfconvert [-debug] [-stitch] [-separate] [-merge] [-expand]
Line 113: Line 234:
  
 Each file would have a single image plane. Each file would have a single image plane.
-</quote>+</blockquote>
  
 ===== LifOpenerCUI.ijm ===== ===== LifOpenerCUI.ijm =====
Line 322: Line 443:
 } }
 </code>  </code> 
 +
 +
documents/101029imagej_cui_lifconversion.txt · Last modified: 2020/11/26 09:11 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki