ImageJ 1.52r issues with ImagePlus Calibration

Pinging @Wayne for this one I guess.

I have noticed an issue with the calibration on some images.


No matter what I try to set in the Calibration API

    image.getCalibration().pixelHeight = image.getCalibration().pixelWidth;

It does not change anymore…

This feature seems broken as it is not backwards compatible apparently…
I am sticking to version 1.52p for now.




Please provide an image and minimal script that we can use to reproduce this problem. This script works as expected.

  img = IJ.createImage("HyperStack", "8-bit color-mode label", 400, 300, 3, 1, 1);, "Properties...", "");
  cal = img.getCalibration();
  cal.pixelWidth = cal.pixelHeight = cal.pixelDepth = 0.3397663;
  cal.setXUnit("um");, "Properties...", "");
  cal2 = img.getCalibration();
  print("Pixel width: "+cal2.pixelWidth);
  print("Pixel height: "+cal2.pixelHeight);
  print("Pixel depth: "+cal2.pixelDepth);
  print("X unit: "+cal2.getXUnit());
  print("Y unit: "+cal2.getYUnit());
  print("Z unit: "+cal2.getZUnit());

It displays these two dialogs:

And it displays this text in the Log window:

Pixel width: 0.3397663
Pixel height: 0.3397663
Pixel depth: 0.3397663
X unit: µm
Y unit: µm
Z unit: µm

1 Like

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;


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!