Esempio n. 1
0
    def mainFunction(self):
        # ...randomly exchange some pixels
        import numpy
        for i in range(10):
            self.testProject.threshold_ov._data._data[
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[0]),
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[1]),
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[2]),
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[3]),
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[4])] = numpy.random.randint(255)
        self.testProject.dataMgr[
            self.testProject.dataMgr.
            _activeImageNumber].Connected_Components.setInputData(
                self.testProject.threshold_ov._data)

        self.testThread = TestThread(self.testProject.connectedComponentsMgr,
                                     self.testProject.listOfResultOverlays,
                                     self.testProject.listOfFilenames)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'),
                               self.finalizeTest)
        self.testThread.start(
            None)  # ...compute connected components without background
Esempio n. 2
0
class TestWholeModule_WithoutBackgroundWrongImage2D(unittest.TestCase): # tests if wrong input leads to a test fail
     
    def setUp(self):
        #print "setUp"
        self.app = QtCore.QCoreApplication(sys.argv) # we need a QCoreApplication to run, otherwise the thread just gets killed
        self.testProject = CCTestProject("test_image_mirrored.png", "cc_threshold_overlay.h5", "ground_truth_cc_without_background.h5")
    
    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)        
        t.start()
        self.app.exec_()
        
    def mainFunction(self):
        # ...randomly exchange some pixels
        import numpy
        for i in range(10):
            self.testProject.threshold_ov._data._data[numpy.random.randint(self.testProject.threshold_ov._data._data.shape[0]), numpy.random.randint(self.testProject.threshold_ov._data._data.shape[1]), numpy.random.randint(self.testProject.threshold_ov._data._data.shape[2]), numpy.random.randint(self.testProject.threshold_ov._data._data.shape[3]), numpy.random.randint(self.testProject.threshold_ov._data._data.shape[4])] = numpy.random.randint(255)
        self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].Connected_Components.setInputData(self.testProject.threshold_ov._data)
        
        self.testThread = TestThread(self.testProject.connectedComponentsMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest)
        self.testThread.start(None) # ...compute connected components without background

    def finalizeTest(self):
        # results comparison
        self.assertEqual(self.testThread.passedTest, False) # has to be different from ground truth result (wrong input data!)
        self.app.quit()
Esempio n. 3
0
class TestWholeModule_WithoutBackground2D(unittest.TestCase):
     
    def setUp(self):
        print "setUp"
        self.app = QtCore.QCoreApplication(sys.argv) # we need a QCoreApplication to run, otherwise the thread just gets killed
        self.testProject = CCTestProject("test_image.png", "cc_threshold_overlay.h5", "ground_truth_cc_without_background.h5")
    
    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)        
        t.start()
        self.app.exec_()
        
    def mainFunction(self):
        self.testThread = TestThread(self.testProject.connectedComponentsMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest)
        self.testThread.start(None) # ...compute connected components without background

    def finalizeTest(self):
        # results comparison
        print "finalize"
        self.assertEqual(self.testThread.passedTest, True)
        self.app.quit()
Esempio n. 4
0
class TestWholeModule_WithoutBackground2D(unittest.TestCase):
    def setUp(self):
        print "setUp"
        self.app = QtCore.QCoreApplication(
            sys.argv
        )  # we need a QCoreApplication to run, otherwise the thread just gets killed
        self.testProject = CCTestProject(
            "test_image.png", "cc_threshold_overlay.h5",
            "ground_truth_cc_without_background.h5")

    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)
        t.start()
        self.app.exec_()

    def mainFunction(self):
        self.testThread = TestThread(self.testProject.connectedComponentsMgr,
                                     self.testProject.listOfResultOverlays,
                                     self.testProject.listOfFilenames)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'),
                               self.finalizeTest)
        self.testThread.start(
            None)  # ...compute connected components without background

    def finalizeTest(self):
        # results comparison
        print "finalize"
        self.assertEqual(self.testThread.passedTest, True)
        self.app.quit()
Esempio n. 5
0
class TestWholeModuleDefaultDecomposer(unittest.TestCase): # use default decomposer

    if not numpyRecentEnough:
        __test__ = False

    def setUp(self):
        self.app = QtCore.QCoreApplication(sys.argv) # we need a QCoreApplication to run, otherwise the thread just gets killed
        self.testProject = UnsupervisedDecompositionTestProject("sims_aligned_s7_32.h5")
    
    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)        
        t.start()
        self.app.exec_()
        
    def mainFunction(self):
        self.testThread = TestThread(self.testProject.unsupervisedMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames, self.testProject.tolerance)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest)
        self.testThread.start(self.testProject.inputOverlays)        

        self.numOverlaysBefore = len(self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())

    def finalizeTest(self):
        # results comparison
        self.assertEqual(self.testThread.passedTest, True)
                
        self.app.quit()
