Matplotlib plotting axes / numpy array ordering

Issue #36 new
Sam Preston created an issue

Jacob, Caleb and I have discussed this some, but I thought this should be an issue so that we can decide on the best solution and resolve it. Matplotlib displays data with axes that match array coordinates -- the first dimension (rows) is vertical and the second dimension (columns) is horizontal. This is the opposite of what we expect in graphics, where the first dimension (x) is horizontal, and the second (y) is vertical.

We don't normally notice this as we always read in .pngs using matplotlib's imread function, which (I've discovered after some testing) reads in an image in these transposed coordinates so that it displays as expected -- for example, if you read in a 128x64 png, the resulting array has shape (64,128). I'm working on enabling the reading of 2D images using ITK's functions, and if we read in a .png using this function and display it, it will be transposed. Also, all medical data we display actually has the axis of the fastest-changing coordinate displayed vertically.

My recommendation is to have common.ReadPNGImage transpose the image read with imread before returning it, and have display.DispImage transpose the displayed image by default. This should display all images as expected, with fastest-changing coordinate displayed horizontally, and images read in by common.ReadITKImage and common.ReadPNGImage will match.

Comments (1)

  1. Jacob Hinkle

    Yes I think the things to preserve are

    • Being able to load PNGs using matplotlib and ImFromNumpyArr
    • Plotting of those PNGs should look fine
    • Loading a PNG using ITK should be the same as loading with matplotlib.

    Hopefully these aren't contradictory, but if they are I think the main thing to preserve is that PNGs get loaded and displayed in PyCA as expected without the user thinking twice about it.

  2. Log in to comment