def test_badRoiBoundary(self): data = FMDLData() data.roi_boundary_contour = np.zeros((100,1), int) data.config = Config( {'minContourArea': 8000,'roiBoundaryPointsReductionFactor': 0.01, "intersectingRoiMaxIterations": 5, "intersectingRoiStepSize": 0.001,}, [('intersectingRoiStepSize', 0.00001, 0.1, 'float'), ('intersectingRoiMaxIterations', 0, 100, 'integer'), ('minContourArea', 10, 100000, 'integer'), ('roiBoundaryPointsReductionFactor',0.001, 0.1, 'float'),]) areIntersecting = areRoiBoundaryPointsIntersecting(data.roi_boundary_contour) self.assertTrue(areIntersecting)
def test_badPostProcessedRoi(self): data = FMDLData() data.postProcessed_roi_actualSize = np.zeros((100, 1), int) data.config = Config( { 'minContourArea': 8000, 'roiBoundaryPointsReductionFactor': 0.01 }, [('minContourArea', 10, 100000, 'integer'),('roiBoundaryPointsReductionFactor',\ 0.001, 0.1, 'float'),]) validResults = getRoiContour(data) self.assertFalse(validResults) self.assertEqual(len(data.approximated_roi_boundary), 0)
def test_outputs_notInteresecting2(self): data = FMDLData() data.approximated_roi_boundary = self.groundTruth_approximated_roi_boundary data.config = Config( {'minContourArea': 8000,'roiBoundaryPointsReductionFactor': 0.01, "intersectingRoiMaxIterations": 10, "intersectingRoiStepSize": 0.001,}, [('intersectingRoiStepSize', 0.00001, 0.1, 'float'), ('intersectingRoiMaxIterations', 0, 100, 'integer'), ('minContourArea', 10, 100000, 'integer'), ('roiBoundaryPointsReductionFactor',0.001, 0.1, 'float'),]) areIntersecting = areRoiBoundaryPointsIntersecting(data.approximated_roi_boundary[:,0,:]) self.assertFalse(areIntersecting)
def test_missingRoiActualSize(self): data = FMDLData() data.config = Config( { 'closingKernelSize': 7, 'closingIterations': 1, 'erosionKernelSize': 7, 'erosionIterations': 1, }, [ ('closingKernelSize', 1, 20), ('closingIterations', 0, 20), ('erosionKernelSize', 1, 20), ('erosionIterations', 0, 20), ]) validResults = postProcessRoi(data) self.assertFalse(validResults) self.assertEqual(len(data.postProcessed_roi_actualSize), 0)
def test_missingBucketBoundary(self): data = FMDLData() data.load_image(self.byteArrayImage) data.config = Config( {'minBoundingBoxAspectRatio':1.5,'maxBoundingBoxAspectRatio': 3,'measuredBucketWidthCM':300,"effectiveWidthYcoordMultiplier":0.5,'maxDiffBetweenAbsBucketEdgeSlopes': 3}, [ ('measuredBucketWidthCM', 10, 100000, 'float'), ('minBoundingBoxAspectRatio', 0.1, 10, 'float'), ('maxBoundingBoxAspectRatio', 0.1, 10, 'float'), ('effectiveWidthYcoordMultiplier', 0, 1, 'float'), ('maxDiffBetweenAbsBucketEdgeSlopes', 0, 100, 'float'), ]) validResults = getPixel2CmConversionFactor(data) self.assertFalse(validResults) self.assertEqual(data.pixel2CM_conversion_factor , -1) self.assertEqual(data.bucketWidthPX, -1) self.assertEqual(data.bucketWidthPointsXCord, [])
def test_bucketBoundaryWithWrongAspectRatio(self): data = FMDLData() data.load_image(self.byteArrayImage) data.bucketBoundary = (1,2,3,4) data.config = Config( {'minBoundingBoxAspectRatio':1.5,'maxBoundingBoxAspectRatio': 3,'measuredBucketWidthCM':300,"effectiveWidthYcoordMultiplier":0.5,'maxDiffBetweenAbsBucketEdgeSlopes': 3}, [ ('measuredBucketWidthCM', 10, 100000, 'float'), ('minBoundingBoxAspectRatio', 0.1, 10, 'float'), ('maxBoundingBoxAspectRatio', 0.1, 10, 'float'), ('effectiveWidthYcoordMultiplier', 0, 1, 'float'), ('maxDiffBetweenAbsBucketEdgeSlopes', 0, 100, 'float'), ]) validResults = getPixel2CmConversionFactor(data) self.assertFalse(validResults)
def test_missingConfigItems(self): data = FMDLData() data.load_image(self.byteArrayImage) data.bucketBoundary = (0.3406982123851776, 0.059263408184051514, 1.0, 0.8910735845565796) data.config = Config( { 'minBoundingBoxAspectRatio': 1.5, 'measuredBucketWidthCM': 300, }, [ ('measuredBucketWidthCM', 10, 100000, 'float'), ('minBoundingBoxAspectRatio', 0.1, 10, 'float'), ('maxBoundingBoxAspectRatio', 0.1, 10, 'float'), ('effectiveWidthYcoordMultiplier', 0, 1, 'float'), ('maxDiffBetweenAbsBucketEdgeSlopes', 0, 100, 'float'), ]) results = getDetectedBucketWidthAndHeightInPixels(data) self.assertEqual(results, (-1, -1, -1, ()))
def test_missingInputImage(self): data = FMDLData() data.bucketBoundary = (1, 2, 3, 4) data.config = Config( { 'minBoundingBoxAspectRatio': 1.5, 'maxBoundingBoxAspectRatio': 3, 'measuredBucketWidthCM': 300, "effectiveWidthYcoordMultiplier": 0.5, "maxDiffBetweenAbsBucketEdgeSlopes": 5 }, [ ('measuredBucketWidthCM', 10, 100000, 'float'), ('minBoundingBoxAspectRatio', 0.1, 10, 'float'), ('maxBoundingBoxAspectRatio', 0.1, 10, 'float'), ('effectiveWidthYcoordMultiplier', 0, 1, 'float'), ('maxDiffBetweenAbsBucketEdgeSlopes', 0, 100, 'float'), ]) results = getDetectedBucketWidthAndHeightInPixels(data) self.assertEqual(results, (-1, -1, -1, ()))
def test_missingConfigItems(self): data = FMDLData() data.load_image(self.byteArrayImage) data.bucketBoundary = (0.3406982123851776, 0.059263408184051514, 1.0, 0.8910735845565796) data.config = Config( {'minBoundingBoxAspectRatio':1.5,'measuredBucketWidthCM':300,'maxDiffBetweenAbsBucketEdgeSlopes': 3}, [ ('measuredBucketWidthCM', 10, 100000, 'float'), ('minBoundingBoxAspectRatio', 0.1, 10, 'float'), ('maxBoundingBoxAspectRatio', 0.1, 10, 'float'), ('effectiveWidthYcoordMultiplier', 0, 1, 'float'), ('maxDiffBetweenAbsBucketEdgeSlopes', 0, 100, 'float'), ]) validResults = getPixel2CmConversionFactor(data) self.assertFalse(validResults) self.assertEqual(data.pixel2CM_conversion_factor , -1) self.assertEqual(data.bucketWidthPX, -1) self.assertEqual(data.bucketWidthPointsXCord, [])
def test_badInputImage1(self): data = FMDLData() data.load_image('tests/networksAndImages-forUnitTesting/FMDL_2018.04.30_19.11.20.png') data.bucketBoundary = (1,2,3,4) data.config = Config( {'minBoundingBoxAspectRatio':1.5,'maxBoundingBoxAspectRatio': 3,'measuredBucketWidthCM':300,"effectiveWidthYcoordMultiplier":0.5,'maxDiffBetweenAbsBucketEdgeSlopes': 3}, [ ('measuredBucketWidthCM', 10, 100000, 'float'), ('minBoundingBoxAspectRatio', 0.1, 10, 'float'), ('maxBoundingBoxAspectRatio', 0.1, 10, 'float'), ('effectiveWidthYcoordMultiplier', 0, 1, 'float'), ('maxDiffBetweenAbsBucketEdgeSlopes', 0, 100, 'float'), ]) validResults = getPixel2CmConversionFactor(data) self.assertFalse(validResults) self.assertEqual(data.pixel2CM_conversion_factor , -1) self.assertEqual(data.bucketWidthPX, -1) self.assertEqual(data.bucketWidthPointsXCord, [])
def test_outputs(self): data = FMDLData() data.load_image(self.byteArrayImage) data.bucketBoundary = (0.3406982123851776, 0.059263408184051514, 1.0, 0.8910735845565796) data.config = Config( {'minBoundingBoxAspectRatio':1.5,'maxBoundingBoxAspectRatio': 3,'measuredBucketWidthCM':300,"effectiveWidthYcoordMultiplier":0.5,'maxDiffBetweenAbsBucketEdgeSlopes': 3}, [ ('measuredBucketWidthCM', 10, 100000, 'float'), ('minBoundingBoxAspectRatio', 0.1, 10, 'float'), ('maxBoundingBoxAspectRatio', 0.1, 10, 'float'), ('effectiveWidthYcoordMultiplier', 0, 1, 'float'), ('maxDiffBetweenAbsBucketEdgeSlopes', 0, 100, 'float'), ]) validResults = getPixel2CmConversionFactor(data) self.assertTrue(validResults) self.assertTrue(np.allclose(data.pixel2CM_conversion_factor, (0.5639097744360902), atol=1e-04)) self.assertAlmostEqual(data.bucketWidthPX, 532) self.assertEqual(data.bucketWidthPointsXCord[0], 38) self.assertEqual(data.bucketWidthPointsXCord[1], 570)