Esempio n. 6
0
 def mainFunction(self):
     self.testThread = TestThread(self.testProject.connectedComponentsMgr,
                                  self.testProject.listOfResultOverlays,
                                  self.testProject.listOfFilenames)
     QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'),
                            self.finalizeTest)
     self.testThread.start(
         None)  # ...compute connected components without background
Esempio n. 7
0
 def mainFunction(self):
     self.testThread = TestThread(self.testProject.connectedComponentsMgr,
                                  self.testProject.listOfResultOverlays,
                                  self.testProject.listOfFilenames)
     QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'),
                            self.finalizeTest)
     backgroundClasses = set([1, 3])  # use a non-empty background set
     self.testThread.start(
         backgroundClasses
     )  # ...compute connected components with background
Esempio n. 8
0
class TestWholeModulePCADecomposer(unittest.TestCase
                                   ):  # use PCA decomposer with 3 components

    if not numpyRecentEnough:
        __test__ = False

    def setUp(self):
        #print "setUp"
        self.app = QtCore.QCoreApplication(
            sys.argv
        )  # we need a QCoreApplication to run, otherwise the thread just gets killed
        self.numComponents = 3
        self.testProject = UnsupervisedDecompositionTestProject(
            "sims_aligned_s7_32.h5", UnsupervisedDecompositionPCA,
            self.numComponents)

    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)
        t.start()
        self.app.exec_()

    def mainFunction(self):
        self.testThread = TestThread(self.testProject.unsupervisedMgr,
                                     self.testProject.listOfResultOverlays,
                                     self.testProject.listOfFilenames,
                                     self.testProject.tolerance)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'),
                               self.finalizeTest)
        self.testThread.start(self.testProject.inputOverlays)

        self.numOverlaysBefore = len(self.testProject.dataMgr[
            self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())

    def finalizeTest(self):
        '''for i in range(self.testProject.unsupervisedMethod.numComponents):
            print "*************************************"
            print self.testProject.listOfResultOverlays[i]
            obtained = self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr[self.testProject.listOfResultOverlays[i]]
            from ilastik.core import dataImpex
            dataImpex.DataImpex.exportOverlay(str("c:/gt_PCA_result_component_%d" % (i+1)), "h5", obtained)'''

        # results comparison
        self.assertEqual(self.testThread.passedTest, True)

        # other conditions
        # exactly self.numComponents computed overlays + self.numComponents ground truth overlays were added
        self.numOverlaysAfter = len(self.testProject.dataMgr[
            self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())
        self.assertEqual(self.numOverlaysAfter - self.numOverlaysBefore,
                         self.numComponents * 2)

        self.app.quit()
Esempio n. 9
0
    def mainFunction(self):
        self.testThread = TestThread(self.testProject.unsupervisedMgr,
                                     self.testProject.listOfResultOverlays,
                                     self.testProject.listOfFilenames,
                                     self.testProject.tolerance)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'),
                               self.finalizeTest)
        self.testThread.start(self.testProject.inputOverlays)

        self.numOverlaysBefore = len(self.testProject.dataMgr[
            self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())
Esempio n. 10
0
class TestWholeModule_WithoutBackgroundWrongImage2D(
        unittest.TestCase):  # tests if wrong input leads to a test fail
    def setUp(self):
        #print "setUp"
        self.app = QtCore.QCoreApplication(
            sys.argv
        )  # we need a QCoreApplication to run, otherwise the thread just gets killed
        self.testProject = CCTestProject(
            "test_image_mirrored.png", "cc_threshold_overlay.h5",
            "ground_truth_cc_without_background.h5")

    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)
        t.start()
        self.app.exec_()

    def mainFunction(self):
        # ...randomly exchange some pixels
        import numpy
        for i in range(10):
            self.testProject.threshold_ov._data._data[
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[0]),
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[1]),
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[2]),
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[3]),
                numpy.random.randint(self.testProject.threshold_ov._data._data.
                                     shape[4])] = numpy.random.randint(255)
        self.testProject.dataMgr[
            self.testProject.dataMgr.
            _activeImageNumber].Connected_Components.setInputData(
                self.testProject.threshold_ov._data)

        self.testThread = TestThread(self.testProject.connectedComponentsMgr,
                                     self.testProject.listOfResultOverlays,
                                     self.testProject.listOfFilenames)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'),
                               self.finalizeTest)
        self.testThread.start(
            None)  # ...compute connected components without background

    def finalizeTest(self):
        # results comparison
        self.assertEqual(
            self.testThread.passedTest, False
        )  # has to be different from ground truth result (wrong input data!)
        self.app.quit()
