【问题标题】:OpenCV image copy pixel value manipulation changes original image [duplicate]OpenCV图像复制像素值操作更改原始图像[重复]
【发布时间】:2021-05-05 03:29:38
【问题描述】:

将原始图像副本上的像素值 255 更改为 1 后,似乎原始图像像素也发生了变化,图像显示为全黑。

#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

您能否告诉我如何在不影响原始图像像素值的情况下操作 imageCopy 像素?

【问题讨论】:

  • 通过.copy()方法创建图像的深层副本:imageCopy = binarizedImage.copy()

标签: python opencv image-processing opencv-python


【解决方案1】:

ImageCopy 并不是真正的副本。而是对原始对象的引用。您将更改的值会影响具有两个引用的同一个对象。您需要克隆原始图像对象。使用 .copy() 来实现这一点。请参阅Clone an image in cv2 python 了解更多信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 1970-01-01
    • 2019-05-04
    相关资源
    最近更新 更多