Untitled

 avatar
unknown
python
8 days ago
753 B
1
Indexable
    def __getitem__(self, idx):
        img_path = self.image_paths[idx]
        mask_path = self.mask_paths[idx]

        # Carica le immagini come array numpy
        image = np.array(Image.open(img_path).convert('RGB'))
        mask = np.array(Image.open(mask_path).convert('L'))

        # Applica le trasformazioni Albumentations
        if self.transform:
            augmented = self.transform(image=image, mask=mask)
            image = augmented['image']
            mask = augmented['mask']

        # Converti in tensore e normalizza
        image = torch.from_numpy(image.transpose(2, 0, 1)).float() / 255.0
        mask = torch.from_numpy(mask).unsqueeze(0).float()
        mask = (mask > 128).float()

        return image, mask.squeeze(0)
Leave a Comment