Commit 5d4ba4e9 authored by Sacha Pronost's avatar Sacha Pronost
Browse files

Update

parent ab68504d
Loading
Loading
Loading
Loading

convert_image_ss.ipynb

0 → 100644
+68 −0
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
import flash
from flash.core.data.utils import download_data
from flash.image import SemanticSegmentation, SemanticSegmentationData

import matplotlib.pyplot as plt
import numpy as np
import torch
import PIL
import os
import torch.utils.data.dataset
import torchvision.transforms as transforms
import torchvision.datasets as datasets
from torchvision.datasets import ImageFolder
```

%% Output

    C:\Users\sacha\anaconda3\envs\deepLearningVehicule\lib\site-packages\torchvision\models\_utils.py:252: UserWarning: Accessing the model URLs via the internal dictionary of the module is deprecated since 0.13 and may be removed in the future. Please access them via the appropriate Weights Enum instead.
      warnings.warn(

%% Cell type:code id: tags:

``` python
color_dict = {(0, 0, 0, 255): (0, 0, 0, 255),
              (70, 70, 70, 255): (1, 0, 0, 255),
              (100, 40, 40, 255): (2, 0, 0, 255),
              (55, 90, 80, 255): (3, 0, 0, 255),
              (220, 20, 60, 255): (4, 0, 0, 255),
              (153, 153, 153, 255): (5, 0, 0, 255),
              (157, 234, 50, 255): (6, 0, 0, 255),
              (128, 64, 128, 255): (7, 0, 0, 255),
              (244, 35, 232, 255): (8, 0, 0, 255),
              (107, 142, 35, 255): (9, 0, 0, 255),
              (0, 0, 142, 255): (10, 0, 0, 255),
              (102, 102, 156, 255): (11, 0, 0, 255),
              (220, 220, 0, 255): (12, 0, 0, 255),
              (70, 130, 180, 255): (13, 0, 0, 255),
              (81, 0, 81, 255): (14, 0, 0, 255),
              (150, 100, 100, 255): (15, 0, 0, 255),
              (230, 150, 140, 255): (16, 0, 0, 255),
              (180, 165, 180, 255): (17, 0, 0, 255),
              (250, 170, 30, 255): (18, 0, 0, 255),
              (110, 190, 160, 255): (19, 0, 0, 255),
              (170, 120, 50, 255): (20, 0, 0, 255),
              (45, 60, 150, 255): (21, 0, 0, 255),
              (145, 170, 100, 255): (22, 0, 0, 255)}
```

%% Cell type:code id: tags:

``` python
for i in range(10001,10002):
    im = PIL.Image.open('data3/Town01/generated/images_ss/' + str(i) + '.png')
    width, height = im.size
    #Créer une nouvelle image
    new_pixels = [(0, 0, 0,255)] * (width * height)
    for idx, pixel in enumerate(im.getdata()):
        if pixel in color_dict:
            new_pixels[idx] = color_dict[pixel]
    newim = PIL.Image.new(im.mode, im.size)
    newim.putdata(new_pixels)

    #Sauvegarder l'image
    newim.save('data3/Town01/generated/image_ss_new/' + str(i) + '.png')
```
Loading