-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstereo.module
41 lines (30 loc) · 1.12 KB
/
stereo.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
# -*- coding: utf-8 -*-
from numpy import *
from scipy.ndimage import filters
def plane_sweep_gauss(im_l,im_r,start,steps,wid):
m,n = im_l.shape
# 差の和を格納する配列
mean_l = zeros((m,n))
mean_r = zeros((m,n))
s = zeros((m,n))
s_l = zeros((m,n))
s_r = zeros((m,n))
# 奥行き平面を格納する配列
dmaps = zeros((m,n,steps))
# パッチ内の画素値の平均を計算する
filters.uniform_filter(im_l,wid,mean_l)
filters.uniform_filter(im_r,wid,mean_r)
# 画像を正規化
norm_l = im_l - mean_l
norm_r = im_r - mean_r
# 視差を順番に試していく
filters.gaussian_filter(norm_r*norm_r,wid,0,s_r) # 分母の和
for displ in range(steps):
# 左の画像を右にずらして和を計算
filters.gaussian_filter(roll(norm_l,-displ-start)*norm_r,wid,0,s) # 分子の和
filters.gaussian_filter(roll(norm_l,-displ-start)*roll(norm_l,-displ-start),wid,0,s_l)
# 相互相関係数を保存
dmaps[:,:,displ] = s/sqrt(s_l*s_r)
# 画素ごとに相関係数が最大値をとるの奥行きを選択
return argmax(dmaps,axis=2)