阴影检测

文章公布了深度学习相关文章的代码与结果,链接为https://github.com/xw-hu/DSC ,还在个人主页https://xw-hu.github.io/ 上传了更多相关资料。此外提到matlab对大阴影有效,还给出了图像阴影检测与去除的代码链接https://github.com/kittenish/Image-Shadow-Detection-and-Removal 。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

深度学习的:

我们公布了文章的代码与结果(https://github.com/xw-hu/DSC),同时在个人主页上传了更多相关的资料(https://xw-hu.github.io/ )。

 

这个对小阴影无效

这个是matlab,也是对大阴影有效

https://github.com/kittenish/Image-Shadow-Detection-and-Removal

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-


# -*- coding: utf-8 -*-
import numpy as np
import cv2
from skimage.morphology import remove_small_objects
im1=cv2.imread(r'd:/shudong.jpg')
b,g,r=np.double(cv2.split(im1))
shadow_ratio = (4/np.pi)*np.arctan2((b-g),(b+g)) #mutiply 4/pi is to ensure value[0,1]
shadow_mask=shadow_ratio>0.2
#cv2.imshow("shadow_mask",np.uint8(shadow_mask*255))
shadow_mask[:5,:]=0
shadow_mask[-5:,:]=0
shadow_mask[:,:5]=0
shadow_mask[:,-5:]=0#边界上的值=0
#cv2.imshow("shadow_mask1",np.uint8(shadow_mask*255))
shadow_mask=remove_small_objects(shadow_mask, min_size=10, connectivity=3)
# opencv 中没有matlab 中类似bwareaopen的函数,二值图像面积开运算
cv2.imshow("shadow_mask1",np.uint8(shadow_mask*255))
kernel=cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
kernel[1,0]=0
kernel[3,0]=0
kernel[1,4]=0
kernel[3,4]=0
shadow_mask1=np.uint8(shadow_mask*1)
mask=cv2.dilate(shadow_mask1,kernel)-shadow_mask1
#cv2.imshow("boundary",np.uint8(mask*255))
#substarct shadow_mask is to get boundary
#get boundary
[row,col]=np.where(mask==1)
#for i in range(len(row)-1):
#    cv2.line(im1,(col[i],row[i]),(col[i+1],row[i+1]),(0,0,255),1)
im1[row,col,:]=im1[40,40,:]
cv2.imshow("original-shadow",im1)
cv2.waitKey(0)

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值