图片去栅栏的代码实现

整个项目可以看:https://github.com/zhangbo2008/remove_railings_in_cv2



# writer:wojianxinygcl@163.com
#=============非常奇怪的一点, cv2保存傅里叶图片有黑图的bug, 用plt存就没问题了!!!!!!!!!!!\\\\\\


'''
原理:
https://baijiahao.baidu.com/s?id=1671643511992284379&wfr=spider&for=pc



'''


# date : 2020.3.30

import cv2 as cv

import numpy as np

from matplotlib import pyplot as plt

#读取图像

img = cv.imread('tmp.png', 0)

#傅里叶变换

f = np.fft.fft2(img)

fshift = np.fft.fftshift(f) # 把左上角的顶点,平移到中心.为了观看效果.

# fshift = np.uint8(fshift)
# #quzao
# import cv2
# fshift=cv2.fastNlMeansDenoisingColored(fshift, None, 10, 10, 7, 21)

if 1:
sigma=0.0001
width, height = img.shape
centX = int(height / 2)
centY = int(width / 2)
Gauss_map1 = np.ones((width, height))
# Gauss_map1[wi]
canshu=0.01
Gauss_map1[0:width//2-int(width*canshu),int(height)//2]=0
Gauss_map1[width//2+int(width*canshu):,int(height)//2]=0
plt.close()
plt.imshow(Gauss_map1, 'gray')
plt.savefig('3.png')
fshift=fshift*Gauss_map1
plt.close()
plt.imshow(np.log(np.abs(fshift)) ) # res 只是为了观看., 'gray')
plt.savefig('4.png')
#查看fshift










#傅里叶逆变换

ishift = np.fft.ifftshift(fshift)

iimg = np.fft.ifft2(ishift)

iimg = np.abs(iimg)

plt.close()
plt.imshow(iimg) # res 只是为了观看., 'gray')
plt.savefig('5.png') # 最终去除掉栅栏的图片纯成5.png


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

15122306087

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

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

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

打赏作者

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

抵扣说明:

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

余额充值