图像中缺少一些损坏的部分(使用python进行图像处理)

2024-09-27 07:35:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图显示图像的受损部分,以便恢复它们。我对图像处理非常陌生,我正在使用cv2。以下是我正在制作的图片

original damaged image

required mask image

我得到以下图像:

Output

import cv2
dim = (512,512)
im_color = cv2.imread("couple.png", cv2.IMREAD_COLOR)
im_color = cv2.resize(im_color,dim)
im_gray = cv2.cvtColor(im_color, cv2.COLOR_BGR2GRAY)
mask = cv2.threshold(im_gray, thresh=200, maxval=255, type=cv2.THRESH_BINARY)
im_thresh_gray = cv2.bitwise_and(im_gray, mask[0])
mask3 = cv2.cvtColor(mask[1], cv2.COLOR_GRAY2BGR)
im_thresh_color = cv2.bitwise_and(im_color, mask3)
cv2.imshow("original image", im_color)
cv2.imshow("binary mask", mask[1])
cv2.imshow("3 channel mask", mask3)
cv2.imshow("im_thresh_gray", im_thresh_gray)
cv2.imshow("im_thresh_color", im_thresh_color)
cv2.imwrite("repaired.png",mask3)
cv2.waitKey(0)

一些损坏的零件丢失了。谁能帮帮我吗


Tags: 图像imagepngmaskcv2colordimimshow

热门问题