Le deal à ne pas rater :
Pokémon EV06 : où acheter le Bundle Lot 6 Boosters Mascarade ...
Voir le deal

Projet ISN

2 participants

Aller en bas

Projet ISN Empty Projet ISN

Message  cquentin Sam 13 Mai - 22:25

Bonjour,

j'ai un projet qui consiste a prendre les pixels d'une image pour les modifier et simuler une vue de daltonien.
J'ai un programme (je le mets ci-dessous) mais celui ne marche qu'avec une image donnée or je dois faire pour qu'on puisse choisir n'importe quelle image et que l'image modifiée et celle non modifier s'affiche sur une fenêtre canvas.
Je cherche donc a créer une barre d'outil pour pouvoir réaliser ce que je souhaite mais je n'y arrive pas... (ou il y a peut être une méthode pus simple)
J’espère que vous pourrez m'aider...

Code:
from tkinter import *
from PIL import Image

def deutenaropie1():
   ImageSource = Image.open("images.png")
   largeur,hauteur = ImageSource.size
   ImageCible=Image.new("RGB",(largeur,hauteur))

   w1=0.43
   w2=0.69
   w3=-0.11
   w4=0.34
   w5=0.59
   w6=0.07
   w7=-0.01
   w8=0.02
   w9=0.99

   for y in range(1,hauteur-2) :
       for x in range(1,largeur-2) :
           p=ImageSource.getpixel((x,y))
           a=ImageSource.getpixel((x-1,y-1))
           n=ImageSource.getpixel((x-1,y))
           c=ImageSource.getpixel((x-1,y+1))
           d=ImageSource.getpixel((x,y-1))
           e=ImageSource.getpixel((x,y+1))
           f=ImageSource.getpixel((x+1,y-1))
           g=ImageSource.getpixel((x+1,y))
           h=ImageSource.getpixel((x+1,y+1))

           r=int(w1*p[0]+w2*p[1]+w3*p[2])
           v=int(w4*p[0]+w5*p[1]+w6*p[2])
           b=int(w7*p[0]+w8*p[1]+w9*p[2])
           q=(r,v,b)
           ImageCible.putpixel((x,y),q)

   ImageCible.save("imagesmodif.png")
   ImageCible.show()


def protanopie1():
   ImageSource = Image.open("images.png")
   largeur,hauteur = ImageSource.size
   ImageCible=Image.new("RGB",(largeur,hauteur))

   w1=0.56
   w2=0.43
   w3=0
   w4=0.55
   w5=0.44
   w6=0
   w7=0
   w8=0.24
   w9=0.75

   for y in range(1,hauteur-2) :
       for x in range(1,largeur-2) :
           p=ImageSource.getpixel((x,y))
           a=ImageSource.getpixel((x-1,y-1))
           n=ImageSource.getpixel((x-1,y))
           c=ImageSource.getpixel((x-1,y+1))
           d=ImageSource.getpixel((x,y-1))
           e=ImageSource.getpixel((x,y+1))
           f=ImageSource.getpixel((x+1,y-1))
           g=ImageSource.getpixel((x+1,y))
           h=ImageSource.getpixel((x+1,y+1))

           r=int(w1*p[0]+w2*p[1]+w3*p[2])
           v=int(w4*p[0]+w5*p[1]+w6*p[2])
           b=int(w7*p[0]+w8*p[1]+w9*p[2])
           q=(r,v,b)
           ImageCible.putpixel((x,y),q)

   ImageCible.save("imagesmodif.png")
   ImageCible.show()

