Home > Net >  Unable to assign a certain pixel value to an image
Unable to assign a certain pixel value to an image

Time:01-16

I assign a certain pixel intensity to a pixel value (255,0,0). I then save that image and reload it to find where that pixel intensity value is with numpy but I end up getting an empty array as output.

Here is my code:

import cv2

#read an img
img = cv2.imread('abc.jpg')

#assign pixel value
img[779,804] = (255,0,0)

#save img
cv2.imwrite('new_img.jpg', img)
read_img = cv2.imread('new_img.jpg')
intensity_val = np.where((read_img [:,:,0]==255)&(read_img [:,:,1]==0)&(read_img [:,:,2]==0))
print(intensity_val)

The output I get is:

(array([], dtype=int64), array([], dtype=int64))

I don't know why the output is empty array.

CodePudding user response:

Just for anyone who is curious, changing the extension of an image from .jpg to .png did the job.

  • Related