Ejemplo n.º 1
0
    def __init__(self, backend):
        qt.QMainWindow.__init__(self, parent=None)
        self._plot = CompareImages(parent=self, backend=backend)

        self._selectionTable = UrlSelectionTable(parent=self)
        self._dockWidgetMenu = qt.QDockWidget(parent=self)
        self._dockWidgetMenu.layout().setContentsMargins(0, 0, 0, 0)
        self._dockWidgetMenu.setFeatures(qt.QDockWidget.DockWidgetMovable)
        self._dockWidgetMenu.setWidget(self._selectionTable)
        self.addDockWidget(qt.Qt.LeftDockWidgetArea, self._dockWidgetMenu)

        self.setCentralWidget(self._plot)

        self._selectionTable.sigImageAChanged.connect(self._updateImageA)
        self._selectionTable.sigImageBChanged.connect(self._updateImageB)
Ejemplo n.º 2
0
    def __init__(self, backend):
        qt.QMainWindow.__init__(self, parent=None)
        self._plot = CompareImages(parent=self, backend=backend)

        self._selectionTable = UrlSelectionTable(parent=self)
        self._dockWidgetMenu = qt.QDockWidget(parent=self)
        self._dockWidgetMenu.layout().setContentsMargins(0, 0, 0, 0)
        self._dockWidgetMenu.setFeatures(qt.QDockWidget.DockWidgetMovable)
        self._dockWidgetMenu.setWidget(self._selectionTable)
        self.addDockWidget(qt.Qt.LeftDockWidgetArea, self._dockWidgetMenu)

        self.setCentralWidget(self._plot)

        self._selectionTable.sigImageAChanged.connect(self._updateImageA)
        self._selectionTable.sigImageBChanged.connect(self._updateImageB)
Ejemplo n.º 3
0
 def setUp(self):
     super(TestCompareImages, self).setUp()
     self.widget = CompareImages()
Ejemplo n.º 4
0
class TestCompareImages(TestCaseQt):
    """Test that CompareImages widget is working in some cases"""
    def setUp(self):
        super(TestCompareImages, self).setUp()
        self.widget = CompareImages()

    def tearDown(self):
        ref = weakref.ref(self.widget)
        self.widget = None
        self.qWaitForDestroy(ref)
        super(TestCompareImages, self).tearDown()

    def testIntensityImage(self):
        image1 = numpy.random.rand(10, 10)
        image2 = numpy.random.rand(10, 10)
        self.widget.setData(image1, image2)

    def testRgbImage(self):
        image1 = numpy.random.randint(0, 255, size=(10, 10, 3))
        image2 = numpy.random.randint(0, 255, size=(10, 10, 3))
        self.widget.setData(image1, image2)

    def testRgbaImage(self):
        image1 = numpy.random.randint(0, 255, size=(10, 10, 4))
        image2 = numpy.random.randint(0, 255, size=(10, 10, 4))
        self.widget.setData(image1, image2)

    def testVizualisations(self):
        image1 = numpy.random.rand(10, 10)
        image2 = numpy.random.rand(10, 10)
        self.widget.setData(image1, image2)
        for mode in CompareImages.VisualizationMode:
            self.widget.setVisualizationMode(mode)

    def testAlignemnt(self):
        image1 = numpy.random.rand(10, 10)
        image2 = numpy.random.rand(5, 5)
        self.widget.setData(image1, image2)
        for mode in CompareImages.AlignmentMode:
            self.widget.setAlignmentMode(mode)

    def testGetPixel(self):
        image1 = numpy.random.rand(11, 11)
        image2 = numpy.random.rand(5, 5)
        image1[5, 5] = 111.111
        image2[2, 2] = 222.222
        self.widget.setData(image1, image2)
        expectedValue = {}
        expectedValue[CompareImages.AlignmentMode.CENTER] = 222.222
        expectedValue[CompareImages.AlignmentMode.STRETCH] = 222.222
        expectedValue[CompareImages.AlignmentMode.ORIGIN] = None
        for mode in expectedValue.keys():
            self.widget.setAlignmentMode(mode)
            data = self.widget.getRawPixelData(11 / 2.0, 11 / 2.0)
            data1, data2 = data
            self.assertEqual(data1, 111.111)
            self.assertEqual(data2, expectedValue[mode])

    def testImageEmpty(self):
        self.widget.setData(image1=None, image2=None)
        self.assertTrue(
            self.widget.getRawPixelData(11 / 2.0, 11 / 2.0) == (None, None))

    def testSetImageSeparately(self):
        self.widget.setImage1(numpy.random.rand(10, 10))
        self.widget.setImage2(numpy.random.rand(10, 10))
        for mode in CompareImages.VisualizationMode:
            self.widget.setVisualizationMode(mode)
Ejemplo n.º 5
0
 def setUp(self):
     super(TestCompareImages, self).setUp()
     self.widget = CompareImages()
