Exemplo n.º 1
0
def getPixmap():
    """
    Open an image file and return the filename and the data.

    Return ``None, None`` in case of failure.
    """
    fileTypeList = [
        'Picture Files (*jpg *jpeg *tif *tiff *png)', 'EDF Files (*edf)',
        'EDF Files (*ccd)', 'ADSC Files (*img)', 'EDF Files (*)'
    ]
    fileList, filterUsed = PyMcaFileDialogs.getFileList(
        parent=None,
        filetypelist=fileTypeList,
        message="Please select one object data file",
        mode="OPEN",
        getfilter=True)
    if not fileList:
        return None, None
    fname = fileList[0]
    if filterUsed.split()[0] == "Picture":
        qimage = qt.QImage(fname)
        if qimage.isNull():
            msg = qt.QMessageBox()
            msg.setIcon(qt.QMessageBox.Critical)
            msg.setText("Cannot read file %s as an image" % fname)
            msg.exec()
            return None, None
        return os.path.basename(fname), convertQImageToArray(qimage)
    if filterUsed.split()[0] in ["EDF", "ADSC"]:
        edf = EdfFile.EdfFile(fname)
        data = edf.GetData(0)
        return os.path.basename(fname), data
    return None, None
Exemplo n.º 2
0
def getPixmap():
    """
    Open an image file and return the filename and the data.

    Return ``None, None`` in case of failure.
    """
    fileTypeList = ['Picture Files (*jpg *jpeg *tif *tiff *png)',
                    'EDF Files (*edf)',
                    'EDF Files (*ccd)',
                    'ADSC Files (*img)',
                    'EDF Files (*)']
    fileList, filterUsed = PyMcaFileDialogs.getFileList(
        parent=None,
        filetypelist=fileTypeList,
        message="Please select one object data file",
        mode="OPEN",
        getfilter=True)
    if not fileList:
        return None, None
    fname = fileList[0]
    if filterUsed.split()[0] == "Picture":
        qimage = qt.QImage(fname)
        if qimage.isNull():
            msg = qt.QMessageBox()
            msg.setIcon(qt.QMessageBox.Critical)
            msg.setText("Cannot read file %s as an image" % fname)
            msg.exec_()
            return None, None
        return os.path.basename(fname), convertQImageToArray(qimage)
    if filterUsed.split()[0] in ["EDF", "ADSC"]:
        edf = EdfFile.EdfFile(fname)
        data = edf.GetData(0)
        return os.path.basename(fname), data
    return None, None
Exemplo n.º 3
0
    def testConvertQImageToArray(self):
        """Test conversion of QImage to numpy array"""
        for format_, channels in [
                ('Format_RGB888', 3),  # Native support
                ('Format_ARGB32', 4),  # Native support
                ('Format_RGB32', 3)]:  # Conversion to RGB
            with self.subTest(format_):
                color = numpy.arange(channels)  # RGB(A) values
                qimage = qt.QImage(3, 3, getattr(qt.QImage, format_))
                qimage.fill(qt.QColor(*color))
                image = convertQImageToArray(qimage)

                self.assertEqual(qimage.height(), image.shape[0])
                self.assertEqual(qimage.width(), image.shape[1])
                self.assertEqual(image.shape[2], len(color))
                self.assertTrue(numpy.all(numpy.equal(image, color)))
Exemplo n.º 4
0
    def testConvertQImageToArray(self):
        """Test conversion of QImage to numpy array"""
        for format_, channels in [
            ('Format_RGB888', 3),  # Native support
            ('Format_ARGB32', 4),  # Native support
            ('Format_RGB32', 3)
        ]:  # Conversion to RGB
            with self.subTest(format_):
                color = numpy.arange(channels)  # RGB(A) values
                qimage = qt.QImage(3, 3, getattr(qt.QImage, format_))
                qimage.fill(qt.QColor(*color))
                image = convertQImageToArray(qimage)

                self.assertEqual(qimage.height(), image.shape[0])
                self.assertEqual(qimage.width(), image.shape[1])
                self.assertEqual(image.shape[2], len(color))
                self.assertTrue(numpy.all(numpy.equal(image, color)))