microscope-cockpit / cockpit

Cockpit is a microscope graphical user interface. It is a flexible and easy to extend platform aimed at life scientists using bespoke microscopes.
https://microscope-cockpit.org
GNU General Public License v3.0
37 stars 27 forks source link

View last image stretches non-square images. #884

Open iandobbie opened 1 year ago

iandobbie commented 1 year ago

The view last image function brings up the image viewer and non-square images are stretched oddly.

The data is correct and hovering the mouse returns the correct pixel locations but it is as though the image is rectangular, but the pixel themselves are stretch to be rectangular so the non-square aspect is effectively doubled. All a bit strange.

iandobbie commented 1 year ago
Screen Shot 2023-10-17 at 10 55 10 AM

An example of a tall thin ROI on a simulated camera saved and then reopened with file:open. The left is the stretched image the right is the original snap, both are tall and thin but the reopened image is obviously extended in the y direction.

iandobbie commented 8 months ago

Trying to trace this and not totally got to the bottom of it but it something to do with how the viewport is scaled across the canvas. If I create a square canvas by changing the imageSequenceViewer code to make size (around line 87)

                size = (max(self.images.shape[-1], self.images.shape[-2]),
                        max(self.images.shape[-1], self.images.shape[-2])+ 40) )

This totally solves the problem. So I assume that the openGL drawing code I assume something in the viewCanvas code onPaint function about line 890

            glViewport(0, 0, self.w, self.h)
            glMatrixMode (GL_PROJECTION)
            glPushMatrix()
            glLoadIdentity ()
            glOrtho (0, self.w, 0, self.h, 1., -1.)

The previous code made a canvas that was shaped to the image. I think either the viewport or the ortho projection code effectively scales the pixels again to stretch the individual pixels to the same aspect ratio as the image as a whole, rather than leaving them square. If the canvas is square (with the hack above) the self.w and self.h are equal and the pixels are square.

iandobbie commented 8 months ago

I have pushed the fix above that creates a square canvas. Fixes the issue but in an ugly way.