示例#1
0
    def test_DataParser_save_sample(self):
        data_parser = DataParser(' ')
        data_parser.set_result_path(self._result_path)
        for line in self._link:
            try:
                """ generate results """
                dicom_file_path = os.path.join(self._data_path, line)
                contour_file_path = os.path.join(self._data_path,
                                                 self._link[line])
                shape, img, mask, contour = data_parser.parse_sample(
                    dicom_file_path, contour_file_path)
                data_parser.save_sample(
                    os.path.splitext(line)[0], shape, img, mask, contour)
                """ Load baseline and do the comparison """
                with h5py.File(os.path.join(self._baseline_path, 'data.h5'),
                               'r') as hf:
                    sample = hf[os.path.splitext(line)[0]]
                    equal1 = np.array_equal(np.array(sample['shape']), shape)
                    equal2 = np.array_equal(np.array(sample['img']), img)
                    equal3 = np.array_equal(np.array(sample['mask']), mask)
                if (not (equal1 and equal2 and equal3)):
                    return False
            except:
                return False

        return True