7

I need to color a pixel in an image. I use opencv and python.
I tried img[x,y]=[255 255 255] to color a pixel(x,y) but it wont work :(

Is there is any mistake in this?
Can you suggest any method?

Thanks in advance.

3 Answers 3

7

img[x,y]=[255, 255, 255] is wrong because opencv img[a,b] is a matrics then you need to change x,y then you must use img[y,x]

actualy mistake in the order of x,y if you want to change color of point x,y use this >> img[y,x] = color

Sign up to request clarification or add additional context in comments.

Comments

7

Try it with comma's between the 255's:

img[y,x]=[255, 255, 255]

Comments

1

This works for me, just change it to load your own image:

import cv2

img = cv2.imread("C:\calibrate\chess\color001.jpg", cv2.CV_LOAD_IMAGE_COLOR);

## Make pixels row and column 300-400 black
img[300:400,300:400] = (0,0,0)

cv2.imshow('title',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

6 Comments

the code is (x,y),radius = cv2.minEnclosingCircle(cnt) . here (x,y) is a center point.I want to color the center point .so I use img[x,y] .Is this wrg? how can I represent the center point?
First try if my code is working for you to color pixels. Than you can say that this has answered you question. The other question -> print out the x,y coordinates and check if they are what you would expect. Perhaps 1 pxl is to small to see.
Ur code is wrking to color a block of pixels.I print x,y .The o/p is(97,417).It is x,y coordiante of a pixel.Am i ryt? I need to color a point img[97,417]=(0,0,0). For tat It is not wrking :(
You probably need to use img[417,97]=(0,0,0)
It shows the following error msg : " img[417,97]=(0,0,0) ValueError: setting an array element with a sequence. "
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.