1

After changing the pixel values 255 to 1 on original image copy, seems that original image pixels are also changed and image is displayed as complete black.

#Load the image 
img = cv.imread('img/test.png', 0)

ret2, binarizedImage = cv.threshold(img, 127, 255, cv.THRESH_BINARY+cv.THRESH_OTSU)

cv.imshow('Binarized', binarizedImage) #This one displayes the image as expected

imageCopy= binarizedImage 
imageCopy[imageCopy==255]=1

cv.imshow('Binarized2', binarizedImage) # This one shows only black image

Can you please advise how can i manipulate imageCopy pixels without affecting original image pixel values?

ussrback
  • 491
  • 2
  • 8
  • 22

1 Answers1

2

ImageCopy is not really a copy. But a reference to the original object. The values you will change are affecting the same object with two references. You need to clone the original image object. Use .copy() to achieve that. See Clone an image in cv2 python for more info

CloudBalancing
  • 1,461
  • 2
  • 11
  • 22