Skip to content
Advertisement

Get Hex Color Code & Coordinate of The Pixel in A Image

imagine i have a 3×3 image & numbers as it’s pixel

JavaScript

using python i want value of each pixel in hex-color code line by line, like using above example as a image if a run the script i should get the output something like:

JavaScript

so please help me how can i achieve this output Note: My image in most cases will not be more than 100 pixels

I am Using Python3 & Debian based Linux Distro

Thanks for answering in advance

Edit: What I Tried is

JavaScript

But this is not giving me correct values

Advertisement

Answer

If you want to have iteration along the x-axis, you can write like:

JavaScript

Thinking of the for statement, x and y are going to change like (x,y) = (0,0), (0,1),… in your initial code. You want to first iterate over x and then iterate over y; you can write iteration over y, wrapping iteration over x.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement