class GrayscaleImageSourceTest( ut.TestCase ):
    def setUp( self ):
        self.raw = numpy.load(os.path.join(volumina._testing.__path__[0], 'lena.npy'))
        self.ars = _ArraySource2d(self.raw)
        self.ims = GrayscaleImageSource( self.ars, GrayscaleLayer( self.ars ))

    def testRequest( self ):
        imr = self.ims.request(QRect(0,0,512,512))
        def check(result, codon):
            self.assertEqual(codon, "unique")
            self.assertTrue(type(result) == QImage)
        imr.notify(check, codon="unique")

    def testSetDirty( self ):
        def checkAllDirty( rect ):
            self.assertTrue( rect.isEmpty() )

        def checkDirtyRect( rect ):
            self.assertEqual( rect.x(), 34 )
            self.assertEqual( rect.y(), 12 )
            self.assertEqual( rect.width(), 3 )
            self.assertEqual( rect.height(), 22  )

        # should mark everything dirty
        self.ims.isDirty.connect( checkAllDirty )
        self.ims.setDirty((slice(34,None), slice(12,34)))
        self.ims.isDirty.disconnect( checkAllDirty )

        # dirty subrect
        self.ims.isDirty.connect( checkDirtyRect )
        self.ims.setDirty((slice(34,37), slice(12,34)))
        self.ims.isDirty.disconnect( checkDirtyRect )
class GrayscaleImageSourceTest(ImageSourcesTestBase):
    def setUp(self):
        super(GrayscaleImageSourceTest, self).setUp()
        self.raw = numpy.load(
            os.path.join(volumina._testing.__path__[0],
                         'lena.npy')).astype(numpy.uint32)
        self.ars = _ArraySource2d(self.raw)
        self.ims = GrayscaleImageSource(self.ars, GrayscaleLayer(self.ars))

    def testRequest(self):
        imr = self.ims.request(QRect(0, 0, 512, 512))
        result = imr.wait()
        self.assertTrue(type(result) == QImage)

    def testSetDirty(self):
        def checkAllDirty(rect):
            self.assertTrue(rect.isEmpty())

        def checkDirtyRect(rect):
            self.assertEqual(rect.x(), 34)
            self.assertEqual(rect.y(), 12)
            self.assertEqual(rect.width(), 3)
            self.assertEqual(rect.height(), 22)

        # should mark everything dirty
        self.ims.isDirty.connect(checkAllDirty)
        self.ims.setDirty((slice(34, None), slice(12, 34)))
        self.ims.isDirty.disconnect(checkAllDirty)

        # dirty subrect
        self.ims.isDirty.connect(checkDirtyRect)
        self.ims.setDirty((slice(34, 37), slice(12, 34)))
        self.ims.isDirty.disconnect(checkDirtyRect)
Example #3
0
class GrayscaleImageSourceTest(ImageSourcesTestBase):
    def setUp(self):
        super(GrayscaleImageSourceTest, self).setUp()
        self.raw = numpy.load(os.path.join(volumina._testing.__path__[0], "lena.npy")).astype(numpy.uint32)
        self.ars = _ArraySource2d(self.raw)
        self.ims = GrayscaleImageSource(self.ars, GrayscaleLayer(self.ars))

    def testRequest(self):
        imr = self.ims.request(QRect(0, 0, 512, 512))
        result = imr.wait()
        self.assertTrue(type(result) == QImage)

    def testSetDirty(self):
        def checkAllDirty(rect):
            self.assertTrue(rect.isEmpty())

        def checkDirtyRect(rect):
            self.assertEqual(rect.x(), 34)
            self.assertEqual(rect.y(), 12)
            self.assertEqual(rect.width(), 3)
            self.assertEqual(rect.height(), 22)

        # should mark everything dirty
        self.ims.isDirty.connect(checkAllDirty)
        self.ims.setDirty((slice(34, None), slice(12, 34)))
        self.ims.isDirty.disconnect(checkAllDirty)

        # dirty subrect
        self.ims.isDirty.connect(checkDirtyRect)
        self.ims.setDirty((slice(34, 37), slice(12, 34)))
        self.ims.isDirty.disconnect(checkDirtyRect)
