I want to change specific pixel value in whole image.I have converted image into List using img.getdata() function.now after processing i want to convert that list into image format.please suggest me if you know any way to do so.
import cv2
import numpy as np
from PIL import Image
img = Image.open('test.jpg','r')
pix=list(img.getdata())
for i in pix:
if i ==(254,0,0):
print("found",i)
pi=np.array(pix)
pi=Image.fromarray(pi)
cv2.imshow("img",pi)
Error is
Traceback (most recent call last):
File "C:\Python38\pixels.py", line 19, in <module>
cv2.imshow("img",pi)
TypeError: Expected Ptr<cv::UMat> for argument 'mat'
i have tried some other way also but not able to see image.


forloop? That will be horribly slow and hard to debug - look at some other PIL/OpenCV questions on Stack Overflow and start thinking about using Numpy or OpenCV vectorised operations.pi.show()- you can't display a PIL Image with OpenCV which expects a Numpy array.PILyou can compare full image usingimg1 == img2and if they have channels in different order then they will be different. If you convert to numpy array then you can compare regions(img[y1:y2,x1:x2] == img[y3:y4,x3:x4]).all(axis=2).all()