Farbe von Pixeln ermitteln
Verfasst: Mittwoch 13. Mai 2020, 17:53
Hallo Leute,
beim Versuch die Farbe von Pixeln eines Bildes zu ermitteln habe ich mit dem Programm:
import tkinter
root = tkinter.Tk()
cc = tkinter.Canvas(root, width='400', height='200')
cc.create_polygon(0,0,100,0,100,100,0,100,fill="#000000")
cc.create_polygon(0,100,100,100,100,200,0,200,fill="#ffffff")
cc.create_polygon(100,0,200,0,200,100,100,100,fill="#ff0000")
cc.create_polygon(200,0,300,0,300,100,200,100,fill="#00ff00")
cc.create_polygon(300,0,400,0,400,100,300,100,fill="#0000ff")
cc.create_polygon(100,100,200,100,200,200,100,200,fill="#00ffff")
cc.create_polygon(200,100,300,100,300,200,200,200,fill="#ff00ff")
cc.create_polygon(300,100,400,100,400,200,300,200,fill="#ffff00")
cc.pack()
ein Rechteck (Breite 400, Höhe 200) erstellt und darauf acht verschieden gefärbte Quadrate angeordnet. Von dem Rechteck habe ich ein Bildschirmfoto der Größe 400*200 als .jpg-file gesichert.
Wenn ich mit einem zweiten Programm:
from PIL import Image
im = Image.open('Farben.jpg')
pix = im.load()
print (im.size)
print (pix[100,100])
print (pix[300,100])
print (pix[500,100])
print (pix[700,100])
print (pix[100,300])
print (pix[300,300])
print (pix[500,300])
print (pix[700,300])
die Größe des Rechtecks ausdrucken lasse, erhalte ich 800*402 statt 400*200 und nach entsprechender Korrektur der Koordinaten die folgende Angabe der Farben:
Größe:
(800, 402) statt (400, 200)
Farben:
(0, 0, 0) ok
(233, 50, 36) statt (255, 0, 0)
(123, 249, 79) statt (0, 255, 0)
(0, 34, 245) statt (0, 0, 255)
(255, 255, 255) ok
(119, 251, 253) statt (0, 255, 255)
(232, 62, 246) statt (255, 0, 255)
(255, 253, 86) statt (255, 255, 0)
Was mache ich falsch und wie wäre es richtig?
Vielen Dank für eure Hilfe.
beim Versuch die Farbe von Pixeln eines Bildes zu ermitteln habe ich mit dem Programm:
import tkinter
root = tkinter.Tk()
cc = tkinter.Canvas(root, width='400', height='200')
cc.create_polygon(0,0,100,0,100,100,0,100,fill="#000000")
cc.create_polygon(0,100,100,100,100,200,0,200,fill="#ffffff")
cc.create_polygon(100,0,200,0,200,100,100,100,fill="#ff0000")
cc.create_polygon(200,0,300,0,300,100,200,100,fill="#00ff00")
cc.create_polygon(300,0,400,0,400,100,300,100,fill="#0000ff")
cc.create_polygon(100,100,200,100,200,200,100,200,fill="#00ffff")
cc.create_polygon(200,100,300,100,300,200,200,200,fill="#ff00ff")
cc.create_polygon(300,100,400,100,400,200,300,200,fill="#ffff00")
cc.pack()
ein Rechteck (Breite 400, Höhe 200) erstellt und darauf acht verschieden gefärbte Quadrate angeordnet. Von dem Rechteck habe ich ein Bildschirmfoto der Größe 400*200 als .jpg-file gesichert.
Wenn ich mit einem zweiten Programm:
from PIL import Image
im = Image.open('Farben.jpg')
pix = im.load()
print (im.size)
print (pix[100,100])
print (pix[300,100])
print (pix[500,100])
print (pix[700,100])
print (pix[100,300])
print (pix[300,300])
print (pix[500,300])
print (pix[700,300])
die Größe des Rechtecks ausdrucken lasse, erhalte ich 800*402 statt 400*200 und nach entsprechender Korrektur der Koordinaten die folgende Angabe der Farben:
Größe:
(800, 402) statt (400, 200)
Farben:
(0, 0, 0) ok
(233, 50, 36) statt (255, 0, 0)
(123, 249, 79) statt (0, 255, 0)
(0, 34, 245) statt (0, 0, 255)
(255, 255, 255) ok
(119, 251, 253) statt (0, 255, 255)
(232, 62, 246) statt (255, 0, 255)
(255, 253, 86) statt (255, 255, 0)
Was mache ich falsch und wie wäre es richtig?
Vielen Dank für eure Hilfe.