Esempio n. 11
0
class TestWholeModulePLSADecomposer(unittest.TestCase
                                    ):  # pLSA with 5 components
    def setUp(self):
        #print "setUp"
        self.app = QtCore.QCoreApplication(sys.argv)
        self.numComponents = 5
        self.testProject = UnsupervisedDecompositionTestProject(
            "sims_aligned_s7_32.h5", UnsupervisedDecompositionPLSA,
            self.numComponents)

    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)
        t.start()
        self.app.exec_()

    def mainFunction(self):
        # fix random seed
        from ilastik.core.randomSeed import RandomSeed
        RandomSeed.setRandomSeed(42)

        self.testThread = TestThread(self.testProject.unsupervisedMgr,
                                     self.testProject.listOfResultOverlays,
                                     self.testProject.listOfFilenames,
                                     self.testProject.tolerance)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'),
                               self.finalizeTest)
        self.testThread.start(self.testProject.inputOverlays)

        self.numOverlaysBefore = len(self.testProject.dataMgr[
            self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())

    def finalizeTest(self):
        '''for i in range(self.testProject.unsupervisedMethod.numComponents):
            obtained = self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr[self.testProject.listOfResultOverlays[i]]
            from ilastik.core import dataImpex
            dataImpex.DataImpex.exportOverlay(str("c:/gt_pLSA_result_component_%d" % (i+1)), "h5", obtained)'''

        # results comparison
        self.assertEqual(self.testThread.passedTest, True)

        # exactly self.numComponents computed overlays + self.numComponents ground truth overlays were added
        self.numOverlaysAfter = len(self.testProject.dataMgr[
            self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())
        self.assertEqual(self.numOverlaysAfter - self.numOverlaysBefore,
                         self.numComponents * 2)

        self.app.quit()
Esempio n. 12
0
class TestWholeModulePCADecomposer(unittest.TestCase): # use PCA decomposer with 3 components

    if not numpyRecentEnough:
        __test__ = False
     
    def setUp(self):
        #print "setUp"
        self.app = QtCore.QCoreApplication(sys.argv) # we need a QCoreApplication to run, otherwise the thread just gets killed
        self.numComponents = 3
        self.testProject = UnsupervisedDecompositionTestProject("sims_aligned_s7_32.h5", UnsupervisedDecompositionPCA, self.numComponents)
    
    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)        
        t.start()
        self.app.exec_()
        
    def mainFunction(self):
        self.testThread = TestThread(self.testProject.unsupervisedMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames, self.testProject.tolerance)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest)
        self.testThread.start(self.testProject.inputOverlays)        

        self.numOverlaysBefore = len(self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())

    def finalizeTest(self):
        '''for i in range(self.testProject.unsupervisedMethod.numComponents):
            print "*************************************"
            print self.testProject.listOfResultOverlays[i]
            obtained = self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr[self.testProject.listOfResultOverlays[i]]
            from ilastik.core import dataImpex
            dataImpex.DataImpex.exportOverlay(str("c:/gt_PCA_result_component_%d" % (i+1)), "h5", obtained)'''
        
         # results comparison
        self.assertEqual(self.testThread.passedTest, True)
        
        # other conditions
        # exactly self.numComponents computed overlays + self.numComponents ground truth overlays were added
        self.numOverlaysAfter = len(self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())
        self.assertEqual(self.numOverlaysAfter - self.numOverlaysBefore, self.numComponents*2)

        self.app.quit()
Esempio n. 13
0
 def mainFunction(self):
     # ...randomly exchange some pixels
     import numpy
     for i in range(10):
         self.testProject.threshold_ov._data._data[numpy.random.randint(self.testProject.threshold_ov._data._data.shape[0]), numpy.random.randint(self.testProject.threshold_ov._data._data.shape[1]), numpy.random.randint(self.testProject.threshold_ov._data._data.shape[2]), numpy.random.randint(self.testProject.threshold_ov._data._data.shape[3]), numpy.random.randint(self.testProject.threshold_ov._data._data.shape[4])] = numpy.random.randint(255)
     self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].Connected_Components.setInputData(self.testProject.threshold_ov._data)
     
     self.testThread = TestThread(self.testProject.connectedComponentsMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames)
     QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest)
     self.testThread.start(None) # ...compute connected components without background
