def augment_dataset(self, params, source_samples, tagrget_dir, range = None):
        patch_root = params.PATCHS_ROOT_PATH[source_samples[0]]
        sample_filename = source_samples[1]
        train_list = "{}/{}".format(patch_root, sample_filename)

        Xtrain, Ytrain = read_csv_file(patch_root, train_list)
        if range is not None:
            Xtrain = Xtrain[range[0]:range[1]]
            Ytrain = Ytrain[range[0]:range[1]]

        target_cancer_path = "{}/{}_cancer".format(patch_root, tagrget_dir)
        target_normal_path = "{}/{}_noraml".format(patch_root, tagrget_dir)

        if (not os.path.exists(target_cancer_path)):
            os.makedirs(target_cancer_path)
        if (not os.path.exists(target_normal_path)):
            os.makedirs(target_normal_path)

        for K, (x, y) in enumerate(zip(Xtrain, Ytrain)):
            block = Block()
            block.load_img(x)
            img = block.get_img()

            aug_img = self.augment_images(img) * 255
            block.set_img(aug_img)
            block.opcode = self.opcode

            if y == 0:
                block.save_img(target_normal_path)
            else:
                block.save_img(target_cancer_path)

            if (0 == K % 1000):
                print("{} augmenting >>> {}".format(time.asctime(time.localtime()), K))
예제 #2
0
    def get_image_block(self, fScale, c_x, c_y, nWidth, nHeight):
        '''
        在指定坐标和倍镜下,提取切片的图块
        :param fScale: 倍镜数
        :param c_x: 中心x
        :param c_y: 中心y
        :param nWidth: 图块的宽
        :param nHeight: 图块的高
        :return: 返回一个图块对象
        '''
        data = self._slide.get_image_block(fScale, c_x, c_y, nWidth, nHeight)

        newBlock = Block(self.slice_id, c_x, c_y, fScale, 0, nWidth, nHeight)
        newBlock.set_img(data)
        return newBlock