-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstereo_creator.asv
63 lines (52 loc) · 2.07 KB
/
stereo_creator.asv
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
function stereo_creator()
im = rgb2gray(imread('tiger.jpg'));
factor = 5; % number of sections to split image into
rds = generate_random_dot_stereogram(im, factor);
im_binary = imbinarize(im);
seg_size = floor(size(im_binary,2)/factor);
srds = rds; % final imag
% generate stereogram for each segment
for idx = 1:factor
seg_start = (seg_size*(idx-1))+1;
seg_end = seg_size*idx;
segment = im_binary(:, seg_start:seg_end);
shifted = shift_section(rds, segment, im_binary, seg_start,seg_end);
tile = imtile({rds, shifted, segment});
rds = shifted;
imshow(tile);
srds = cat(2, srds, shifted); % append segment to final
end
tile = imtile({srds, im_binary});
imshow(tile);
end
% generate an image of random noise to hide the image in
function rds = generate_random_dot_stereogram(im_pic, factor)
im = zeros([size(im_pic,1) floor(size(im_pic,2)/factor)]) + 255;
im = imbinarize(imnoise(im,'salt & pepper',.1));
rds = imerode(im, strel('disk', 3));
end
function map = generate_disparity_map(im)
map = ind2rgb(histeq(im),gray(100));
end
% shift section of map and hide it in the noise
function shifted = shift_section(rds, map_section, map, seg_start,seg_end)
shift = 10;
stereo_bin = map_section & rds;
moved_rds = imtranslate(stereo_bin,[-shift, 0]);
shift_map =[];
% compensate for the shift by wrapping around pattern
if seg_end+shift > size(map,2)
leftover = map(:, seg_start+shift: size(map,2));
size_left = seg_end+shift - size(map,2) - 1;
filler = zeros(size(map,1), size_left);
shift_map =
end
shift_map = map(:, seg_start+shift:seg_end+shift);
shift_rds = imtranslate(rds, [size(rds,2)-shift, 0]);
com = (shift_rds & shift_map) + (moved_rds & shift_map);
section1 = imbinarize(rds - shift_map); % binarize to avoid negaitves
combined = section1 + com;% + shift_comp;
shifted = combined;
tile = imtile({rds, combined, moved_rds,shift_map, com});
imshow(tile)
end