Example #4
0
class GrayscaleImageSourceTest2(ImageSourcesTestBase):
    def setUp(self):
        super(GrayscaleImageSourceTest2, self).setUp()
        self.raw = numpy.load(
            os.path.join(volumina._testing.__path__[0],
                         "2d_cells_apoptotic_1channel.npy"))[0:512,
                                                             0:512].astype(
                                                                 numpy.uint32)
        self.raw = numpy.ma.masked_array(self.raw,
                                         numpy.zeros(self.raw.shape,
                                                     dtype=bool),
                                         shrink=False)

        self.raw[:10, :] = numpy.ma.masked
        self.raw[-10:, :] = numpy.ma.masked
        self.raw[:, :10] = numpy.ma.masked
        self.raw[:, -10:] = numpy.ma.masked

        self.ars = _ArraySource2d(self.raw)
        self.ims = GrayscaleImageSource(self.ars, GrayscaleLayer(self.ars))

    def testRequest(self):
        imr = self.ims.request(QRect(0, 0, 512, 512))
        result = imr.wait()
        self.assertTrue(type(result) == QImage)

        result_array = qimage2ndarray.byte_view(result)

        assert (result_array[:10, :, -1] == 255).all()
        assert (result_array[-10:, :, -1] == 255).all()
        assert (result_array[:, :10, -1] == 255).all()
        assert (result_array[:, -10:, -1] == 255).all()

    def testSetDirty(self):
        def checkAllDirty(rect):
            self.assertTrue(rect.isEmpty())

        def checkDirtyRect(rect):
            self.assertEqual(rect.x(), 34)
            self.assertEqual(rect.y(), 12)
            self.assertEqual(rect.width(), 3)
            self.assertEqual(rect.height(), 22)

        # should mark everything dirty
        self.ims.isDirty.connect(checkAllDirty)
        self.ims.setDirty((slice(34, None), slice(12, 34)))
        self.ims.isDirty.disconnect(checkAllDirty)

        # dirty subrect
        self.ims.isDirty.connect(checkDirtyRect)
        self.ims.setDirty((slice(34, 37), slice(12, 34)))
        self.ims.isDirty.disconnect(checkDirtyRect)
Example #5
0
class GrayscaleImageSourceTest2( ImageSourcesTestBase ):
    def setUp( self ):
        super( GrayscaleImageSourceTest2, self ).setUp()
        self.raw = numpy.load(os.path.join(volumina._testing.__path__[0], 'lena.npy')).astype( numpy.uint32 )
        self.raw = numpy.ma.masked_array(self.raw, numpy.zeros(self.raw.shape, dtype=bool), shrink=False)

        self.raw[:10, :] = numpy.ma.masked
        self.raw[-10:, :] = numpy.ma.masked
        self.raw[:, :10] = numpy.ma.masked
        self.raw[:, -10:] = numpy.ma.masked

        self.ars = _ArraySource2d(self.raw)
        self.ims = GrayscaleImageSource( self.ars, GrayscaleLayer( self.ars ))

    def testRequest( self ):
        imr = self.ims.request(QRect(0,0,512,512))
        def check(result, codon):
            self.assertEqual(codon, "unique")
            self.assertTrue(type(result) == QImage)

            result_array = qimage2ndarray.byte_view(result)

            assert((result_array[:10, :, -1] == 255).all())
            assert((result_array[-10:, :, -1] == 255).all())
            assert((result_array[:, :10, -1] == 255).all())
            assert((result_array[:, -10:, -1] == 255).all())

        imr.notify(check, codon="unique")

    def testSetDirty( self ):
        def checkAllDirty( rect ):
            self.assertTrue( rect.isEmpty() )

        def checkDirtyRect( rect ):
            self.assertEqual( rect.x(), 34 )
            self.assertEqual( rect.y(), 12 )
            self.assertEqual( rect.width(), 3 )
            self.assertEqual( rect.height(), 22  )

        # should mark everything dirty
        self.ims.isDirty.connect( checkAllDirty )
        self.ims.setDirty((slice(34,None), slice(12,34)))
        self.ims.isDirty.disconnect( checkAllDirty )

        # dirty subrect
        self.ims.isDirty.connect( checkDirtyRect )
        self.ims.setDirty((slice(34,37), slice(12,34)))
        self.ims.isDirty.disconnect( checkDirtyRect )