Exemplo n.º 1
0
    def setUp( self ):
        self.GRAY1 = 60
        self.ds1 = ConstantSource( self.GRAY1 )

        self.GRAY2 = 120
        self.ds2 = ConstantSource( self.GRAY2 )

        self.GRAY3 = 190
        self.ds3 = ConstantSource( self.GRAY3 )

        self.layer1 = GrayscaleLayer( self.ds1, normalize = False )
        self.layer1.visible = False
        self.layer1.opacity = 0.1
        self.ims1 = GrayscaleImageSource( self.ds1, self.layer1 )
        self.layer2 = GrayscaleLayer( self.ds2, normalize = False )
        self.layer2.visible = True
        self.layer2.opacity = 0.3
        self.ims2 = GrayscaleImageSource( self.ds2, self.layer2 )
        self.layer3 = GrayscaleLayer( self.ds3, normalize = False )
        self.layer3.visible = True
        self.layer3.opacity = 1.0
        self.ims3 = GrayscaleImageSource( self.ds3, self.layer3 )

        lsm = LayerStackModel()
        lsm.append(self.layer1)
        lsm.append(self.layer2)
        lsm.append(self.layer3)
        self.lsm = lsm
        sims = StackedImageSources( lsm )
        sims.register( self.layer1, self.ims1 )
        sims.register( self.layer2, self.ims2 )
        sims.register( self.layer3, self.ims3 )
        self.sims = sims
Exemplo n.º 2
0
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)
Exemplo n.º 4
0
 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))
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def setUp(self):
     super(GrayscaleImageSourceTest, self).setUp()
     self.raw = numpy.load(
         os.path.join(volumina._testing.__path__[0],
                      "2d_cells_apoptotic_1channel.npy")).astype(
                          numpy.uint32)
     self.ars = _ArraySource2d(self.raw)
     self.ims = GrayscaleImageSource(self.ars, GrayscaleLayer(self.ars))
Exemplo n.º 7
0
    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))
Exemplo n.º 8
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)
Exemplo n.º 9
0
    def setUp(self):
        self.ds = ConstantSource()

        self.layer1 = GrayscaleLayer(self.ds)
        self.layer1.visible = False
        self.layer1.opacity = 0.1
        self.ims1 = GrayscaleImageSource(self.ds, self.layer1)
        self.layer2 = GrayscaleLayer(self.ds)
        self.layer2.visible = True
        self.layer2.opacity = 0.3
        self.ims2 = GrayscaleImageSource(self.ds, self.layer2)
        self.layer3 = GrayscaleLayer(self.ds)
        self.layer3.visible = True
        self.layer3.opacity = 1.0
        self.ims3 = GrayscaleImageSource(self.ds, self.layer3)
Exemplo n.º 10
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 )
Exemplo n.º 11
0
    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 ))
Exemplo n.º 12
0
 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 ))
Exemplo n.º 13
0
 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 ))
Exemplo n.º 14
0
 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))