Esempio n. 14
0
    def mainFunction(self):
        # fix random seed
        from ilastik.core.randomSeed import RandomSeed
        RandomSeed.setRandomSeed(42)
        
        self.testThread = TestThread(self.testProject.unsupervisedMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames, self.testProject.tolerance)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest)
        self.testThread.start(self.testProject.inputOverlays)        

        self.numOverlaysBefore = len(self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())
Esempio n. 15
0
class TestWholeModulePLSADecomposer(unittest.TestCase): # pLSA with 5 components
    
    def setUp(self):
        #print "setUp"
        self.app = QtCore.QCoreApplication(sys.argv) 
        self.numComponents = 5
        self.testProject = UnsupervisedDecompositionTestProject("sims_aligned_s7_32.h5", UnsupervisedDecompositionPLSA, self.numComponents)
    
    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)        
        t.start()
        self.app.exec_()
        
    def mainFunction(self):
        # fix random seed
        from ilastik.core.randomSeed import RandomSeed
        RandomSeed.setRandomSeed(42)
        
        self.testThread = TestThread(self.testProject.unsupervisedMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames, self.testProject.tolerance)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest)
        self.testThread.start(self.testProject.inputOverlays)        

        self.numOverlaysBefore = len(self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())

    def finalizeTest(self):
        '''for i in range(self.testProject.unsupervisedMethod.numComponents):
            obtained = self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr[self.testProject.listOfResultOverlays[i]]
            from ilastik.core import dataImpex
            dataImpex.DataImpex.exportOverlay(str("c:/gt_pLSA_result_component_%d" % (i+1)), "h5", obtained)'''
        
        # results comparison
        self.assertEqual(self.testThread.passedTest, True)
        
        # exactly self.numComponents computed overlays + self.numComponents ground truth overlays were added
        self.numOverlaysAfter = len(self.testProject.dataMgr[self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())
        self.assertEqual(self.numOverlaysAfter - self.numOverlaysBefore, self.numComponents*2)
                
        self.app.quit()
Esempio n. 16
0
class TestWholeModuleDefaultDecomposer(unittest.TestCase
                                       ):  # use default decomposer

    if not numpyRecentEnough:
        __test__ = False

    def setUp(self):
        self.app = QtCore.QCoreApplication(
            sys.argv
        )  # we need a QCoreApplication to run, otherwise the thread just gets killed
        self.testProject = UnsupervisedDecompositionTestProject(
            "sims_aligned_s7_32.h5")

    def test_WholeModule(self):
        t = QtCore.QTimer()
        t.setSingleShot(True)
        t.setInterval(0)
        self.app.connect(t, QtCore.SIGNAL('timeout()'), self.mainFunction)
        t.start()
        self.app.exec_()

    def mainFunction(self):
        self.testThread = TestThread(self.testProject.unsupervisedMgr,
                                     self.testProject.listOfResultOverlays,
                                     self.testProject.listOfFilenames,
                                     self.testProject.tolerance)
        QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'),
                               self.finalizeTest)
        self.testThread.start(self.testProject.inputOverlays)

        self.numOverlaysBefore = len(self.testProject.dataMgr[
            self.testProject.dataMgr._activeImageNumber].overlayMgr.keys())

    def finalizeTest(self):
        # results comparison
        self.assertEqual(self.testThread.passedTest, True)

        self.app.quit()
Esempio n. 17
0
 def mainFunction(self):
     self.testThread = TestThread(self.testProject.connectedComponentsMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames)
     QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest)
     self.testThread.start(None) # ...compute connected components without background
Esempio n. 18
0
 def mainFunction(self):
     self.testThread = TestThread(self.testProject.connectedComponentsMgr, self.testProject.listOfResultOverlays, self.testProject.listOfFilenames)
     QtCore.QObject.connect(self.testThread, QtCore.SIGNAL('done()'), self.finalizeTest)
     backgroundClasses = set([1, 3]) # use a non-empty background set
     self.testThread.start(backgroundClasses) # ...compute connected components with background