Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
a4bffd96
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a4bffd96
编写于
8月 18, 2012
作者:
A
Alexander Mordvintesv
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added deconvolution.py sample and example images
上级
19462c87
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
118 addition
and
0 deletion
+118
-0
samples/python2/data/licenseplate_motion.jpg
samples/python2/data/licenseplate_motion.jpg
+0
-0
samples/python2/data/text_defocus.jpg
samples/python2/data/text_defocus.jpg
+0
-0
samples/python2/data/text_motion.jpg
samples/python2/data/text_motion.jpg
+0
-0
samples/python2/deconvolution.py
samples/python2/deconvolution.py
+118
-0
未找到文件。
samples/python2/data/licenseplate_motion.jpg
0 → 100644
浏览文件 @
a4bffd96
此差异由.gitattributes 抑制。
samples/python2/data/text_defocus.jpg
0 → 100644
浏览文件 @
a4bffd96
此差异由.gitattributes 抑制。
samples/python2/data/text_motion.jpg
0 → 100644
浏览文件 @
a4bffd96
此差异由.gitattributes 抑制。
samples/python2/deconvolution.py
0 → 100644
浏览文件 @
a4bffd96
'''
Wiener deconvolution.
Sample shows how DFT can be used to perform Weiner deconvolution [1]
of an image with user-defined point spread function (PSF)
Usage:
deconvolution.py [--circle]
[--angle <degrees>]
[--d <diameter>]
[--snr <signal/noise ratio in db>]
[<input image>]
Use sliders to adjust PSF paramitiers.
Keys:
SPACE - switch btw linear/cirular PSF
ESC - exit
Examples:
deconvolution.py --angle 135 --d 22 data/licenseplate_motion.jpg
(image source: http://www.topazlabs.com/infocus/_images/licenseplate_compare.jpg)
deconvolution.py --angle 86 --d 31 data/text_motion.jpg
deconvolution.py --circle --d 19 data/text_defocus.jpg
(image source: compact digital photo camera, no artificial distortion)
[1] http://en.wikipedia.org/wiki/Wiener_deconvolution
'''
import
numpy
as
np
import
cv2
from
common
import
nothing
def
blur_edge
(
img
,
d
=
31
):
h
,
w
=
img
.
shape
[:
2
]
img_pad
=
cv2
.
copyMakeBorder
(
img
,
d
,
d
,
d
,
d
,
cv2
.
BORDER_WRAP
)
img_blur
=
cv2
.
GaussianBlur
(
img_pad
,
(
2
*
d
+
1
,
2
*
d
+
1
),
-
1
)[
d
:
-
d
,
d
:
-
d
]
y
,
x
=
np
.
indices
((
h
,
w
))
dist
=
np
.
dstack
([
x
,
w
-
x
-
1
,
y
,
h
-
y
-
1
]).
min
(
-
1
)
w
=
np
.
minimum
(
np
.
float32
(
dist
)
/
d
,
1.0
)
return
img
*
w
+
img_blur
*
(
1
-
w
)
def
motion_kernel
(
angle
,
d
,
sz
=
65
):
kern
=
np
.
ones
((
1
,
d
),
np
.
float32
)
c
,
s
=
np
.
cos
(
angle
),
np
.
sin
(
angle
)
A
=
np
.
float32
([[
c
,
-
s
,
0
],
[
s
,
c
,
0
]])
sz2
=
sz
//
2
A
[:,
2
]
=
(
sz2
,
sz2
)
-
np
.
dot
(
A
[:,:
2
],
((
d
-
1
)
*
0.5
,
0
))
kern
=
cv2
.
warpAffine
(
kern
,
A
,
(
sz
,
sz
),
flags
=
cv2
.
INTER_CUBIC
)
return
kern
def
defocus_kernel
(
d
,
sz
=
65
):
kern
=
np
.
zeros
((
sz
,
sz
),
np
.
uint8
)
cv2
.
circle
(
kern
,
(
sz
,
sz
),
d
,
255
,
-
1
,
cv2
.
CV_AA
,
shift
=
1
)
kern
=
np
.
float32
(
kern
)
/
255.0
return
kern
if
__name__
==
'__main__'
:
print
__doc__
import
sys
,
getopt
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
''
,
[
'circle'
,
'angle='
,
'd='
,
'snr='
])
opts
=
dict
(
opts
)
try
:
fn
=
args
[
0
]
except
:
fn
=
'data/licenseplate_motion.jpg'
win
=
'deconvolution'
img
=
cv2
.
imread
(
fn
,
0
)
img
=
np
.
float32
(
img
)
/
255.0
cv2
.
imshow
(
'input'
,
img
)
img
=
blur_edge
(
img
)
IMG
=
cv2
.
dft
(
img
,
flags
=
cv2
.
DFT_COMPLEX_OUTPUT
)
defocus
=
'--circle'
in
opts
def
update
(
_
):
ang
=
np
.
deg2rad
(
cv2
.
getTrackbarPos
(
'angle'
,
win
)
)
d
=
cv2
.
getTrackbarPos
(
'd'
,
win
)
noise
=
10
**
(
-
0.1
*
cv2
.
getTrackbarPos
(
'SNR (db)'
,
win
))
if
defocus
:
psf
=
defocus_kernel
(
d
)
else
:
psf
=
motion_kernel
(
ang
,
d
)
cv2
.
imshow
(
'psf'
,
psf
)
psf
/=
psf
.
sum
()
psf_pad
=
np
.
zeros_like
(
img
)
kh
,
kw
=
psf
.
shape
psf_pad
[:
kh
,
:
kw
]
=
psf
PSF
=
cv2
.
dft
(
psf_pad
,
flags
=
cv2
.
DFT_COMPLEX_OUTPUT
,
nonzeroRows
=
kh
)
PSF2
=
(
PSF
**
2
).
sum
(
-
1
)
iPSF
=
PSF
/
(
PSF2
+
noise
)[...,
np
.
newaxis
]
RES
=
cv2
.
mulSpectrums
(
IMG
,
iPSF
,
0
)
res
=
cv2
.
idft
(
RES
,
flags
=
cv2
.
DFT_SCALE
|
cv2
.
DFT_REAL_OUTPUT
)
res
=
np
.
roll
(
res
,
-
kh
//
2
,
0
)
res
=
np
.
roll
(
res
,
-
kw
//
2
,
1
)
cv2
.
imshow
(
win
,
res
)
cv2
.
namedWindow
(
win
)
cv2
.
namedWindow
(
'psf'
,
0
)
cv2
.
createTrackbar
(
'angle'
,
win
,
int
(
opts
.
get
(
'--angle'
,
135
)),
180
,
update
)
cv2
.
createTrackbar
(
'd'
,
win
,
int
(
opts
.
get
(
'--d'
,
22
)),
50
,
update
)
cv2
.
createTrackbar
(
'SNR (db)'
,
win
,
int
(
opts
.
get
(
'--snr'
,
25
)),
50
,
update
)
update
(
None
)
while
True
:
ch
=
cv2
.
waitKey
()
if
ch
==
27
:
break
if
ch
==
ord
(
' '
):
defocus
=
not
defocus
update
(
None
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录