Python Forum

Full Version: Pillow alternative?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi, sorry for my bad English,
I tried to remove some lines of a webtoon picture if the line only contain 1 color
(it is just an example, I cannot share real images because it have "rights")
[attachment=2472]

from PIL import Image

Image.MAX_IMAGE_PIXELS = None

img = Image.open('01.png')
width = img.size[0] 
height = img.size[1]
print("height : ",height,"\nwidth: ",width)
for h in range(0,height):
    for w in range(0,width):
        pix = img.getpixel((h,w))
        print("y : ",h,", x : ",w,", RGB Value : ",pix)
    print(h,w)
    break #limit to easy debug
but when I use my code in real webtoon images (not image above), the result is wrong:
a line that I tested using the "pipet or color picker" tool using different software claims it is white or 255,255,255,
but when I use that code some result is

Output:
y : 1 , x : 696 , RGB Value : (157, 155, 166) y : 1 , x : 697 , RGB Value : (156, 154, 165) y : 1 , x : 698 , RGB Value : (155, 153, 164) y : 1 , x : 699 , RGB Value : (154, 152, 163) y : 1 , x : 700 , RGB Value : (152, 150, 161) y : 1 , x : 701 , RGB Value : (149, 147, 158) y : 1 , x : 702 , RGB Value : (139, 137, 148) y : 1 , x : 703 , RGB Value : (124, 122, 133) y : 1 , x : 704 , RGB Value : (90, 89, 97) y : 1 , x : 705 , RGB Value : (70, 69, 77) y : 1 , x : 706 , RGB Value : (68, 67, 72) y : 1 , x : 707 , RGB Value : (22, 22, 24) y : 1 , x : 708 , RGB Value : (0, 0, 0) y : 1 , x : 709 , RGB Value : (2, 2, 2) y : 1 , x : 710 , RGB Value : (0, 0, 0) y : 1 , x : 711 , RGB Value : (1, 1, 1) y : 1 , x : 712 , RGB Value : (0, 0, 0) y : 1 , x : 713 , RGB Value : (0, 0, 0)
is my code, method, or something i don't know?
or is there alternative package that i can use?

Edit : i use combine 1 chapter into 1 file, so the file is large
height : 130312
width: 720
Size : 44,9 MB (47.100.824 bytes)
Hi,
I would also use PIL for pixel peeping.
So without having tested it,my suggestion would be to make sure
that you are scanning the pixels in the right order.
You start with 0,0 0,1 ... etc and you name this height, width.
You are reading left-right, row by row.
Have you verified that this is the right order?
Paul
From Pillow documentation: https://pillow.readthedocs.io/en/stable/...Image.html

Quote:Image.getpixel(xy)
Returns the pixel value at a given position.

PARAMETERS:
xy – The coordinate, given as (x, y). See Coordinate System.

x is horizontal and y is vertical. Translating your code to use the correct coordinates.
for h in range(0,height):
    for w in range(0,width):
        pix = img.getpixel((w, h))
        print("y : ",h,", x : ",w,", RGB Value : ",pix)
    print(h,w)
(Jul-26-2023, 05:39 PM)deanhystad Wrote: [ -> ]From Pillow documentation: https://pillow.readthedocs.io/en/stable/...Image.html

Quote:Image.getpixel(xy)
Returns the pixel value at a given position.

PARAMETERS:
xy – The coordinate, given as (x, y). See Coordinate System.

x is horizontal and y is vertical. Translating your code to use the correct coordinates.
for h in range(0,height):
    for w in range(0,width):
        pix = img.getpixel((w, h))
        print("y : ",h,", x : ",w,", RGB Value : ",pix)
    print(h,w)

thank you, thank you
it was very stupid of me, I am so embarrassed
i will give you reputation point
The only stupid questions are the ones not asked!