How can get the RGB values of every pixel in an image and after it gets all the values of the first row?
Script:
JavaScript
x
15
15
1
image = input("image:")
2
im = Image.open(image)
3
pix = im.load()
4
width, height = im.size
5
x = 0
6
y = 0
7
8
# For each pixel in the Y
9
while (y < height):
10
# For each pixel in the X
11
while (x < width):
12
print pix[x,y]
13
x = x + 1
14
y = y + 1
15
Advertisement
Answer
The way you initialize your x and y values is the problem. X should be initialized back to zero immediately before the second while loop, so that the count starts again for the width of the next row.
Something like:
JavaScript
1
11
11
1
x = 0
2
y = 0
3
#for each pixel in the Y
4
while (y < height):
5
# for each pixel in the X
6
x = 0 #start counting again for the next row
7
while (x < width):
8
print pix[x,y]
9
x = x + 1
10
y = y + 1
11
Your loop freezes, because at the end of the first row, x=width and you forget to reset it back to zero for the second iteration of the first while loop.