Esempio n. 1
0
def colors_in_image(uri) -> Set:
    """Returns set of colors that appears in the image.

    Args:
        uri: path to the image

    Returns:
        Set: colors that appears in the image
    """
    image = imread(uri, rootpath=args.in_dir)
    colors = np.unique(image.reshape(-1, image.shape[-1]), axis=0)
    result = {tuple(row) for row in colors.tolist()}  # np.array to hashable
    return result
    def preprocess(self, image_path: Path):
        image = imread(image_path, rootpath=str(self.in_dir))
        heigth, width = image.shape[:2]

        mask = np.zeros((heigth, width, len(self.index2color)), dtype=np.uint8)
        for index, color in self.index2color.items():
            mask[np.all((image == color), axis=-1), index] = 255

        target_path = self.out_dir / f"{image_path.stem}.tiff"
        target_path.parent.mkdir(parents=True, exist_ok=True)

        mimwrite_with_meta(
            target_path, np.dsplit(mask, mask.shape[2]), {"compress": 9}
        )
Esempio n. 3
0
    def _load_data(data_dir: Path) -> Tuple[torch.Tensor, torch.Tensor]:
        """
        Load data from train directory of the dataset.
        Parse names of images to get person id as labels.

        Args:
            data_dir: path to directory that contains training data
        Returns:
            images for training and their labels
        """
        filenames = list(data_dir.glob("*.jpg"))
        data = torch.from_numpy(np.array([imread(filename) for filename in filenames])).float()
        targets = torch.from_numpy(
            np.array([int(filename.name.split("_")[0]) for filename in filenames])
        )
        return data, targets
Esempio n. 4
0
    def _load_data(data_dir: Path) -> Tuple[torch.Tensor, Iterable, Iterable]:
        """
        Load data from directory.
        Parse names of images to get person ids as labels and camera ids.

        Args:
            data_dir: path to directory that contains data
        Returns:
            images, their labels and ids of the cameras that made the photos
        """
        # Gallery dataset contains good, junk and distractor images;
        # junk ones (marked as -1) should be neglected during evaluation.
        filenames = list(data_dir.glob("[!-]*.jpg"))
        data = torch.from_numpy(np.array([imread(filename) for filename in filenames])).float()
        pids = np.array([int(filename.name.split("_")[0]) for filename in filenames])
        cids = np.array([int(filename.name.split("_")[1][1:2]) for filename in filenames])
        return data, pids, cids
Esempio n. 5
0
def colors_in_image(uri) -> Set:
    image = imread(uri, rootpath=args.in_dir)
    colors = np.unique(image.reshape(-1, image.shape[-1]), axis=0)
    result = {tuple(row) for row in colors.tolist()}  # np.array to hashable
    return result