问题
Currently I am learning python and I'd like to get a little bit more into Data Compression. So I decided to try to code Run-Length Encoding(RLE).
From what I've read it can be useful when you try to compress pictures.
I would like to know what would be the easiest image-file-type for a beginner? How can I read out pixel RGB values or similar from a picture with python?
回答1:
As for the second part of your question: I would highly recommend OpenCV. It is very power for image processing and analysis. A very basic example of getting the pixel values of an image in Python using OpenCV:
import cv2
image = cv2.imread("some_image.jpg")
image[x, y, z]
This will return the value of the pixel at x, y, z
coordinates. Note that indexing begins at 0 so if you want to access the third RGB component, you have to do image[x, y, 2]
where x
and y
are the line and column.
来源:https://stackoverflow.com/questions/22456480/reading-and-compressing-a-picture-with-rle