def test_compute_haralick_features(self):

        f = [
            'Haralick.ASM',
            'Haralick.Contrast',
            'Haralick.Correlation',
            'Haralick.SumOfSquares',
            'Haralick.IDM',
            'Haralick.SumAverage',
            'Haralick.SumVariance',
            'Haralick.SumEntropy',
            'Haralick.Entropy',
            'Haralick.DifferenceVariance',
            'Haralick.DifferenceEntropy',
            'Haralick.IMC1',
            'Haralick.IMC2',
        ]

        expected_feature_list = []
        for col in f:
            expected_feature_list.append(col + '.Mean')
            expected_feature_list.append(col + '.Range')

        fdata = htk_features.compute_haralick_features(
            self.im_nuclei_seg_mask, self.im_nuclei_stain)

        self.check_fdata_sanity(fdata, expected_feature_list)

        self.check_fdata_sanity(self.fdata_nuclei, expected_feature_list,
                                prefix='Nucleus.',
                                match_feature_count=False)

        self.check_fdata_sanity(self.fdata_nuclei, expected_feature_list,
                                prefix='Cytoplasm.',
                                match_feature_count=False)
Beispiel #2
0
    def test_compute_haralick_features(self):

        f = [
            'Haralick.ASM',
            'Haralick.Contrast',
            'Haralick.Correlation',
            'Haralick.SumOfSquares',
            'Haralick.IDM',
            'Haralick.SumAverage',
            'Haralick.SumVariance',
            'Haralick.SumEntropy',
            'Haralick.Entropy',
            'Haralick.DifferenceVariance',
            'Haralick.DifferenceEntropy',
            'Haralick.IMC1',
            'Haralick.IMC2',
        ]

        expected_feature_list = []
        for col in f:
            expected_feature_list.append(col + '.Mean')
            expected_feature_list.append(col + '.Range')

        fdata = htk_features.compute_haralick_features(cfg.im_nuclei_seg_mask,
                                                       cfg.im_nuclei_stain)

        check_fdata_sanity(fdata, expected_feature_list)

        check_fdata_sanity(cfg.fdata_nuclei,
                           expected_feature_list,
                           prefix='Nucleus.',
                           match_feature_count=False)

        check_fdata_sanity(cfg.fdata_nuclei,
                           expected_feature_list,
                           prefix='Cytoplasm.',
                           match_feature_count=False)

        if GENERATE_GROUNDTRUTH:
            fdata.to_csv(os.path.join(tempfile.gettempdir(),
                                      'Easy1_nuclei_haralick_features.csv'),
                         index=False)

        fdata_gtruth = pd.read_csv(
            utilities.getTestFilePath('Easy1_nuclei_haralick_features.csv'))

        pd.testing.assert_frame_equal(fdata,
                                      fdata_gtruth,
                                      check_less_precise=2)
    def test_compute_haralick_features(self):

        f = [
            'Haralick.ASM',
            'Haralick.Contrast',
            'Haralick.Correlation',
            'Haralick.SumOfSquares',
            'Haralick.IDM',
            'Haralick.SumAverage',
            'Haralick.SumVariance',
            'Haralick.SumEntropy',
            'Haralick.Entropy',
            'Haralick.DifferenceVariance',
            'Haralick.DifferenceEntropy',
            'Haralick.IMC1',
            'Haralick.IMC2',
        ]

        expected_feature_list = []
        for col in f:
            expected_feature_list.append(col + '.Mean')
            expected_feature_list.append(col + '.Range')

        fdata = htk_features.compute_haralick_features(self.im_nuclei_seg_mask,
                                                       self.im_nuclei_stain)

        self.check_fdata_sanity(fdata, expected_feature_list)

        self.check_fdata_sanity(self.fdata_nuclei,
                                expected_feature_list,
                                prefix='Nucleus.',
                                match_feature_count=False)

        self.check_fdata_sanity(self.fdata_nuclei,
                                expected_feature_list,
                                prefix='Cytoplasm.',
                                match_feature_count=False)

        # Uncomment to generate ground truth
        # fdata.to_csv(os.path.join(
        #    TEST_DATA_DIR, 'Easy1_nuclei_haralick_features.csv'),
        #     index=False)

        fdata_gtruth = pd.read_csv(
            os.path.join(TEST_DATA_DIR, 'Easy1_nuclei_haralick_features.csv'))

        pd.testing.assert_frame_equal(fdata, fdata_gtruth)