1 package ij.plugin.filter;
6 import java.awt.event.*;
7 import java.util.Locale;
8 import ij.measure.Calibration;
12 static final int NANOMETER=0, MICROMETER=1, MILLIMETER=2, CENTIMETER=3,
13 METER=4, KILOMETER=5, INCH=6, FOOT=7, MILE=8, PIXEL=9, OTHER_UNIT=10;
24 public void run(ImageProcessor ip) {
30 oldUnitIndex = getUnitIndex(cal.
getUnit());
31 oldUnitsPerCm = getUnitsPerCm(oldUnitIndex);
32 GenericDialog gd =
new ImagePropertiesDialog(imp.
getTitle(),
this);
33 gd.addStringField(
"Unit of Length:", cal.
getUnit());
35 gd.addNumericField(
"Pixels/Unit:", oldScale, (
int)oldScale==oldScale?0:3);
41 gd.addNumericField(
"Frames per Second:", fps, (
int)fps==fps?0:2); }
45 String unit = gd.getNextString();
46 if (unit.equals(
"um"))
47 unit =
IJ.micronSymbol +
"m";
48 else if (unit.equals(
"u"))
49 unit =
"" +
IJ.micronSymbol;
50 else if (unit.equals(
"A"))
51 unit =
""+
IJ.angstromSymbol;
52 double resolution = gd.getNextNumber();
53 if (unit.equals(
"")||unit.equalsIgnoreCase(
"pixel")
54 ||unit.equalsIgnoreCase(
"none")||resolution==0.0) {
64 double spacing = gd.getNextNumber();
65 double fps = gd.getNextNumber();
75 double getNewScale(String newUnit) {
76 if (oldUnitsPerCm==0.0)
78 double newScale = 0.0;
79 int newUnitIndex = getUnitIndex(newUnit);
80 if (newUnitIndex!=oldUnitIndex) {
81 double newUnitsPerCm = getUnitsPerCm(newUnitIndex);
82 if (oldUnitsPerCm!=0.0 && newUnitsPerCm!=0.0) {
83 newScale = oldScale * (oldUnitsPerCm/newUnitsPerCm);
89 int getUnitIndex(String unit) {
90 unit = unit.toLowerCase(Locale.US);
91 if (unit.equals(
"cm")||unit.startsWith(
"cent"))
93 else if (unit.equals(
"mm")||unit.startsWith(
"milli"))
95 else if (unit.startsWith(
"inch"))
97 else if (unit.startsWith(
""+IJ.micronSymbol)||unit.startsWith(
"u")||unit.startsWith(
"micro"))
99 else if (unit.equals(
"nm")||unit.startsWith(
"nano"))
101 else if (unit.startsWith(
"meter"))
103 else if (unit.equals(
"km")||unit.startsWith(
"kilo"))
105 else if (unit.equals(
"ft")||unit.equals(
"foot")||unit.equals(
"feet"))
107 else if (unit.equals(
"mi")||unit.startsWith(
"mile"))
113 double getUnitsPerCm(
int unitIndex) {
115 case NANOMETER:
return 10000000.0;
116 case MICROMETER:
return 10000.0;
117 case MILLIMETER:
return 10.0;
118 case CENTIMETER:
return 1.0;
119 case METER:
return 0.01;
120 case KILOMETER:
return 0.00001;
121 case INCH:
return 0.3937;
122 case FOOT:
return 0.0328083;
123 case MILE:
return 0.000006213;
130 class ImagePropertiesDialog
extends GenericDialog {
131 ImageProperties iprops;
133 public ImagePropertiesDialog(String title, ImageProperties iprops) {
135 this.iprops = iprops;
138 public void textValueChanged(TextEvent e) {
139 TextField unitField = (TextField)stringField.elementAt(0);
140 if (e.getSource()!=unitField)
142 String newUnit = unitField.getText();
143 TextField ppuField = (TextField)numberField.elementAt(0);
144 double newScale = iprops.getNewScale(newUnit);
146 ppuField.setText(((
int)newScale)==newScale?IJ.d2s(newScale,0):IJ.d2s(newScale,2));
147 iprops.oldUnitIndex = iprops.getUnitIndex(newUnit);
148 iprops.oldUnitsPerCm = iprops.getUnitsPerCm(iprops.oldUnitIndex);
149 iprops.oldScale = newScale;;