Creating 3D Image from two 2D arrays

504 views
Skip to first unread message

Victoria Price

unread,
Oct 18, 2012, 3:16:54 PM10/18/12
to pyqt...@googlegroups.com
Hello,
So I've plotted the 2D numpy arrays as images beautifully.  I have a master image and a slave image that I'm hoping to combine together into an x,y,z system but I'm not entirely clear on how to do this.  The x and y axis are from the master image and the z coordinate comes from the slave image x coordinate, if that helps.  Any guidance would be appreciated, I'm a bit lost.
Thanks!
Victoria

Luke Campagnola

unread,
Oct 18, 2012, 3:31:15 PM10/18/12
to pyqt...@googlegroups.com
On Thu, Oct 18, 2012 at 3:16 PM, Victoria Price <victoria...@gmail.com> wrote:
So I've plotted the 2D numpy arrays as images beautifully.  I have a master image and a slave image that I'm hoping to combine together into an x,y,z system but I'm not entirely clear on how to do this.  The x and y axis are from the master image and the z coordinate comes from the slave image x coordinate, if that helps.  Any guidance would be appreciated, I'm a bit lost.

So you have 2 images; one in the x,y plane and one in the z,y plane. 
How exactly do you want to visualize this? 
Perhaps two image planes in a 3D view, like panel B in this image: http://c431376.r76.cf2.rackcdn.com/344/fninf-03-009/image_m/fninf-03-009-g005.jpg   ?

Luke

Victoria Price

unread,
Oct 18, 2012, 3:52:31 PM10/18/12
to pyqt...@googlegroups.com
Yes, that's exactly what I'm thinking!  Thank you for articulating that for me.  What is the best way to go about doing this? 

Luke Campagnola

unread,
Oct 18, 2012, 4:50:08 PM10/18/12
to pyqt...@googlegroups.com
We'll need a GLImageItem class for that. 
Should be very easy to put together.. I'll include one in the next release (probably tonight).

Luke Campagnola

unread,
Oct 19, 2012, 10:39:41 AM10/19/12
to pyqt...@googlegroups.com
Have a look at the latest revision, particularly examples/GLImageItem.py

Victoria Price

unread,
Oct 19, 2012, 12:12:12 PM10/19/12
to pyqt...@googlegroups.com
Those are excellent, thank you.  One question I have is, since I'm deriving the Z coordinate from a different data array, how to I merge the two to create the xz/yz planes? 

The arrays are 96x512... so would the shape be (96,512,96)?  

Luke Campagnola

unread,
Oct 19, 2012, 12:16:22 PM10/19/12
to pyqt...@googlegroups.com
On Fri, Oct 19, 2012 at 12:12 PM, Victoria Price <victoria...@gmail.com> wrote:
Those are excellent, thank you.  One question I have is, since I'm deriving the Z coordinate from a different data array, how to I merge the two to create the xz/yz planes? 

The arrays are 96x512... so would the shape be (96,512,96)?  

In the example, I use 2D slices taken from a 3D data set so that the images on the slice planes will match where they intersect.
It sounds like you already have two 2D planes selected from what (I presume) was originally a 3D volume, so it's not necessary to try to reconstruct a 3D array--just create one GLImageItem from each array and rotate/position them accordingly.

Victoria Price

unread,
Oct 19, 2012, 2:32:08 PM10/19/12
to pyqt...@googlegroups.com
I've attached the basic code, though it does call modules that I've written to read in the data from the file (and locate the appropriate image data array)...I receive this error:

Traceback (most recent call last):
  File "C:/Users/Tory/Desktop/3DTesting", line 17, in <module>
    image=pg.makeRGBA(frame.data[shape[0]])[0]
IndexError: index out of bounds

Am I on the right track?
Thank you again for all of your help!

Edit:  it seems to not want to let me attach a file...

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from fileheader import FileHeader, Frame
import pyqtgraph as pg
import pyqtgraph.opengl as gl
from scipy import ndimage
import sys,os

filename="C:/Users/Tory/Desktop/PYTHON NOAA/test.ddf"
slaveFilename="C:/Users/Tory/Desktop/PYTHON NOAA/test.ddf"
fileheader=FileHeader(filename)
frame=fileheader.frameAtIndex(1)
slaveFileHeader=FileHeader(slaveFilename)
slaveFrame=slaveFileHeader.frameAtIndex(1)

shape=(96,512)
image=pg.makeRGBA(frame.data[shape[0]])[0]
slaveImage=pg.makeRGBA(slaveFrame.data[shape[1]])[0]

app=QApplication([])
w = gl.GLViewWidget()

w.show()

v1=gl.GLImageItem(image)
v1.translate(-shape[1],-shape[2])
w.addItem(v1)

v2=gl.GLImageItem(slaveImage)
v2.translate(-shape[0],-shape[2])
w.addItem(v2)

if sys.flags.interactive !=1:
    app.exec_()

Luke Campagnola

unread,
Oct 19, 2012, 3:34:02 PM10/19/12
to pyqt...@googlegroups.com
If 'frame.data' is a 2D array and 'shape' is the shape of that array, then one would expect the expression 'frame.data[shape[0]]' to generate this error.


-- [ You are subscribed to pyqt...@googlegroups.com. To unsubscribe, send email to pyqtgraph+...@googlegroups.com ]

Reply all
Reply to author
Forward
0 new messages