-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_code.m
98 lines (76 loc) · 3.07 KB
/
main_code.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
97
% This is the code for the computer vision project [CS763, IIT-B,2016]
% Developers: Nithin Vasisth, Pulkit Katdare
% This code mainly follows the paper written by Varsha Hedao: Recovering
% the spacial layout of Cluttered Rooms
% "http://vision.cs.uiuc.edu/~vhedau2/Research/research_spatialLayout.html"
clear;
close all
%image = imread('calib_data.jpg');
%image = imread('groundtruth/Images/2884291786_69bec3d738_m.jpg');
%image = imread('groundtruth/Images/bedroom4.jpg');
image = imread('groundtruth/Images/0000000041.jpg');
grayIm = rgb2gray(image);
size_im = size(grayIm);
minLen = 0.025*sqrt(size(image,1)*size(image,2));
lines = APPgetLargeConnectedEdges(grayIm, minLen);
% Adding a column to indicate the validity of the detected lines
% 1 == valid, 0 == invalid
lines = [lines , ones(size(lines,1),1)];
% Detecting the vanishing points
intn_pts = find_intersection(lines);
% Voting for each of the interesection points
threshold = 1;
[vote_init,vote_matrix_init] = vote_points(intn_pts,lines,threshold);
[~,num_1] = sort(vote_init);
% remove points whose vote is zero
%intn_pts(vote==0,5)=0;
clc;
%% Staring the iterative loop to create bins
% Here we iteratively remove the most voted points, and the lines voting
% for it, so that in the end we have a set of most voted points and their
% membership points
vp_candidates = zeros(size(intn_pts,1),1); % pre-allocating for speed
count_vp = 0;
vote = vote_init;
vote_matrix = vote_matrix_init;
vp_membership = cell(1);
while((sum(intn_pts(:,5)==1)>10)&&(numel((unique(vote)))~=1))
[~,num] = sort(vote);
% Since we want to ignore the vanishing point, we'll change it's validity
% index from 1 to 0; Also we'll invalidate the lines voting for it
count_vp = count_vp +1;
vp_candidates(count_vp) = num(end);
intn_pts(num(end),5) = 0;
vp_lines = determine_membership(num(end),lines,vote_matrix);
lines(vp_lines,7) = 0;
vp_membership{count_vp} = vp_lines;
% Let's also remove the validity of all the points who have been formed by
% the intersection of the vp_1_lines
intn_pts((ismember(intn_pts(:,3),vp_lines)|...
ismember(intn_pts(:,4),vp_lines)),5) = 0;
%recomputing the votes of each point
% We change the threshold at each iteration
% threshold = 1/(count_vp^2); % We're not using thresholds here
[vote,vote_matrix] = vote_points(intn_pts,lines,threshold);
%{.
% display the lines voting for the selected point in each iteration
vp_1 = num(end);
figure(3), hold off, imshow(1/5*grayIm)
figure(3), hold on, plot(lines(vp_lines,[1 2])',...
lines(vp_lines,[3 4])','r')
disp(vp_lines)
pause
%}
end
vp_candidates = vp_candidates(1:count_vp);
[suitable_set,o,f] = find_vpoints(lines,vp_candidates,intn_pts,size_im,grayIm,vp_membership);
% We now display the image with all the vanishing points and correspnding lines
%{
for i = 1:size(suitable_set,1)
display_points([vp_candidates(1),vp_candidates(suitable_set(i,:))'],intn_pts,lines,grayIm);
k = waitforbuttonpress;
if k==0
disp(i)
end
end
%}