图像像素及其颜色
我有一个灰度图像,我想将其分成像素,并确定图像的每个像素中的灰度。 需要以以下形式进行数组:( x,x的像素,y,灰色阴影0-255)。
1,1,25;
1,2,36;
1,3,50;
。 。 。
50,60,96;
。 。 。 如果图像为500 x 600个点,则最终应该得到 - (500,600,灰度)。
您能告诉我,如何从图像中获取如此多的数据?我需要做什么?我应该使用哪些库?如果有人解决了这样的问题,请举一个例子。非常感谢!
I have a grayscale image, I would like to split it into pixels and determine the grayscale in each pixel of the image.
The array is needed in the following form: (pixel by X, pixel by Y, gray shade 0-255).
1,1,25;
1,2,36;
1,3,50;
.
.
.
50,60,96;
.
.
.
if the image is 500 by 600 dots, then at the end it should get - (500,600, grayscale).
Could you tell me please, how can I get such an array of data from an image? What do I need to do? Which libraries should I use? If there is someone who has solved such a problem, please give an example. Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您已经有一个图像文件,则可以这样读取:
要获得一个数组:
如果它确实是8位灰度图像,则可以使用
image.open('image.png' ,mode ='l')
,但是在任何情况下,您总是可以使用ima [:,:,0]
获得红色通道。如果是灰度,则所有频道将相等。现在,您可以用坐标堆叠这些灰色级别:
If you already have an image file, you can read it like this:
To get this an an array:
If it's really an 8-bit greyscale image, you might be able to use
Image.open('image.png', mode='L')
, but in any case you can always just get the red channel withima[:, :, 0]
. If it's greyscale, all the channels will be equal.Now you can stack these grey levels with the coordinates:
我会这样做:
输出:
I would do this:
Output: