Liu*_*uan 12 python opencv image-processing
我想在使用OpenCV进行图像二值化之前删除阴影.我已经尝试过Otsu方法和自适应阈值处理,但是对于有大区域阴影的图像,这两种方法都不会给出好的结果.
更好的解决方案?提前致谢.
] 1
] 2
Dan*_*šek 23
你没有指定一种语言,所以我假设Python可以说明.
一个不错的起点可能是采用我在这个答案中展示的方法并将其扩展为使用多个渠道.
有点像
import cv2
import numpy as np
img = cv2.imread('shadows.png', -1)
rgb_planes = cv2.split(img)
result_planes = []
result_norm_planes = []
for plane in rgb_planes:
dilated_img = cv2.dilate(plane, np.ones((7,7), np.uint8))
bg_img = cv2.medianBlur(dilated_img, 21)
diff_img = 255 - cv2.absdiff(plane, bg_img)
norm_img = cv2.normalize(diff_img,None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8UC1)
result_planes.append(diff_img)
result_norm_planes.append(norm_img)
result = cv2.merge(result_planes)
result_norm = cv2.merge(result_norm_planes)
cv2.imwrite('shadows_out.png', result)
cv2.imwrite('shadows_out_norm.png', result_norm)
Run Code Online (Sandbox Code Playgroud)
非标准化结果如下:
并且归一化结果:
| 归档时间: |
|
| 查看次数: |
12963 次 |
| 最近记录: |