TheJacksonLaboratory / ezomero

A module with convenience functions for writing Python code that interacts with OMERO.
GNU General Public License v2.0
39 stars 13 forks source link

[BUG] Image orientation change upon upload due to transpose #54

Closed BlanchardMR closed 2 years ago

BlanchardMR commented 2 years ago

Describe the bug Line 183 of _posts.py transposes the image array possibly unnecessarily which causes user to transpose their image before uploading to Omero in order to maintain proper orientation. This may be intended behavior.

 def plane_gen(image, image_sizez, image_sizec, image_sizet):
        for z in range(image_sizez):
            for c in range(image_sizec):
                for t in range(image_sizet):
                    yield image[:, :, z, c, t].T 

The .T should be removed unless there is some other intended behavior.

To Reproduce This behavior should apply to all images uploaded unless XY is of size 1,1.

Expected behavior The image uploaded to Omero should be of the same orientation as the image the user uploaded.

Screenshots Image with transpose removed and not removed. And then overview with tile shown. ROI is Row: 0 Col:1 notTransposed withTranspose overview_context

Desktop (please complete the following information):

Additional context

erickmartins commented 2 years ago
>>> grad = np.linspace(1, 200, 200)
>>> im_grad = np.tile(test, (200, 1))
>>> test_im = np.expand_dims(im_grad, axis=(2, 3, 4))
>>> np.shape(test_im)
(200, 200, 1, 1, 1)
>>> test_im
array([[  1.,   2.,   3., ..., 198., 199., 200.],
       [  1.,   2.,   3., ..., 198., 199., 200.],
       [  1.,   2.,   3., ..., 198., 199., 200.],
       ...,
       [  1.,   2.,   3., ..., 198., 199., 200.],
       [  1.,   2.,   3., ..., 198., 199., 200.],
       [  1.,   2.,   3., ..., 198., 199., 200.]])
>>> ezomero.post_image(conn, test_im, "random image")
>>> ezomero.post_image(conn, test_im, "random image", dim_order='xyzct')

Resulted in:

image @mellertd thoughts? I think it would probably make sense to have images in OMERO "look" like what their arrays in Python do.

BlanchardMR commented 2 years ago

Ah this must be the issue since when you call a frame using omero.getTile it must output as a 2d python array. I had assumed it was of the same orientation as the image but I guess you could argue getTile is doing the flipping.

mellertd commented 2 years ago

This was fine as originally released, not sure where the problem is. It's possible something changed with addition of dim_order. Is the confusion coming from the fact that OMEROs "natural" ordering is xyzct whereas anything numpy is yx ordered (hence the .T)?

BlanchardMR commented 2 years ago

Yeah I think the confusion is primarily that when you call down a tile and probably a plane from Omero the np.array (I did confirm it is a np.array) is in the xy ordering so that if you do-something and then send it back to omero using ezomero.post_image the image will be transposed. I just assumed that the way the array was downloaded should be the same as uploaded. My guess is you guys interface with more yx orderings by the sound of it so maybe best to just keep it this way. It just seemed really weird at the time and caused some hair pulling assuming I had done the rotation somewhere.

erickmartins commented 2 years ago

as a final sanity test, I did

>>> _, pix = ezomero.get_image(conn, 51, dim_order="xyzct")
>>> ezomero.post_image(conn, pix, "test", dim_order="xyzct")

and indeed the new image looks exactly like the original (ID=51). I think it's all behaving as intended. Ordering dimensions is always a pain!

mellertd commented 2 years ago

Closing, since everything is working as intended