-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseg_test.m
96 lines (77 loc) · 2.84 KB
/
seg_test.m
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
clc;clear;
vid_read = VideoReader('./img/driverec.mp4','CurrentTime',653);
%vid_write = VideoWriter('./img/encode','MPEG-4');
%open(vid_write);
factor_l = zeros(1,5);
while hasFrame(vid_read)
img = readFrame(vid_read);
img = imresize(img, [480 640]);
imwrite(img,'./img/encode.png','png');
ref = rgb2hsv(img);
factor = zeros(1,5);
%% Sparse depth estimation
img = img(:,:,2);
ref_spa = double((f_blur(img,3,1)) - (f_blur(img,9,1))) ;
%ref_spa = (imgaussfilt(im2gray(img),1.3)-imgaussfilt(im2gray(img),1.5)).*2;
e = edge((img),'log'); % あとで手実装する
ref_spa(e == 0) = 0;
%% dense depth estimation
% HSV変換(変数:ref)
% H(色相)とS(彩度)の情報を使い類似度を求める
ref_hue = cos(ref(:,:,1) .* 2 .* pi);
ref_sat = ref(:,:,2);
ref_val = ref(:,:,3);
ref_gray_bk = ref_val;
gthresh1 = my_graythresh(ref_val);
ref_val(ref_val > gthresh1) = 0;
gthresh2 = my_graythresh(ref_val);
% 屋外晴天時と室内
ref_val = (ref_gray_bk >= gthresh2) .* 1 ...
+ (ref_gray_bk >= gthresh1) .* 1;
factor = ((ref_hue > 0) .* 1 ...
+ (ref_hue <= 0) .* -1 ...
);
ref_val = ref_val .* factor; % -2~+2までの5階調になる(0を含むので)
% % 大津のn値化と輪郭の検証は下記4行をコメントアウト
figure(1); colormap("default")
m = min(ref_spa>0,[],'all')
x = max(ref_spa,[],"all")
imagesc(ref_spa);clim([10 x])
colorbar;
im_width = width(ref_spa);
im_height = height(ref_spa);
img_dense = zeros(size(ref_spa));
fill_enable = false;
edge_factor = 0;
fill_factor = 0;
fill_counter = 0; %同じエッジ要素で塗りつぶし続けることを制限するためのカウンタ
N = 40;
for i=1:N:im_width-N
for j=1:N:im_height-N
pick_defocus = ref_spa(j:j+N-1,i:i+N-1);
pick_matrices = ref_val(j:j+N-1,i:i+N-1);
l = 1;
for k=unique(ref_val)'
factor = (pick_matrices == k);
fill_factor = mean(ref_spa(factor),'all');
if ~isempty(fill_factor) && fill_factor > 0
%fill_factor
factor_l(l) = fill_factor;
img_dense(j:j+N-1,i:i+N-1) = img_dense(j:j+N-1,i:i+N-1) + double(factor) .* fill_factor;
else
img_dense(j:j+N-1,i:i+N-1) = img_dense(j:j+N-1,i:i+N-1) + factor_l(l);
end
l = l + 1;
end
end
end
figure(2)
colormap('default')
%img_dense(e == 0) = 0;
imagesc(img_dense.*10);clim([0 15])
colorbar
drawnow
% %im = ind2rgb(uint8(img_dense),turbo(30));
% %writeVideo(vid_write,im);
end
%close(vid_write);