1 | % * This code was used in the following articles:
|
---|
2 | % * [1] Learning 3-D Scene Structure from a Single Still Image,
|
---|
3 | % * Ashutosh Saxena, Min Sun, Andrew Y. Ng,
|
---|
4 | % * In ICCV workshop on 3D Representation for Recognition (3dRR-07), 2007.
|
---|
5 | % * (best paper)
|
---|
6 | % * [2] 3-D Reconstruction from Sparse Views using Monocular Vision,
|
---|
7 | % * Ashutosh Saxena, Min Sun, Andrew Y. Ng,
|
---|
8 | % * In ICCV workshop on Virtual Representations and Modeling
|
---|
9 | % * of Large-scale environments (VRML), 2007.
|
---|
10 | % * [3] 3-D Depth Reconstruction from a Single Still Image,
|
---|
11 | % * Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
|
---|
12 | % * International Journal of Computer Vision (IJCV), Aug 2007.
|
---|
13 | % * [6] Learning Depth from Single Monocular Images,
|
---|
14 | % * Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
|
---|
15 | % * In Neural Information Processing Systems (NIPS) 18, 2005.
|
---|
16 | % *
|
---|
17 | % * These articles are available at:
|
---|
18 | % * http://make3d.stanford.edu/publications
|
---|
19 | % *
|
---|
20 | % * We request that you cite the papers [1], [3] and [6] in any of
|
---|
21 | % * your reports that uses this code.
|
---|
22 | % * Further, if you use the code in image3dstiching/ (multiple image version),
|
---|
23 | % * then please cite [2].
|
---|
24 | % *
|
---|
25 | % * If you use the code in third_party/, then PLEASE CITE and follow the
|
---|
26 | % * LICENSE OF THE CORRESPONDING THIRD PARTY CODE.
|
---|
27 | % *
|
---|
28 | % * Finally, this code is for non-commercial use only. For further
|
---|
29 | % * information and to obtain a copy of the license, see
|
---|
30 | % *
|
---|
31 | % * http://make3d.stanford.edu/publications/code
|
---|
32 | % *
|
---|
33 | % * Also, the software distributed under the License is distributed on an
|
---|
34 | % * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
---|
35 | % * express or implied. See the License for the specific language governing
|
---|
36 | % * permissions and limitations under the License.
|
---|
37 | % *
|
---|
38 | % */
|
---|
39 | function [FeatureSup ]= f_sup_old(Default,smallSup, sup, SupNeighborTable) |
---|
40 | % This fuction calculate the features of each superpixel (total 14) |
---|
41 | |
---|
42 | %%% |
---|
43 | % loads a new constant from generalData/SFeaMax.mat |
---|
44 | % |
---|
45 | % then for each superpixel index, calculate 13 features (each is |
---|
46 | % divided by a number in SFeaMax) |
---|
47 | % |
---|
48 | % 1) % of image spanned by this superpixel |
---|
49 | % 2) x and y position of the center of mass of the superpixel [0-1] |
---|
50 | % 3) x and y squared |
---|
51 | % 4) x and y positions of 10% and 90% of mass [0-1] |
---|
52 | % 5) # of unique superpixels that border this one |
---|
53 | % 6) angle of the principal direction of the shape of this |
---|
54 | % superpixel (max eigenvector) and sqrt(max eigenvalue) |
---|
55 | %%%% |
---|
56 | |
---|
57 | % normalize the Superpixel feature according to the previous result |
---|
58 | load([Default.ParaFolder '/SFeaMax.mat']); |
---|
59 | % Default.Flag.NormalizeFlag = 1; |
---|
60 | imdilateFlag = 0; |
---|
61 | % SFeaMax = 10.^floor(log10(SFeaMax)); |
---|
62 | if Default.Flag.NormalizeFlag == 1 |
---|
63 | SFeaMax = 10.^floor(log10(SFeaMax)); |
---|
64 | else |
---|
65 | SFeaMax(:) = 1; |
---|
66 | end |
---|
67 | |
---|
68 | [yn xn] = size(sup); |
---|
69 | NuFea = 13; |
---|
70 | NuSup = unique(smallSup(:))'; |
---|
71 | SupMaxInd = (max(sup(:))); |
---|
72 | FeatureSup = sparse(NuFea,SupMaxInd); |
---|
73 | SE = strel('diamond',3); |
---|
74 | NeighborList = []; % size undetermined |
---|
75 | for i=NuSup |
---|
76 | % tic; |
---|
77 | count = 2; |
---|
78 | l = 2; |
---|
79 | FeaturePicsSup = zeros(NuFea,1); |
---|
80 | mask = sup==i; |
---|
81 | % calculating feature |
---|
82 | |
---|
83 | % 2) x y position of superpixel |
---|
84 | [y x] = find(mask); |
---|
85 | y50 = prctile(y,50)/yn; |
---|
86 | x50 = prctile(x,50)/xn; |
---|
87 | FeaturePicsSup(count:(count+1)) = [x50/SFeaMax(1,l); y50/SFeaMax(1,l+1)]; |
---|
88 | l = l+2; |
---|
89 | count = count + 2; |
---|
90 | % 3) x^2 y^2 position of superpixel |
---|
91 | FeaturePicsSup(count:(count+1)) = [(x50)^2/SFeaMax(1,l); (y50)^2/SFeaMax(1,l+1)]; |
---|
92 | l = l+1; |
---|
93 | count = count + 2; |
---|
94 | % 4) x y 10th & 90th |
---|
95 | y90 = prctile(y,90)/yn; |
---|
96 | x90 = prctile(x,90)/xn; |
---|
97 | y10 = prctile(y,10)/yn; |
---|
98 | x10 = prctile(x,10)/xn; |
---|
99 | FeaturePicsSup(count:(count+3)) = [x10/SFeaMax(1,l); y10/SFeaMax(1,l+1); x90/SFeaMax(1,l+2); y90/SFeaMax(1,l+3)]; |
---|
100 | l = l+4; |
---|
101 | count = count + 4; |
---|
102 | % 5) number of connected superpixel |
---|
103 | % if i==56 |
---|
104 | % disp('i=56'); |
---|
105 | % end |
---|
106 | if imdilateFlag |
---|
107 | mask_dilate = imdilate(mask,SE); |
---|
108 | mask_dilate_edge = mask_dilate; |
---|
109 | mask_dilate_edge(mask) = 0; |
---|
110 | [list_sup] = unique(sup(mask_dilate_edge)); %hard work |
---|
111 | FeaturePicsSup(count) = size(list_sup,1)/SFeaMax(1,l); |
---|
112 | |
---|
113 | % storaging the Neighborhood List |
---|
114 | newNei = [i*ones(size(list_sup,1),1) list_sup]; |
---|
115 | newNei = sortrows(newNei,2); |
---|
116 | NeighborList = [ NeighborList; newNei]; |
---|
117 | end |
---|
118 | lNuNei = l; |
---|
119 | countNuNei =count; |
---|
120 | l=l+1; |
---|
121 | count = count + 1; |
---|
122 | % 6) eccentricity |
---|
123 | [y x] = find(mask); |
---|
124 | x = x/xn; |
---|
125 | y = y/yn; |
---|
126 | C = cov([x y]); |
---|
127 | [v e] = eig(C); |
---|
128 | tt = diag(e); |
---|
129 | if size(tt,1)~=2 |
---|
130 | tt = [tt ;tt]; |
---|
131 | end |
---|
132 | [I C] = max(abs(tt)); |
---|
133 | ta = v(:,C).*sign(tt(C)); |
---|
134 | |
---|
135 | % abs(tt): the standard deviation of the prime axis |
---|
136 | % v(:,C).*sign(tt(C)) : the direction of the prime axis |
---|
137 | FeaturePicsSup(count:(count+2)) = [sqrt(abs(tt))/SFeaMax(1,l); acos(ta(1))/SFeaMax(1,l+1)]; |
---|
138 | if size(FeaturePicsSup,1) ~=13 |
---|
139 | disp('error'); |
---|
140 | end |
---|
141 | %l=l+1; |
---|
142 | %MIN: Convert the eigenvector to a positive angle between 0 to 360 |
---|
143 | %FeaturePicsSup = [FeaturePicsSup; sqrt(abs(tt)); abs(v(:,C))]; |
---|
144 | FeatureSup(:,i) = FeaturePicsSup; |
---|
145 | % toc; |
---|
146 | end |
---|
147 | Hist = histc( sup(:), NuSup); |
---|
148 | FeatureSup(1,NuSup) = Hist/sum(Hist)./SFeaMax(1); |
---|
149 | tempNuNeighbor = sum(SupNeighborTable,2); |
---|
150 | FeatureSup( countNuNei, NuSup) = tempNuNeighbor(NuSup)./SFeaMax(lNuNei); |
---|