def tritanopie1():
   ImageSource = Image.open("images.png")
   largeur,hauteur = ImageSource.size
   ImageCible=Image.new("RGB",(largeur,hauteur))

   w1=0.95
   w2=0.05
   w3=0
   w4=0
   w5=0.83
   w6=0.17
   w7=0
   w8=0.87
   w9=0.12

   for y in range(1,hauteur-2) :
       for x in range(1,largeur-2) :
           p=ImageSource.getpixel((x,y))
           a=ImageSource.getpixel((x-1,y-1))
           n=ImageSource.getpixel((x-1,y))
           c=ImageSource.getpixel((x-1,y+1))
           d=ImageSource.getpixel((x,y-1))
           e=ImageSource.getpixel((x,y+1))
           f=ImageSource.getpixel((x+1,y-1))
           g=ImageSource.getpixel((x+1,y))
           h=ImageSource.getpixel((x+1,y+1))

           r=int(w1*p[0]+w2*p[1]+w3*p[2])
           v=int(w4*p[0]+w5*p[1]+w6*p[2])
           b=int(w7*p[0]+w8*p[1]+w9*p[2])
           q=(r,v,b)
           ImageCible.putpixel((x,y),q)

   ImageCible.save("imagesmodif.png")
   ImageCible.show()

def monochromatisme1():

   w1=0.33
   w2=0.33
   w3=0.33
   w4=0.33
   w5=0.33
   w6=0.33
   w7=0.33
   w8=0.33
   w9=0.33

   for y in range(1,hauteur-2) :
       for x in range(1,largeur-2) :
           p=ImageSource.getpixel((x,y))
           a=ImageSource.getpixel((x-1,y-1))
           n=ImageSource.getpixel((x-1,y))
           c=ImageSource.getpixel((x-1,y+1))
           d=ImageSource.getpixel((x,y-1))
           e=ImageSource.getpixel((x,y+1))
           f=ImageSource.getpixel((x+1,y-1))
           g=ImageSource.getpixel((x+1,y))
           h=ImageSource.getpixel((x+1,y+1))

           r=int(w1*p[0]+w2*p[1]+w3*p[2])
           v=int(w4*p[0]+w5*p[1]+w6*p[2])
           b=int(w7*p[0]+w8*p[1]+w9*p[2])
           q=(r,v,b)
           ImageCible.putpixel((x,y),q)

ImageCible.save("imagesmodif.png")
   ImageCible.show()


fenetre=Tk()
fenetre.geometry("400x250")
fenetre.title("convertisseur d'image")
label= Label(fenetre, text="choisissez votre type de daltonisme", width=30)
label.pack()
bouton1=Button(fenetre, text="deuteranopie", command=deutenaropie1)
bouton2=Button(fenetre, text="protanopie",command=protanopie1)
bouton3=Button(fenetre, text="tritanopie", command=tritanopie1)
bouton4=Button(fenetre, text="monochromatisme", command=monochromatisme1)
bouton1.pack()
bouton2.pack()
bouton3.pack()
bouton4.pack()
fenetre.mainloop()

cquentin

Messages : 2
Date d'inscription : 13/05/2017

Revenir en haut Aller en bas

Projet ISN Empty Re: Projet ISN

Message  Pyt Sam 13 Mai - 22:32

Bonsoir cquentin,

Je ne suis pas sûre qu'en balançant ton code sans même te présenter sur le forum soit très "productif".

Au moins l'appel est lancé.


Pyt
Pyt
Pyt
Admin

Messages : 48
Date d'inscription : 19/04/2017
Localisation : Près de Clermont-Ferrand

https://apprendrepython.forumactif.com

Revenir en haut Aller en bas

Projet ISN Empty Re: Projet ISN

Message  cquentin Sam 13 Mai - 22:39

Bonsoir,

Je pensais que c’était un forum pour se faire aider, pas un site de rencontre.

cquentin

Messages : 2
Date d'inscription : 13/05/2017

Revenir en haut Aller en bas

Projet ISN Empty Re: Projet ISN

Message  Pyt Sam 13 Mai - 22:47

Pas mal, la blague !

J'ai lancé un appel sur twitter également.

Pyt
Pyt
Pyt
Admin

Messages : 48
Date d'inscription : 19/04/2017
Localisation : Près de Clermont-Ferrand

https://apprendrepython.forumactif.com

Revenir en haut Aller en bas

Projet ISN Empty Re: Projet ISN

Message  Contenu sponsorisé


Contenu sponsorisé


Revenir en haut Aller en bas

Revenir en haut


 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum