imagej / ImageJ

Public domain software for processing and analyzing scientific images
http://imagej.org
Other
557 stars 221 forks source link

Inconsistent origin updates #155

Closed bogovicj closed 2 years ago

bogovicj commented 2 years ago

@rasband,

Cropping / duplicating an image sometimes updates the origin metadata, but sometimes does not.

From what I can tell, it does not update the origin when it is set to zeros, but do update it otherwise.

I would expect the origin to always be updated.

To reproduce

Running this macro

run("MRI Stack");
run("Properties...", "channels=1 slices=27 frames=1 pixel_width=1.0000 pixel_height=1.0000 voxel_depth=1.0000 origin=-5,-10,-20");
makeRectangle(51, 67, 84, 100);
run("Duplicate...", "duplicate");
selectWindow("mri-stack-1.tif");
getImageInfo()

sets the image origin to some non-zero value, then crops ("Duplicate"s with an ROI). It logs some output, one line of which is:

Coordinate origin:  -56,-77,-20

This is correct, and what I would expect.

Running this macro (same as above but does not set the origin)

run("MRI Stack");
makeRectangle(51, 67, 84, 100);
run("Duplicate...", "duplicate");
selectWindow("mri-stack-1.tif");
getImageInfo()

also logs some output, one of of which is:

Coordinate origin:  0,0,0

I expect a non-zero origin in this latter situation as well, because the origin when it is opened is 0,0,0

rasband commented 2 years ago

When duplicating a selection, the origin is only updated if it is not set to zero in the source image. You can force it to be updated by setting the x origin to small non-zero value like 0.00001. Here is an example:

run("MRI Stack");
run("Properties...", "origin=0.00001,0,0");
makeRectangle(51, 67, 84, 100);
run("Duplicate...", "duplicate");
selectWindow("mri-stack-1.tif");
getImageInfo();
bogovicj commented 2 years ago

@rasband Why is this the desired behavior? I don't see a downside in always modifying the origin, nor do I see an upside in modifying the origin sometimes but not others.

Doing this workaround in code is one thing, but making users (me) implement this workaround in the UI is quite burdonsome.

rasband commented 2 years ago

Why is this the desired behavior?

This is the way it has always worked and it can't be changed without breaking existing workflows.

odinsbane commented 2 years ago

@rasband

What about changing the origin when an image is scaled? It seems like the origin should be scaled to the destination image pixels. Would that also break workflows?

imagesc-bot commented 2 years ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/is-there-a-way-to-get-the-origin-value-from-an-imageplus/67220/5

NicoKiaru commented 2 years ago

This is the way it has always worked and it can't be changed without breaking existing workflows.

Which ones ? Can we work on these ? Alternatively could other fields be added in the calibration that would behave differently ? A calibrated 3D matrix to specify the location of the image in 3D would be very useful.

rasband commented 2 years ago

The Image>Scale command in the ImageJ 1.53t1 daily build updates the origin.