Leo
Leo

Reputation: 1139

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. I've tried using multiple things from Rectangle to CV_RGB but with no successful results.

Upvotes: 0

Views: 4532

Answers (1)

entropiece
entropiece

Reputation: 389

Consider checking out the new version of the opencv library.

You import it with

import cv2

and it directly returns numpy arrays.

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[0,0] = 100

sets the top left pixel to the value to 100.

Depending on your installation, you may already have the cv2 bindings, so check if import cv2 works.

Otherwise just install opencv and numpy and you are good to go.

Upvotes: 5

Related Questions