Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uint16 RGB numpy array to Qimage in 48bits #16

Open
dragonlost opened this issue Jul 1, 2019 · 9 comments
Open

uint16 RGB numpy array to Qimage in 48bits #16

dragonlost opened this issue Jul 1, 2019 · 9 comments

Comments

@dragonlost
Copy link

Hello.

I use your lib in my code : https://github.com/gehelem/als (alpha branch).
But i use this lib for astronomic picture. For this, i need visualization in 16bit x3 ( for RGB picture).

currently I do not know if your library manages conversion to qimage 48bits.
In my code i convert in qimage and after i convert qimage to qpixmap.

before i used Opencv for create 48bit tiff picture and i use qpixmap for read this image (but it's slow).

Thanks for help

@dragonlost dragonlost changed the title uint16 RGB numpy array to Qimage in 18bits uint16 RGB numpy array to Qimage in 48bits Jul 1, 2019
@hmeine
Copy link
Owner

hmeine commented Jul 1, 2019

qimage2ndarray only provides a thin, efficient conversion between numpy arrays and QImage.

QImage does not support more than 8 bits per channel (I just checked again, but please correct me if I'm wrong).

One may specify min/max values during conversion, enabling to work with 48 bit data, for instance using QImage for display purposes (limited to 8bit per channel, of course).

@dragonlost
Copy link
Author

actualy on pyqt5.4 he have rgb30 (10-10-10) format and in 5.12 have 2 new format : rgbx64 and rgba64. In pyqt5.13 ( actually in dev branch of pyqt5) you have grayscale8 (pyqt 5.5) and grayscale16 (new).

@dragonlost
Copy link
Author

actually for grayscale 8bit nparray what is the format ? ( grayscale8 ?)
actually for rgb 8bit nparray what is the format ? ( rgb888 ?)

@hmeine
Copy link
Owner

hmeine commented Jul 2, 2019

Thanks for the information! Indeed, then qimage2ndarray needs updating. Should be a rather local change.

hmeine added a commit that referenced this issue Jul 7, 2019
see issue #16:
- collect list of all formats, handle them more consistently
- let core view method support 16 and 64 bit formats as well
@dragonlost
Copy link
Author

On July 5th, Pypi has released the new version of pyqt 5! (5.13). The current version is now compatible with RGBA / RGBX and grayscale 16 bit!

@hmeine
Copy link
Owner

hmeine commented Jul 13, 2019

Thanks for the info. Let me dump my brain here, while I am not able to work on this quickly enough myself:

  • (Relevant basic info) Converting to QImage is built on top of the from QImage functionality; at the core, there's a view method that makes the QImage memory available via an ndarray.
  • Right now, the core method is raw_view(), which creates an ndarray that points to the same memory, with a dtype that has the right bit size. Supported bit sizes are 8 and 32 bits (ok, I just introduced 16 and 64 bit support).
  • There's also byte_view(), which is built on top of raw_view(). byte_view() views the memory as a uint8 block with three dimensions.
  • Supporting 24 or 48 bits would be nice (and what you initially asked for), but that cannot be done by raw_view() currently, because it tries to return a 2D array with a dtype of the right size. I don't think there are built in data types of 24 or 48 bits.
  • Maybe one should make byte_view() the core view function. I could easily support other bit depths.
  • 1-bit images (mono, mono lsb) and other bit packed formats cannot be viewed in general. I would be fine with viewing 1-bit images as uint8 and 16-bit RGB as uint16, requiring the caller to do the bit (un)packing.

@dragonlost
Copy link
Author

Hello
concretely if I have 2 numpy array,

  • in numpy array uint16 to 3 dimention 3x500x500.
  • a numpy array in uint16 with 2 dimensions 500x500.
    How can i use nparray2qimage to convert my 2 numpy to 2 qimage by keeping their 16 bit (under pyq5.13 of course)?

@dragonlost
Copy link
Author

no news ?

@hmeine
Copy link
Owner

hmeine commented Feb 18, 2020

W.r.t. news, you may have noticed that I worked quite a bit on this in the master branch. However, it is much more work than I thought. As indicated above, one needs to first work on the opposite direction. Since qimage2ndarray should not depend on PyQt 5.13+ (in fact, it must not even depend on PyQt), it needs to dynamically detect the availability of higher bit depths. Furthermore, the test suite must run fine with different versions of PyQt, PySide, PythonQt, Qt and Python itself, so we want conditional tests. Any help is appreciated, potentially also with CI (issue #20).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants