def test_badInputImage(self):
        data = FMDLData()

        data.input_image_np_cropped = np.zeros(100)

        data.roi_roidDelineatorSize = self.test_roiDetection

        data.bestBoundary = (0.36415937542915344, 0.059263408184051514,
                             0.9990353584289551, 0.8910735845565796)

        validResults = uncropImage(data)

        self.assertFalse(validResults)
        self.assertEqual(len(data.roi_actualSize), 0)
Exemplo n.º 2
0
    def test_missingBucketBoundaryWithMatInsideInConfig(self):
        data = FMDLData()

        data.config = Config(
                {'minObjectsRequired':[['bucket', 'matInside']]},
                [('minObjectsRequired',[ [[]], [['bucket']], [['matInside']],  [['matInside', 'bucket']], [['bucket','matInside']] ])])


        data.matInsideBoundary = (0.3406982123851776, 0.8910735845565796, 0.059263408184051514, 1.0)

        getBestBoundaryToCropWith(data)

        self.assertTrue(np.allclose(data.bucketBoundary, (0.3406982123851776, 0.8910735845565796, 0.059263408184051514, 1.0), atol=1e-04))
        self.assertTrue(np.allclose(data.bestBoundary, (0.3406982123851776, 0.8910735845565796, 0.059263408184051514, 1.0), atol=1e-04))
Exemplo n.º 3
0
 def test_missingBucketBoundaryNoMatInsideInConfig(self):
     data = FMDLData()
     
     data.config = Config(
             {'minObjectsRequired':[['bucket']]},
             [('minObjectsRequired',[ [[]], [['bucket']], [['matInside']],  [['matInside', 'bucket']], [['bucket','matInside']] ])])
     
 
     data.matInsideBoundary = (0.36415937542915344, 0.050836026668548584, 0.9990353584289551, 0.9131188988685608)
     
     getBestBoundaryToCropWith(data)
 
     
     self.assertEqual(data.bestBoundary,())
Exemplo n.º 4
0
    def test_badRoiBoundaryContour(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'),])

        validResults = getRoiBoundaryPoints(data.roi_boundary_contour)

        self.assertFalse(validResults)
        self.assertEqual(len(data.approximated_roi_boundary), 0)
    def test_inferOnSingleImage_badInputImage(self):
        data = FMDLData()

        data.config = Config(
            {'roiDelineatorScoreThreshold': 0.5},
            [('roiDelineatorScoreThreshold', 0, 100, 'float')])

        data.input_image_np_cropped = np.zeros(100)

        validResult = self.roiDelineator.inferOnSingleImage(data)

        self.assertFalse(validResult)

        self.assertEqual(len(data.roi_roidDelineatorSize), 0)
 def test_missingRoiBoundary2(self):
     data = FMDLData()
     
     
     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([])
     
     self.assertTrue(areIntersecting)
Exemplo n.º 7
0
    def test_missingApproxRoi(self):
        data = FMDLData()

        validResults = validateApproximatedRoiBoundary(data)

        self.assertFalse(validResults)
        self.assertFalse(data.valid)
Exemplo n.º 8
0
    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_missingEffectiveWidthModifier(self):
        data = FMDLData()

        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', -1, 1, 'float'),
                ('maxDiffBetweenAbsBucketEdgeSlopes', 0, 100, 'float'),
            ])

        data.load_image(self.byteArrayImage)

        data.bucketBoundary = (0.3406982123851776, 0.059263408184051514, 1.0,
                               0.8910735845565796)

        data.bucketBoundary = (4, 2, 1, 3)

        data.config.effectiveWidthYcoordMultiplier = None

        results = getDetectedBucketWidthAndHeightInPixels(data)

        self.assertEqual(results, (-1, -1, -1, ()))
 def test_badBucketBoundary(self):
     data = FMDLData()
     
 
     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'),
             ])
    
     
     data.load_image(self.byteArrayImage)
     
     
     data.bucketBoundary = (0.3406982123851776, 0.8910735845565796, 0.059263408184051514, 1.0)
     validResults1 = getPixel2CmConversionFactor(data)
     
     
     data.bucketBoundary = (0, -0.8910735845565796, 0, 1.0)
     validResults2 = getPixel2CmConversionFactor(data)
     
     self.assertFalse(validResults1)
     self.assertFalse(validResults2)
     self.assertEqual(data.pixel2CM_conversion_factor , -1)
     self.assertEqual(data.bucketWidthPX, -1)
     self.assertEqual(data.bucketWidthPointsXCord, [])
    def test_outputs_withCase_badCase3(self):
        data = FMDLData()

        data.load_image(self.byteArrayImage)

        data.bucketBoundary = (0.20768868923187256, 0.15239688754081726,
                               0.869536280632019, 0.8369340896606445)

        data.caseBoundary = (0.7303502559661865, 0.27012908458709717,
                             0.37515637278556824, 0.19773945212364197)

        data.config = Config(
            {
                'minBoundingBoxAspectRatio': 1,
                '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'),
            ])

        detected_bucketWidth_inPixels_withCase, detected_bucketWith_inPixels_fromBucketAlone,\
     detected_bucketHeight_inPixels, bucketWidthPointsXCord = getDetectedBucketWidthAndHeightInPixels(data)

        self.assertAlmostEqual(detected_bucketWidth_inPixels_withCase, 438)
        self.assertAlmostEqual(detected_bucketWith_inPixels_fromBucketAlone,
                               438)
        self.assertAlmostEqual(detected_bucketHeight_inPixels, 317)
        self.assertAlmostEqual(bucketWidthPointsXCord[0], 98)
        self.assertAlmostEqual(bucketWidthPointsXCord[1], 536)
    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_outputs(self):
        data = FMDLData()

        actualCopedImage = cv2.imread(
            'tests/networksAndImages-forUnitTesting/cropped_FMDL_2018.04.30_19.11.20.png'
        )

        data.bestBoundary = (0.36415937542915344, 0.059263408184051514, 0.9990353584289551,\
         0.8910735845565796)

        data.load_image(self.byteArrayImage)

        validResults = cropImage(data)

        self.assertTrue(validResults)

        self.assertTrue(
            np.allclose(data.input_image_np_cropped,
                        actualCopedImage,
                        atol=1e-04))
    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_png3chan(self):
        data = FMDLData()

        testFilePath = 'tests/networksAndImages-forUnitTesting/3Chan_FMDL_2018.04.30_19.11.20.png'
        with open(testFilePath, "rb") as imageFile:
            f = imageFile.read()
            byteArrayImage = bytearray(f)

        data.load_image(byteArrayImage)

        imageToTestAgainst = np.load(
            'tests/networksAndImages-forUnitTesting/png_FMDL_2018.04.30_19.11.20.npy'
        )
        testImHeight, testImWidth, _ = imageToTestAgainst.shape

        self.assertTrue(data.is_valid_image)
        self.assertEqual(data.imageWidthPx, testImWidth)
        self.assertEqual(data.imageHeightPx, testImHeight)
        self.assertTrue(
            np.allclose(data.input_image_np, imageToTestAgainst, atol=1e-04))
 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_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": 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_bucketBoundaryWithWrongAspectRatio(self):
        data = FMDLData()

        data.load_image(self.byteArrayImage)

        data.bucketBoundary = (4, 2, 1, 3)

        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_outputs_noCase(self):
        data = FMDLData()

        data.load_image(self.byteArrayImage)

        data.bucketBoundary = (0.36322835087776184, 0.13493812084197998, 1.0,
                               0.8854146003723145)

        data.config = Config(
            {
                'minBoundingBoxAspectRatio': 1,
                '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'),
            ])

        detected_bucketWidth_inPixels_withCase, detected_bucketWith_inPixels_fromBucketAlone,\
     detected_bucketHeight_inPixels, bucketWidthPointsXCord = getDetectedBucketWidthAndHeightInPixels(data)

        self.assertAlmostEqual(detected_bucketWidth_inPixels_withCase, 481)
        self.assertAlmostEqual(detected_bucketWith_inPixels_fromBucketAlone,
                               481)
        self.assertAlmostEqual(detected_bucketHeight_inPixels, 306)
        self.assertAlmostEqual(bucketWidthPointsXCord[0], 86)
        self.assertAlmostEqual(bucketWidthPointsXCord[1], 567)
Exemplo n.º 20
0
    def test_inferOnSingleImage_missingInputImage(self):
        data = FMDLData()
        validResult = self.boxDetector.inferOnSingleImage(data)

        self.assertFalse(validResult)

        for itm1, item2 in zip(data.bucketBoundary, ()):
            self.assertAlmostEqual(itm1, item2)

        self.assertAlmostEqual(data.bucketScore, -1)

        for itm1, item2 in zip(data.matInsideBoundary, ()):
            self.assertAlmostEqual(itm1, item2)

        self.assertAlmostEqual(data.matInsideScore, -1)
    def test_badInputImage(self):
        data = FMDLData()

        testFilePath = 'tests/networksAndImages-forUnitTesting/bad_FMDL_2018.04.30_19.11.20.png'
        with open(testFilePath, "rb") as imageFile:
            f = imageFile.read()
            byteArrayImage = bytearray(f)

        data.load_image(byteArrayImage)

        data.load_image(byteArrayImage)

        self.assertFalse(data.is_valid_image)
    def test_badBestBoundary(self):
        data = FMDLData()

        data.load_image(self.byteArrayImage)

        data.roi_roidDelineatorSize = self.test_roiDetection

        data.bestBoundary = (1, 0, 1, 0)

        validResults = uncropImage(data)

        self.assertFalse(validResults)
        self.assertEqual(len(data.roi_actualSize), 0)
    def test_badRoidDelineatorSize(self):
        data = FMDLData()

        data.load_image(self.byteArrayImage)

        data.roi_roidDelineatorSize = np.zeros(100)

        data.bestBoundary = (0.36415937542915344, 0.059263408184051514,
                             0.9990353584289551, 0.8910735845565796)

        validResults = uncropImage(data)

        self.assertFalse(validResults)
    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_outputs(self):
        data = FMDLData()

        data.load_image(self.byteArrayImage)

        data.roi_roidDelineatorSize = self.test_roiDetection

        data.bestBoundary = (0.36415937542915344, 0.059263408184051514,
                             0.9990353584289551, 0.8910735845565796)

        validResults = uncropImage(data)

        actualRoiUncropped = cv2.imread(
            'tests/networksAndImages-forUnitTesting/roiActualSize_FMDL_2018.04.30_19.11.20.png'
        )
        actualRoiUncropped = cv2.cvtColor(actualRoiUncropped,
                                          cv2.COLOR_BGR2GRAY)

        self.assertTrue(validResults)

        self.assertTrue(
            np.allclose(data.roi_actualSize, actualRoiUncropped, atol=1e-04))
 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)