Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pillow alternative?
#1
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")
   

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)
Reply
#2
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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#3
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)
kucingkembar likes this post
Reply
#4
(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
Reply
#5
The only stupid questions are the ones not asked!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Twilio alternative jmair 3 3,923 Feb-08-2024, 01:55 PM
Last Post: Sharmi
  Alternative for Cairosvg? Maryan 0 2,469 Oct-26-2020, 01:27 PM
Last Post: Maryan
  another alternative to np.interp evelynow 1 2,931 Aug-22-2019, 03:32 PM
Last Post: Larz60+
  Multithreading alternative MartinV279 1 2,803 Aug-01-2019, 11:41 PM
Last Post: scidam
  Array alternative oldcity 3 3,489 Oct-01-2018, 10:03 PM
Last Post: ichabod801
  If elif else alternative brocq_18 13 12,236 Apr-12-2017, 06:53 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020