Skip to content

Why are the patches always downscaled from 512 but not directly used as 256x256? #10

@GozdeUnver

Description

@GozdeUnver

In the paper it says that 256x256 sized patches are used but in the config file i2i_config.yml, the patch size is set to 512 and the downscale is set to 2, which means that original patches had the size of 512x512 and then they are resized to 256x256. What is the reason for this? Why can't we just directly use 256x256 sized patches?

Secondly in _get_shape() function, why is the original TMA image (~6kx6k) is padded all the time even though it could be actually divisible by 512? Because self.patch_size - h % self.patch_size is always greater than 0.

train:
  data:
    input_nc: 3
    output_nc: 3
    patch_size: 512
    downsample: 2
    max_src_samples: -1
    load_in_ram: true
# load previously extacted patches
def _load_patches(
            self,
            marker_patch_paths: [],
            core_name: str
    ) -> Tuple[List[Any], List[List[int]], List[str]]:
        # load pre-extracted patches and corresponding information
        paths = marker_patch_paths[core_name]
        patches = list()
        patch_coords = list()
        patch_paths = list()
        for path_ in paths:
            # load patch
            patch = Image.open(path_).convert('RGB')
            if self.downsample != 1:
                patch = patch.resize(self.downsampled_size, resample=Image.BILINEAR)
            patches.append(patch)

            # load patch co-ordinates
            basename = os.path.basename(path_)
            y = int(basename.rpartition('_y_')[2].rpartition('_x_')[0])
            x = int(basename.rpartition('_x_')[2].rpartition('_patch_')[0])
            if self.downsample != 1:
                y = int(y/self.downsample)
                x = int(x/self.downsample)
            patch_coords.append([y, x])

            # load patch paths
            patch_paths.append(os.path.basename(path_))

        return patches, patch_coords, patch_paths

# get the shape of TMA with padded pixels
def _get_shape(self, image_paths):
        image_shape = []
        for x in tqdm(image_paths):
            image = read_image(x)
            h, w, c = image.shape
            pad_h = self.patch_size - h % self.patch_size
            pad_w = self.patch_size - w % self.patch_size
            image = np.pad(image, ((0, pad_h), (0, pad_w), (0, 0)), mode='constant', constant_values=255)
            h, w, c = image.shape
            if self.downsample != 1:
                h = h // self.downsample
                w = w // self.downsample
            image_shape.append((c, h, w))
        return image_shape

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions