Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
Info.java
1 package ij.plugin.filter;
2 import java.awt.*;
3 import java.util.*;
4 import ij.*;
5 import ij.gui.*;
6 import ij.process.*;
7 import ij.text.*;
8 import ij.measure.*;
9 import ij.io.*;
10 import ij.util.Tools;
11 
13 public class Info implements PlugInFilter {
14  private ImagePlus imp;
15 
16  public int setup(String arg, ImagePlus imp) {
17  this.imp = imp;
18  return DOES_ALL+NO_CHANGES;
19  }
20 
21  public void run(ImageProcessor ip) {
22  String info = getImageInfo(imp, ip);
23  if (info.indexOf("----")>0)
24  showInfo(info, 400, 500);
25  else
26  showInfo(info, 300, 300);
27  }
28 
29  public String getImageInfo(ImagePlus imp, ImageProcessor ip) {
30  String infoProperty = null;
31  if (infoProperty==null)
32  infoProperty = (String)imp.getProperty("Info");
33  String info = getInfo(imp, ip);
34  if (infoProperty!=null)
35  return infoProperty + "\n------------------------\n" + info;
36  else
37  return info;
38 
39  }
40 
41  String getInfo(ImagePlus imp, ImageProcessor ip) {
42  String s = new String("\n");
43  s += "Title: " + imp.getTitle() + "\n";
44  Calibration cal = imp.getCalibration();
45  int digits = imp.getBitDepth()==32?4:0;
46  if (cal.scaled()) {
47  String unit = cal.getUnit();
48  String units = cal.getUnits();
49  s += "Width: "+IJ.d2s(imp.getWidth()*cal.pixelWidth,2)+" " + units+" ("+imp.getWidth()+")\n";
50  s += "Height: "+IJ.d2s(imp.getHeight()*cal.pixelHeight,2)+" " + units+" ("+imp.getHeight()+")\n";
51  double xResolution = 1.0/cal.pixelWidth;
52  double yResolution = 1.0/cal.pixelHeight;
53  int places = Tools.getDecimalPlaces(xResolution, yResolution);
54  if (xResolution==yResolution)
55  s += "Resolution: "+IJ.d2s(xResolution,places) + " pixels per "+unit+"\n";
56  else {
57  s += "X Resolution: "+IJ.d2s(xResolution,places) + " pixels per "+unit+"\n";
58  s += "Y Resolution: "+IJ.d2s(yResolution,places) + " pixels per "+unit+"\n";
59  }
60  } else {
61  s += "Width: " + imp.getWidth() + " pixels\n";
62  s += "Height: " + imp.getHeight() + " pixels\n";
63  }
64  int type = imp.getType();
65  switch (type) {
66  case ImagePlus.GRAY8:
67  s += "Bits per pixel: 8 ";
68  String lut = "LUT";
69  if (imp.getProcessor().isColorLut())
70  lut = "color " + lut;
71  else
72  lut = "grayscale " + lut;
73  if (imp.isInvertedLut())
74  lut = "inverted " + lut;
75  s += "(" + lut + ")\n";
76  break;
77  case ImagePlus.GRAY16: case ImagePlus.GRAY32:
78  if (type==ImagePlus.GRAY16) {
79  ShortProcessor sp = (ShortProcessor)imp.getProcessor();
80  s += "Bits per pixel: 16 (unsigned short)\n";
81  } else
82  s += "Bits per pixel: 32 (float)\n";
83  s += "Display range: ";
84  double min = ip.getMin();
85  double max = ip.getMax();
86  if (cal.calibrated()) {
87  min = cal.getCValue((int)min);
88  max = cal.getCValue((int)max);
89  }
90  s += IJ.d2s(min,digits) + " - " + IJ.d2s(max,digits) + "\n";
91  break;
92  case ImagePlus.COLOR_256:
93  s += "Bits per pixel: 8 (color LUT)\n";
94  break;
95  case ImagePlus.COLOR_RGB:
96  s += "Bits per pixel: 32 (RGB)\n";
97  break;
98  }
99  double interval = cal.frameInterval;
100 
101  if (ip.getMinThreshold()==ip.NO_THRESHOLD)
102  s += "No Threshold\n";
103  else {
104  double lower = ip.getMinThreshold();
105  double upper = ip.getMaxThreshold();
106  int dp = digits;
107  if (cal.calibrated()) {
108  lower = cal.getCValue((int)lower);
109  upper = cal.getCValue((int)upper);
110  dp = cal.isSigned16Bit()?0:4;
111  }
112  s += "Threshold: "+IJ.d2s(lower,dp)+"-"+IJ.d2s(upper,dp)+"\n";
113  }
114  ImageCanvas ic = imp.getCanvas();
115  double mag = ic.getMagnification();
116  if (mag!=1.0)
117  s += "Magnification: " + mag + "\n";
118 
119  if (cal.calibrated()) {
120  s += " \n";
121  int curveFit = cal.getFunction();
122  s += "Calibration Function: ";
123  if (curveFit==Calibration.UNCALIBRATED_OD)
124  s += "Uncalibrated OD\n";
125  else
126  s += CurveFitter.fList[curveFit]+"\n";
127  double[] c = cal.getCoefficients();
128  if (c!=null) {
129  s += " a: "+IJ.d2s(c[0],6)+"\n";
130  s += " b: "+IJ.d2s(c[1],6)+"\n";
131  if (c.length>=3)
132  s += " c: "+IJ.d2s(c[2],6)+"\n";
133  if (c.length>=4)
134  s += " c: "+IJ.d2s(c[3],6)+"\n";
135  if (c.length>=5)
136  s += " c: "+IJ.d2s(c[4],6)+"\n";
137  }
138  s += " Unit: \""+cal.getValueUnit()+"\"\n";
139  } else
140  s += "Uncalibrated\n";
141 
142  FileInfo fi = imp.getOriginalFileInfo();
143  if (fi!=null) {
144  if (fi.directory!=null && fi.fileName!=null) {
145  s += "Path: " + fi.directory + fi.fileName + "\n";
146  }
147  if (fi.url!=null && !fi.url.equals("")) {
148  s += "URL: " + fi.url + "\n";
149  }
150  }
151 
152  Roi roi = imp.getRoi();
153  if (roi == null) {
154  if (cal.calibrated())
155  s += " \n";
156  s += "No Selection\n";
157  } else {
158  s += " \n";
159  s += roi.getTypeAsString()+" Selection";
160  String name = roi.getName();
161  if (name!=null)
162  s += " (\"" + name + "\")";
163  s += "\n";
164  Rectangle r = roi.getBounds();
165  if (roi instanceof Line) {
166  Line line = (Line)roi;
167  s += " X1: " + IJ.d2s(line.x1*cal.pixelWidth) + "\n";
168  s += " Y1: " + IJ.d2s(yy(line.y1,imp)*cal.pixelHeight) + "\n";
169  s += " X2: " + IJ.d2s(line.x2*cal.pixelWidth) + "\n";
170  s += " Y2: " + IJ.d2s(yy(line.y2,imp)*cal.pixelHeight) + "\n";
171 
172  } else if (cal.scaled()) {
173  s += " X: " + IJ.d2s(r.x*cal.pixelWidth) + " (" + r.x + ")\n";
174  s += " Y: " + IJ.d2s(yy(r.y,imp)*cal.pixelHeight) + " (" + r.y + ")\n";
175  s += " Width: " + IJ.d2s(r.width*cal.pixelWidth) + " (" + r.width + ")\n";
176  s += " Height: " + IJ.d2s(r.height*cal.pixelHeight) + " (" + r.height + ")\n";
177  } else {
178  s += " X: " + r.x + "\n";
179  s += " Y: " + yy(r.y,imp) + "\n";
180  s += " Width: " + r.width + "\n";
181  s += " Height: " + r.height + "\n";
182  }
183  }
184 
185  return s;
186  }
187 
188  // returns a Y coordinate based on the "Invert Y Coodinates" flag
189  int yy(int y, ImagePlus imp) {
190  return Analyzer.updateY(y, imp.getHeight());
191  }
192 
193  void showInfo(String info, int width, int height) {
194  new TextWindow("Info for "+imp.getTitle(), info, width, height);
195  }
196 
197 }