示例#1
0
def split_image(image_fname, output_dir, tile_size, tile_step, image_margin):
    os.makedirs(output_dir, exist_ok=True)
    image = read_image_as_is(image_fname)
    image_id = id_from_fname(image_fname)

    slicer = ImageSlicer(image.shape, tile_size, tile_step, image_margin)
    tiles = slicer.split(image)

    fnames = []
    for i, tile in enumerate(tiles):
        output_fname = os.path.join(output_dir, f"{image_id}_tile_{i}.png")
        cv2.imwrite(output_fname, tile)
        fnames.append(output_fname)

    return fnames
示例#2
0
    def __getitem__(self, i):
        # read data
        image = fs.read_rgb_image(self.images_fps[i])
        mask = fs.read_image_as_is(self.masks_fps[i])
        assert mask.max() < len(CLASSES)

        # apply augmentations
        sample = self.transform(image=image, mask=mask)
        image, mask = sample['image'], sample['mask']

        return {
            "image_id": id_from_fname(self.images_fps[i]),
            "features": tensor_from_rgb_image(image),
            "targets": torch.from_numpy(mask).long()
        }
示例#3
0
def read_inria_mask(fname):
    mask = read_image_as_is(fname)
    return (mask > 0).astype(np.uint8)
示例#4
0
def read_inria_mask_with_pseudolabel(fname):
    mask = fs.read_image_as_is(fname).astype(np.float32) / 255.0
    return mask
示例#5
0
def read_inria_mask(fname):
    mask = fs.read_image_as_is(fname)
    if mask is None:
        raise IOError("Cannot read " + fname)
    cv2.threshold(mask, thresh=0, maxval=1, type=cv2.THRESH_BINARY, dst=mask)
    return mask
示例#6
0
def read_inria_mask_with_pseudolabel(fname):
    mask = fs.read_image_as_is(fname)
    mask[mask > UNLABELED_SAMPLE] = 1
    return mask