Ejemplo n.º 6
0
class TestCompareImages(TestCaseQt):
    """Test that CompareImages widget is working in some cases"""

    def setUp(self):
        super(TestCompareImages, self).setUp()
        self.widget = CompareImages()

    def tearDown(self):
        ref = weakref.ref(self.widget)
        self.widget = None
        self.qWaitForDestroy(ref)
        super(TestCompareImages, self).tearDown()

    def testIntensityImage(self):
        image1 = numpy.random.rand(10, 10)
        image2 = numpy.random.rand(10, 10)
        self.widget.setData(image1, image2)

    def testRgbImage(self):
        image1 = numpy.random.randint(0, 255, size=(10, 10, 3))
        image2 = numpy.random.randint(0, 255, size=(10, 10, 3))
        self.widget.setData(image1, image2)

    def testRgbaImage(self):
        image1 = numpy.random.randint(0, 255, size=(10, 10, 4))
        image2 = numpy.random.randint(0, 255, size=(10, 10, 4))
        self.widget.setData(image1, image2)

    def testVizualisations(self):
        image1 = numpy.random.rand(10, 10)
        image2 = numpy.random.rand(10, 10)
        self.widget.setData(image1, image2)
        for mode in CompareImages.VisualizationMode:
            self.widget.setVisualizationMode(mode)

    def testAlignemnt(self):
        image1 = numpy.random.rand(10, 10)
        image2 = numpy.random.rand(5, 5)
        self.widget.setData(image1, image2)
        for mode in CompareImages.AlignmentMode:
            self.widget.setAlignmentMode(mode)

    def testGetPixel(self):
        image1 = numpy.random.rand(11, 11)
        image2 = numpy.random.rand(5, 5)
        image1[5, 5] = 111.111
        image2[2, 2] = 222.222
        self.widget.setData(image1, image2)
        expectedValue = {}
        expectedValue[CompareImages.AlignmentMode.CENTER] = 222.222
        expectedValue[CompareImages.AlignmentMode.STRETCH] = 222.222
        expectedValue[CompareImages.AlignmentMode.ORIGIN] = None
        for mode in expectedValue.keys():
            self.widget.setAlignmentMode(mode)
            data = self.widget.getRawPixelData(11 / 2.0, 11 / 2.0)
            data1, data2 = data
            self.assertEqual(data1, 111.111)
            self.assertEqual(data2, expectedValue[mode])

    def testImageEmpty(self):
        self.widget.setData(image1=None, image2=None)
        self.assertTrue(self.widget.getRawPixelData(11 / 2.0, 11 / 2.0) == (None, None))

    def testSetImageSeparately(self):
        self.widget.setImage1(numpy.random.rand(10, 10))
        self.widget.setImage2(numpy.random.rand(10, 10))
        for mode in CompareImages.VisualizationMode:
            self.widget.setVisualizationMode(mode)
Ejemplo n.º 7
0
class CompareImagesSelection(qt.QMainWindow):
    def __init__(self, backend):
        qt.QMainWindow.__init__(self, parent=None)
        self._plot = CompareImages(parent=self, backend=backend)

        self._selectionTable = UrlSelectionTable(parent=self)
        self._dockWidgetMenu = qt.QDockWidget(parent=self)
        self._dockWidgetMenu.layout().setContentsMargins(0, 0, 0, 0)
        self._dockWidgetMenu.setFeatures(qt.QDockWidget.DockWidgetMovable)
        self._dockWidgetMenu.setWidget(self._selectionTable)
        self.addDockWidget(qt.Qt.LeftDockWidgetArea, self._dockWidgetMenu)

        self.setCentralWidget(self._plot)

        self._selectionTable.sigImageAChanged.connect(self._updateImageA)
        self._selectionTable.sigImageBChanged.connect(self._updateImageB)

    def setUrls(self, urls):
        for url in urls:
            self._selectionTable.addUrl(url)

    def setFiles(self, files):
        urls = list()
        for _file in files:
            if os.path.isfile(_file):
                urls.append(DataUrl(file_path=_file, scheme=None))
        urls.sort(key=lambda url: url.path())
        window.setUrls(urls)
        window._selectionTable.setSelection(url_img_a=urls[0].path(),
                                            url_img_b=urls[1].path())

    def clear(self):
        self._plot.clear()
        self._selectionTable.clear()

    def _updateImageA(self, urlpath):
        self._updateImage(urlpath, self._plot.setImage1)

    def _updateImage(self, urlpath, fctptr):
        def getData():
            _url = silx.io.url.DataUrl(path=urlpath)
            for scheme in ('silx', 'fabio'):
                try:
                    dataImg = silx.io.utils.get_data(
                        silx.io.url.DataUrl(file_path=_url.file_path(),
                                            data_slice=_url.data_slice(),
                                            data_path=_url.data_path(),
                                            scheme=scheme))
                except:
                    _logger.debug("Error while loading image with %s" % scheme,
                                  exc_info=True)
                else:
                    # TODO: check is an image
                    return dataImg
            return None

        data = getData()
        if data is not None:
            fctptr(data)

    def _updateImageB(self, urlpath):
        self._updateImage(urlpath, self._plot.setImage2)
Ejemplo n.º 8
0
if __name__ == "__main__":
    parser = createParser()
    options = parser.parse_args(sys.argv[1:])

    if options.debug:
        logging.root.setLevel(logging.DEBUG)

    if options.use_opengl_plot:
        backend = "gl"
    else:
        backend = "mpl"

    app = qt.QApplication([])
    if options.testdata or len(options.files) == 2:
        if options.testdata:
            _logger.info("Generate test data")
            data1, data2 = createTestData()
        else:
            data1 = loadImage(options.files[0])
            data2 = loadImage(options.files[1])
        window = CompareImages(backend=backend)
        window.setData(data1, data2)
    else:
        data = options.files
        window = CompareImagesSelection(backend=backend)
        window.setFiles(options.files)

    window.setVisible(True)
    app.exec_()
                        help='Use OpenGL for plots (instead of matplotlib)')
    return parser


if __name__ == "__main__":
    parser = createParser()
    options = parser.parse_args(sys.argv[1:])

    if options.debug:
        logging.root.setLevel(logging.DEBUG)

    if options.testdata:
        _logger.info("Generate test data")
        data1, data2 = createTestData()
    else:
        if len(options.files) != 2:
            raise Exception("Expected 2 images to compare them")
        data1 = loadImage(options.files[0])
        data2 = loadImage(options.files[1])

    if options.use_opengl_plot:
        backend = "gl"
    else:
        backend = "mpl"

    app = qt.QApplication([])
    window = CompareImages(backend=backend)
    window.setData(data1, data2)
    window.setVisible(True)
    app.exec_()
Ejemplo n.º 10
0
class CompareImagesSelection(qt.QMainWindow):
    def __init__(self, backend):
        qt.QMainWindow.__init__(self, parent=None)
        self._plot = CompareImages(parent=self, backend=backend)

        self._selectionTable = UrlSelectionTable(parent=self)
        self._dockWidgetMenu = qt.QDockWidget(parent=self)
        self._dockWidgetMenu.layout().setContentsMargins(0, 0, 0, 0)
        self._dockWidgetMenu.setFeatures(qt.QDockWidget.DockWidgetMovable)
        self._dockWidgetMenu.setWidget(self._selectionTable)
        self.addDockWidget(qt.Qt.LeftDockWidgetArea, self._dockWidgetMenu)

        self.setCentralWidget(self._plot)

        self._selectionTable.sigImageAChanged.connect(self._updateImageA)
        self._selectionTable.sigImageBChanged.connect(self._updateImageB)

    def setUrls(self, urls):
        for url in urls:
            self._selectionTable.addUrl(url)

    def setFiles(self, files):
        urls = list()
        for _file in files:
            if os.path.isfile(_file):
                urls.append(DataUrl(file_path=_file, scheme=None))
        urls.sort(key=lambda url: url.path())
        window.setUrls(urls)
        window._selectionTable.setSelection(url_img_a=urls[0].path(),
                                            url_img_b=urls[1].path())

    def clear(self):
        self._plot.clear()
        self._selectionTable.clear()

    def _updateImageA(self, urlpath):
        self._updateImage(urlpath, self._plot.setImage1)

    def _updateImage(self, urlpath, fctptr):
        def getData():
            _url = silx.io.url.DataUrl(path=urlpath)
            for scheme in ('silx', 'fabio'):
                try:
                    dataImg = silx.io.utils.get_data(
                        silx.io.url.DataUrl(file_path=_url.file_path(),
                                            data_slice=_url.data_slice(),
                                            data_path=_url.data_path(),
                                            scheme=scheme))
                except:
                    _logger.debug("Error while loading image with %s" % scheme,
                                  exc_info=True)
                else:
                    # TODO: check is an image
                    return dataImg
            return None

        data = getData()
        if data is not None:
            fctptr(data)

    def _updateImageB(self, urlpath):
        self._updateImage(urlpath, self._plot.setImage2)
Ejemplo n.º 11
0
if __name__ == "__main__":
    parser = createParser()
    options = parser.parse_args(sys.argv[1:])

    if options.debug:
        logging.root.setLevel(logging.DEBUG)

    if options.use_opengl_plot:
        backend = "gl"
    else:
        backend = "mpl"

    app = qt.QApplication([])
    if options.testdata or len(options.files) == 2:
        if options.testdata:
            _logger.info("Generate test data")
            data1, data2 = createTestData()
        else:
            data1 = loadImage(options.files[0])
            data2 = loadImage(options.files[1])
        window = CompareImages(backend=backend)
        window.setData(data1, data2)
    else:
        data = options.files
        window = CompareImagesSelection(backend=backend)
        window.setFiles(options.files)

    window.setVisible(True)
    app.exec_()