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
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()
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()
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()
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()
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 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
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()
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())
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()
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()
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()
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 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())
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()
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()
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 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