def fit(self, I):
        """
        Fit to an image I.

        :param I:
        :return:
        """
        self.image_shape = I.shape
        self.stain_matrix = self.extractor.get_stain_matrix(I)
        self.source_concentrations = get_concentrations(I, self.stain_matrix)
        self.n_stains = self.source_concentrations.shape[1]
        self.tissue_mask = LuminosityThresholdTissueLocator.get_tissue_mask(I).ravel()
    def fit_transform(self, target):
        """Fit and transform a target image

        :param target: Image RGB uint8.
        :return:
        """
        self.stain_matrix_target = self.extractor.get_stain_matrix(target)
        self.target_concentrations = get_concentrations(
            target, self.stain_matrix_target)
        self.stain_matrix_target_RGB = convert_OD_to_RGB(
            self.stain_matrix_target)  # useful to visualize.
        tmp = 255 * np.exp(
            -1 * np.dot(self.target_concentrations, self.stain_matrix_target))
        return tmp.reshape(target.shape).astype(np.uint8)
Exemple #3
0
    def transform(self, I):
        """
        Transform an image.

        :param I: Image RGB uint8.
        :return:
        """
        stain_matrix_source = self.extractor.get_stain_matrix(I)
        source_concentrations = get_concentrations(I, stain_matrix_source)
        maxC_source = np.percentile(source_concentrations, 99, axis=0).reshape(
            (1, 2))
        source_concentrations *= (self.maxC_target / maxC_source)
        tmp = 255 * np.exp(
            -1 * np.dot(source_concentrations, self.stain_matrix_target))
        return tmp.reshape(I.shape).astype(np.uint8)
Exemple #4
0
    def fit(self, target):
        """
        Fit to a target image.

        :param target: Image RGB uint8.
        :return:
        """
        self.stain_matrix_target = self.extractor.get_stain_matrix(target)
        self.target_concentrations = get_concentrations(
            target, self.stain_matrix_target)
        self.maxC_target = np.percentile(self.target_concentrations,
                                         99,
                                         axis=0).reshape((1, 2))
        self.stain_matrix_target_RGB = convert_OD_to_RGB(
            self.stain_matrix_target)  # useful to visualize.
Exemple #5
0
 pict_name = img_num[i]
 picture_name1 = img_num[i].split('-')
 picture_name2 = ''
 for s in picture_name1[:-2]:
     picture_name2 = picture_name2 + s + '-'
 picture_name2 = picture_name2[:-4]
 print(picture_name2)
 sum_dir = '/cptjack/totem/barrylee/cut_small_cell/cell_tri-classification/train54-' + img_name + '/'
 I_raw = cv2.imread(img_dir + pict_name)
 biaozhu_raw = cv2.imread(biaozhu_img)
 print(biaozhu_img)
 flag_path = pict_name.split('.')[0]
 I = cv2.cvtColor(I_raw, cv2.COLOR_BGR2RGB)
 I_gray = cv2.cvtColor(I, cv2.COLOR_BGR2GRAY)
 stain_matrix_source = extractor.get_stain_matrix(I)  # ,regularizer=0.8)
 source_concentrations = get_concentrations(
     I, stain_matrix_source)  # , regularizer=0.1)
 b = source_concentrations.reshape(
     (I.shape[0], I.shape[1], 2)).astype(np.uint8)
 # 打开保存的npy格式的mask文件
 with open(mask_dir + pict_name.split('.')[0] + '.npy', 'rb') as fr:
     print(mask_dir + pict_name.split('.')[0] + '.npy')
     mask = np.load(fr)
 mask_sum = []
 cnt_list = []
 # 将轮廓和面积存入一个变量
 for j in range(mask.shape[2]):
     outline = mask[:, :, j]
     outline = outline.astype(np.uint8)
     # print(outline)
     image, contours, hierarchy = cv2.findContours(outline, cv2.RETR_TREE,
                                                   cv2.CHAIN_APPROX_NONE)