Dear @Wayne,
Thanks for getting back to me.
While trying to prove the issue, I realized that the problem was not with the calibration per se but with the xOrigin
, yOrigin
fields and how they are used in the getRawX().
In my mind getRawX()
was supposed to give me a length, but it gives a coordinate, which is obviously affected by the origin. And I was using it to convert from calibrated units to pixels, oblivious of this imporant detail.
img = IJ.createImage("HyperStack", "8-bit color-mode label", 400, 300, 3, 1, 1);
cal = img.getCalibration()
print("GetRawX of 5 from raw: "+cal.getRawX(5.0));
cal.pixelWidth = cal.pixelHeight = cal.pixelDepth = 0.3397663;
cal.setXUnit("um");
cal2 = img.getCalibration();
print("GetRawX of 5 from calibrated: "+cal2.getRawX(5.0));
cal2.xOrigin = 10;
cal2.yOrigin = 45;
print("GetRawX of 5 from calibrated with positive origin: "+cal2.getRawX(5.0));
cal2.xOrigin = -10;
cal2.yOrigin = -45;
print("GetRawX of 5 from calibrated with negative origin: "+cal2.getRawX(5.0));
So everything works as intended! And the error I saw was caused by the image I was working on having a non-zero xOrigin
, yOrigin
Again apologies for the assumption that it was broken.
All the best!
Oli