[英]How can I remove the bright glare regions in image
I have some tomato images with bright shadow on tomatoes.我有一些番茄图像,番茄上有明亮的阴影。 I want to remove/reduce these bright shadow points.
我想删除/减少这些明亮的阴影点。 Is there any suggestion?
有什么建议吗?
I tried below code but It did not solve my problem:我尝试了下面的代码,但它没有解决我的问题:
def decrease_brightness(img, value=30):
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
lim = 255 - value
v[v >= lim] -= value
final_hsv = cv2.merge((h, s, v))
img = cv2.cvtColor(final_hsv, cv2.COLOR_HSV2BGR)
return img
image = decrease_brightness(image, value=50)
Here is how to do the inpainting in Python/OpenCV.以下是如何在 Python/OpenCV 中进行修复。
Note that shadows are dark.请注意,阴影是黑暗的。 You want to remove the bright glare regions.
您想要移除明亮的眩光区域。 Please use the correct terms so that you do not confuse others on the forum.
请使用正确的术语,以免在论坛上混淆其他人。 Refer to a dictionary.
参考字典。
Input:输入:
import cv2
import numpy as np
# read image
img = cv2.imread('tomato.jpg')
hh, ww = img.shape[:2]
# threshold
lower = (150,150,150)
upper = (240,240,240)
thresh = cv2.inRange(img, lower, upper)
# apply morphology close and open to make mask
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (7,7))
morph = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel, iterations=1)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (25,25))
morph = cv2.morphologyEx(morph, cv2.MORPH_DILATE, kernel, iterations=1)
# floodfill the outside with black
black = np.zeros([hh + 2, ww + 2], np.uint8)
mask = morph.copy()
mask = cv2.floodFill(mask, black, (0,0), 0, 0, 0, flags=8)[1]
# use mask with input to do inpainting
result1 = cv2.inpaint(img, mask, 101, cv2.INPAINT_TELEA)
result2 = cv2.inpaint(img, mask, 101, cv2.INPAINT_NS)
# write result to disk
cv2.imwrite("tomato_thresh.jpg", thresh)
cv2.imwrite("tomato_morph.jpg", morph)
cv2.imwrite("tomato_mask.jpg", mask)
cv2.imwrite("tomato_inpaint1.jpg", result1)
cv2.imwrite("tomato_inpaint2.jpg", result2)
# display it
cv2.imshow("IMAGE", img)
cv2.imshow("THRESH", thresh)
cv2.imshow("MORPH", morph)
cv2.imshow("MASK", mask)
cv2.imshow("RESULT1", result1)
cv2.imshow("RESULT2", result2)
cv2.waitKey(0)
Threshold Image:阈值图像:
Morphology and Floodfill Image:形态和填海图:
Mask Image:蒙版图片:
Inpaint Telea:修复 Telea:
Inpaint Navier-Stokes: Inpaint Navier-Stokes:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.