Posted by
Alan Brooks on
Jul 02, 2014; 4:59pm
URL: http://imagej.273.s1.nabble.com/Non-Uniform-X-Y-Z-Units-Patch-tp5008492p5008548.html
>> The "Rotate Right", "Rotate Left" and "Show Info" commands in latest ImageJ
>> daily build (1.49d5) support non-uniform units.
>
> This is generally working for me on my data. However it seems to pick the
> number of decimal points to display in an inconsistent manner.
>
> On a data set with time in the x-dimension, pixels in the y-dimension, and
> electronic integrator in the z-dimension, I get the following Image>Show
> Info.. when opening the file:
>
> Width: 65.83 sec (11350)
> Height: 1504.00 dexel (1504)
> Depth: 2.00 integrator (2)
> X Resolution: 172.4138 pixels per sec
> Y Resolution: 1.0000 pixels per dexel
> Voxel size: 0.0058x1.0000x1.0000 (sec x dexel x integrator)
>
> but it changes to the following after rotating by 90 degrees:
>
> Width: 1504 dexel (1504)
> Height: 66 sec (11350)
> Depth: 2 integrator (2)
> X Resolution: 1 pixels per dexel
> Y Resolution: 172 pixels per sec
> Voxel size: 1x0x1 (dexel x sec x integrator)
>
> Perhaps there is a problem with Tools.getDecimalPlaces(double n1, double
> n2)? I couldn't see it upon inspection.
I looked at this problem further and found that the two-input
Tools.getDecimalPlaces() didn't behave as expected if one the units is
a round number with other units as decimals. I developed a minor patch
for this, included inline below.
Also, I realized that it makes more sense for non-uniform units to
treat each number separately when computing significant digits for
display in ImageWindow's subtitle and in the Info command. I developed
a potential patch that does this, inline below.
If you create a sample image with this javascript:
imp = IJ.createImage("Untitled", "8-bit black", 500, 200, 10);
cal = imp.getCalibration();
cal.pixelWidth = 0.0058;
cal.pixelHeight = 1.0;
cal.pixelDepth = 12.3;
cal.setXUnit("sec");
cal.setYUnit("dexel");
cal.setZUnit("mm");
imp.show();
win = imp.getWindow();
print(win.createSubtitle());
The current IJ daily (1.49d6) shows:
1/10; 2.9 sec x 200.0 dexel (500x200); 8-bit; 977K
My patch shows:
1/10; 2.9 sec x 200 dexel (500x200); 8-bit; 977K
Similarly, IJ daily shows the following Info:
Width: 2.9 sec (500)
Height: 200.0 sec (200)
Depth: 123.0 sec (10)
X Resolution: 172.4138 pixels per sec
Y Resolution: 1.0000 pixels per sec
Voxel size: 0.0058x1.0000x12.3000 sec
My patch shows:
Width: 2.9 sec (500)
Height: 200 dexel (200)
Depth: 123 mm (10)
X Resolution: 172.4138 pixels per sec
Y Resolution: 1 pixels per dexel
Voxel size: 0.0058x1x12.3 (sec x dexel x mm)
The patch against 1.49d6 follows
-----------------------------
From dc43859d9abe52403751492f1f3325516ea74ad8 Mon Sep 17 00:00:00 2001
From: Alan Brooks <
[hidden email]>
Date: Wed, 2 Jul 2014 11:34:02 -0500
Subject: [PATCH] For two-input getDecimalPlaces with either input almost an
integer, let the other input determine the format.
---
ij/util/Tools.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/ij/util/Tools.java b/ij/util/Tools.java
index c99c11b..9874402 100644
--- a/ij/util/Tools.java
+++ b/ij/util/Tools.java
@@ -147,7 +147,11 @@ import java.util.Comparator;
return 0;
int digits = getDecimalPlaces(n1);
int digits2 = getDecimalPlaces(n2);
- if (digits<=0 || digits2<=0)
+ if (digits==0)
+ return digits2;
+ if (digits2==0)
+ return digits;
+ if (digits<0 || digits2<0)
return digits;
if (digits2>digits)
digits = digits2;
--
1.8.4.msysgit.0
From 8f4a5a8caf6881b7967cb802306b8e15b1ef94bb Mon Sep 17 00:00:00 2001
From: Alan Brooks <
[hidden email]>
Date: Wed, 2 Jul 2014 11:32:20 -0500
Subject: [PATCH] Separate the handling of display digits to account for
non-uniform units of much different scales.
---
ij/gui/ImageWindow.java | 12 +++++++-----
ij/plugin/filter/Info.java | 31 +++++++++++++++++--------------
2 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/ij/gui/ImageWindow.java b/ij/gui/ImageWindow.java
index d9b47af..e972509 100644
--- a/ij/gui/ImageWindow.java
+++ b/ij/gui/ImageWindow.java
@@ -304,14 +304,16 @@ public class ImageWindow extends Frame
implements FocusListener, WindowListener,
boolean unitsMatch = cal.getXUnit().equals(cal.getYUnit());
double cwidth = imp.getWidth()*cal.pixelWidth;
double cheight = imp.getHeight()*cal.pixelHeight;
- int digits = Tools.getDecimalPlaces(cwidth, cheight);
- if (digits>2) digits=2;
+ int digitsw = Tools.getDecimalPlaces(cwidth);
+ if (digitsw>2) digitsw=2;
+ int digitsh = Tools.getDecimalPlaces(cheight);
+ if (digitsh>2) digitsh=2;
if (unitsMatch) {
- s += IJ.d2s(cwidth,digits) + "x" + IJ.d2s(cheight,digits)
+ s += IJ.d2s(cwidth,digitsw) + "x" + IJ.d2s(cheight,digitsh)
+ " " + cal.getUnits() + " (" + imp.getWidth() + "x" +
imp.getHeight() + "); ";
} else {
- s += IJ.d2s(cwidth,digits) + " " + cal.getXUnit() + " x "
- + IJ.d2s(cheight,digits) + " " + cal.getYUnit()
+ s += IJ.d2s(cwidth,digitsw) + " " + cal.getXUnit() + " x "
+ + IJ.d2s(cheight,digitsh) + " " + cal.getYUnit()
+ " (" + imp.getWidth() + "x" + imp.getHeight() + "); ";
}
} else
diff --git a/ij/plugin/filter/Info.java b/ij/plugin/filter/Info.java
index e6d193a..070db3a 100644
--- a/ij/plugin/filter/Info.java
+++ b/ij/plugin/filter/Info.java
@@ -93,7 +93,7 @@ public class Info implements PlugInFilter {
int slices = imp.getNSlices();
int frames = imp.getNFrames();
int digits = imp.getBitDepth()==32?4:0;
- int dp, dp2;
+ int dpw, dph, dpd;
boolean nonUniformUnits = !cal.getXUnit().equals(cal.getYUnit());
String xunit = cal.getXUnit();
String yunit = cal.getYUnit();
@@ -109,22 +109,24 @@ public class Info implements PlugInFilter {
}
double pw = imp.getWidth()*cal.pixelWidth;
double ph = imp.getHeight()*cal.pixelHeight;
- dp = Tools.getDecimalPlaces(pw, ph);
- s += "Width: "+IJ.d2s(pw,dp)+" " + xunits+" ("+imp.getWidth()+")\n";
- s += "Height: "+IJ.d2s(ph,dp)+" " + yunits+" ("+imp.getHeight()+")\n";
+ dpw = Tools.getDecimalPlaces(pw);
+ dph = Tools.getDecimalPlaces(ph);
+ s += "Width: "+IJ.d2s(pw,dpw)+" " + xunits+" ("+imp.getWidth()+")\n";
+ s += "Height: "+IJ.d2s(ph,dph)+" " + yunits+" ("+imp.getHeight()+")\n";
if (slices>1) {
double pd = slices*cal.pixelDepth;
- dp = Tools.getDecimalPlaces(pw, pd);
- s += "Depth: "+IJ.d2s(pd,dp)+" " + zunits+" ("+slices+")\n";
+ dpd = Tools.getDecimalPlaces(pd);
+ s += "Depth: "+IJ.d2s(pd,dpd)+" " + zunits+" ("+slices+")\n";
}
double xResolution = 1.0/cal.pixelWidth;
double yResolution = 1.0/cal.pixelHeight;
- int places = Tools.getDecimalPlaces(xResolution, yResolution);
+ int placesx = Tools.getDecimalPlaces(xResolution);
+ int placesy = Tools.getDecimalPlaces(yResolution);
if (xResolution==yResolution)
- s += "Resolution: "+IJ.d2s(xResolution,places) + " pixels per
"+xunit+"\n";
+ s += "Resolution: "+IJ.d2s(xResolution,placesx) + " pixels per
"+xunit+"\n";
else {
- s += "X Resolution: "+IJ.d2s(xResolution,places) + " pixels per
"+xunit+"\n";
- s += "Y Resolution: "+IJ.d2s(yResolution,places) + " pixels per
"+yunit+"\n";
+ s += "X Resolution: "+IJ.d2s(xResolution,placesx) + " pixels
per "+xunit+"\n";
+ s += "Y Resolution: "+IJ.d2s(yResolution,placesy) + " pixels
per "+yunit+"\n";
}
} else {
s += "Width: " + imp.getWidth() + " pixels\n";
@@ -132,18 +134,19 @@ public class Info implements PlugInFilter {
if (stackSize>1)
s += "Depth: " + slices + " pixels\n";
}
+ dpw = Tools.getDecimalPlaces(cal.pixelWidth);
+ dph = Tools.getDecimalPlaces(cal.pixelHeight);
if (stackSize>1) {
String vunit = cal.getUnit()+"^3";
if (nonUniformUnits)
vunit = "("+xunit+" x "+yunit+" x "+zunit+")";
- dp = Tools.getDecimalPlaces(cal.pixelWidth, cal.pixelDepth);
- s += "Voxel size:
"+IJ.d2s(cal.pixelWidth,dp)+"x"+IJ.d2s(cal.pixelHeight,dp)+"x"+IJ.d2s(cal.pixelDepth,dp)+"
"+vunit+"\n";
+ dpd = Tools.getDecimalPlaces(cal.pixelDepth);
+ s += "Voxel size:
"+IJ.d2s(cal.pixelWidth,dpw)+"x"+IJ.d2s(cal.pixelHeight,dph)+"x"+IJ.d2s(cal.pixelDepth,dpd)+"
"+vunit+"\n";
} else {
String punit = cal.getUnit()+"^2";
if (nonUniformUnits)
punit = "("+xunit+" x "+yunit+")";
- dp = Tools.getDecimalPlaces(cal.pixelWidth, cal.pixelHeight);
- s += "Pixel size:
"+IJ.d2s(cal.pixelWidth,dp)+"x"+IJ.d2s(cal.pixelHeight,dp)+"
"+punit+"\n";
+ s += "Pixel size:
"+IJ.d2s(cal.pixelWidth,dpw)+"x"+IJ.d2s(cal.pixelHeight,dph)+"
"+punit+"\n";
}
s += "ID: "+imp.getID()+"\n";
--
1.8.4.msysgit.0
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html