I was successful in getting the examples to run directly from python. I'm having a bit of trouble with inheritance issues, however... I have one .py file for reading in the file and file header info, and one .py file for using this information to create the image. The code for processing the data to create the image is as follows:
"""
echogram.py
"""
import sys
import pyqtgraph as pg
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import numpy as np
from fileheader import FileHeader, Frame
class QEchogram(QObject):
def __init__(self):
super(QEchogram, self).__init__()
self.__colorTable=[]
self.colorTable=None
self.threshold=[50,255]
self.painter=None
self.image=None
self._fileHeader = None
def initFromFile(self, filename):
self._fileHeader=FileHeader(filename)
def processEchogram(self):
fileHeader = self._fileHeader
frame=Frame(Fileheader.infile)
echoData=frame.data
#fileName = fileName
self.size=[echoData.shape[0],echoData.shape[1]]
# define the size of the data (and resulting image)
#size = [96, 512]
# create a color table for our image
# first define the colors as RGB triplets
colorTable = [(255,255,255),
(159,159,159),
(95,95,95),
(0,0,255),
(0,0,127),
(0,191,0),
(0,127,0),
(255,255,0),
(255,127,0),
(255,0,191),
(255,0,0),
(166,83,60),
(120,60,40),
(200,200,200)]
# then create a color table for Qt - this encodes the color table
# into a list of 32bit integers (4 bytes) where each byte is the
# red, green, blue and alpha 8 bit values. In this case we don't
# set alpha so it defaults to 255 (opaque)
ctLength = len(colorTable)
self.__ctLength=ctLength
__colorTable = []
for c in colorTable:
__colorTable.append(QColor(c[0],c[1],c[2]).rgb())
echoData = np.round((echoData - self.threshold[0])*(float(self.__ctLength)/(self.threshold[1]-self.threshold[0])))
echoData[echoData < 0] = 0
echoData[echoData > self.__ctLength-1] = self.__ctLength-1
echoData = echoData.astype(np.uint8)
self.data=echoData
# create an image from our numpy data
image = QImage(echoData.data, echoData.shape[1], echoData.shape[0], echoData.shape[1],
QImage.Format_Indexed8)
image.setColorTable(__colorTable)
# convert to ARGB
image = image.convertToFormat(QImage.Format_ARGB32)
# save the image to file
image.save('test.png')
self.image=QImage(self.size[0],self.size[1],QImage.Format_ARGB32)
self.painter=QPainter(self.image)
self.painter.drawImage(QRect(0.0,0.0,self.size[0],self.size[1]),image)
self.painter.end()
def getData(self):
return self.data
def getImage(self):
return self.image
def getPixmap(self):
return QPixmap.fromImage(self.image)
When I try and use this for anything, I get a "FileHeader has no attribute infile" error. I'm trying to keep things in separate programs for brevity's sake, so I'm trying to figure out how to create a third file for the actual widgets and displaying of images. I'm quite new at all of this and get tangled up in inheritance stuff...any pointers?