[英]Change a pixel value
I have an image that I opened using LoadImageM
and I get the pixel data using Get2D
put I can't seem to find any built-in function to change a pixel value. 我有一个使用LoadImageM
打开的图像,并使用LoadImageM
获取了像素数据, Get2D
我似乎找不到任何内置函数来更改像素值。 I've tried using multiple things from Rectangle
to CV_RGB
but with no successful results. 我尝试使用从Rectangle
到CV_RGB
多种方法,但是没有成功的结果。
Consider checking out the new version of the opencv library. 考虑签出新版本的opencv库。
You import it with 您将其导入
import cv2
and it directly returns numpy arrays. 它直接返回numpy数组。
So for example if you do 例如,如果您这样做
image_array = cv2.imread('image.png')
then you can just access and change the pixels values by simply manipulating image_array
: 那么您可以通过简单地操作image_array
来访问和更改像素值:
image_array[0,0] = 100
sets the top left pixel to the value to 100. 将左上像素设置为100。
Depending on your installation, you may already have the cv2
bindings, so check if import cv2
works. 根据您的安装,您可能已经具有cv2
绑定,因此请检查import cv2
有效。
Otherwise just install opencv
and numpy
and you are good to go. 否则,只需安装opencv
和numpy
即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.