creating 3D image from 3D array

73 views
Skip to first unread message

Georges Hb

unread,
Aug 16, 2016, 7:47:07 PM8/16/16
to pyqtgraph
Hello, so I've been trying to play around the 3D image in GLImageItem.py. My goal is to plot a 3D array of shape (r, c, t) with images (1002, 1004, 115) and dtype uint16

In an out-of-the-box solution attempt i checked the data variable in the example shape and type and adjusted to a float 3-dimensional array yet the output is a white image.
The initial image is not white, to get the middle image in the stack one could use the following (excerpt of variable tex3):

>>> data[:,:,shape[2]/2]
array
([[10204, 11500, 11012, ..., 10472, 10020, 11232],
       
[13196, 13024, 13868, ..., 12200, 13252, 12676],
       
[13184, 11932, 13576, ..., 12668, 12256, 13216],
       
...,
       
[14496, 13908, 13652, ..., 13816, 14204, 13384],
       
[14472, 14536, 13900, ..., 13960, 15312, 14460],
       
[15072, 14856, 14984, ..., 15440, 15528, 15888]], dtype=uint16)

>>> data[:,:,shape[2]/2].shape
(1002, 1004)

tex3 = pg.makeRGBA(data[:,:,shape[2]/2], levels=levels)[0] # xy plane
tex3 is in that case an array of shape (1004, ) which is not representative of the xy plane due to [0].. but removing that breaks hell loose..

    |      shape = self.data.shape
   
|  AttributeError: 'tuple' object has no attribute 'shape'
   
|==============================<<
Error while drawing item <pyqtgraph.opengl.items.GLImageItem.GLImageItem object at 0x10e990c30>.


changing to float is done using:
from skimage import img_as_float


Appreciate any help!



Georges Hb

unread,
Aug 16, 2016, 8:23:53 PM8/16/16
to pyqtgraph
upon investigation the [0] simply removes this weird thing (object?) which contains the array.
(array...  [  255,   255,   255, 255]]], dtype=uint8), False)

the trick was not to use float but ubyte:

tex1
= pg.makeRGBA(img_as_ubyte(data[shape[0]/2]))[0]      # yz plane
tex2
= pg.makeRGBA(img_as_ubyte(data[:,shape[1]/2]))[0]     # xz plane
tex3
= pg.makeRGBA(img_as_ubyte(data[:,:,shape[2]/2]))[0]   # xy plane
Reply all
Reply to author
Forward
0 new messages