source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/Features/OldBatchVersion/f_sup_oldv1.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 5.3 KB
Line 
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% */
39function [FeatureSup]= f_sup_old(Default,sup)
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
58load([Default.SFeaPara '/SFeaMax.mat']);
59NormalizeFlag = 1;
60% SFeaMax = 10.^floor(log10(SFeaMax));
61if  NormalizeFlag == 1
62    SFeaMax = 10.^floor(log10(SFeaMax));
63else
64    SFeaMax(:) = 1;
65end
66
67FeatureSup = [];
68[yn xn] = size(sup);
69NuSup = max(max(sup));
70for i=1:NuSup
71%     tic;
72    l = 1;
73    FeaturePicsSup = [];
74    mask = sup==i;
75    % calculating feature
76    % 1) size of superpixel normalized to the total number of subsuperpixel
77    NuSub = sum(sum(mask));
78    FeaturePicsSup = [FeaturePicsSup; NuSub/(xn*yn)/SFeaMax(1,l)];
79    l=l+1;
80    % 2) x y position of superpixel
81    NuSubSupVertY =  sum(mask,1);
82    PosiHoriX = find(NuSubSupVertY);
83    AccuHoriX =cumsum(NuSubSupVertY(1,NuSubSupVertY~=0));
84    x = PosiHoriX(min(find(AccuHoriX>=round(NuSub/2))))/xn;% normalize by the size of the pics
85    NuSubSupHoriX =  sum(mask,2);
86    PosiVertY = find(NuSubSupHoriX);
87    AccuVertY =cumsum(NuSubSupHoriX(NuSubSupHoriX~=0,1));
88    y = PosiVertY(min(find(AccuVertY>=round(NuSub/2))))/yn;% normalize by the size of the pics
89    FeaturePicsSup = [FeaturePicsSup; x/SFeaMax(1,l); y/SFeaMax(1,l+1)];
90    l = l+2;
91    % 3) x^2 y^2 position of superpixel
92    FeaturePicsSup = [FeaturePicsSup; x^2/SFeaMax(1,l); y^2/SFeaMax(1,l+1)];
93    l = l+1;
94    % 4) x y 10th & 90th
95    xten = PosiHoriX(min(find(AccuHoriX>=round(NuSub/10))))/xn;% normalize by the size of the pics   
96    xninety = PosiHoriX(min(find(AccuHoriX>=round(NuSub*9/10))))/xn;% normalize by the size of the pics
97    yten = PosiVertY(min(find(AccuVertY>=round(NuSub/10))))/yn;% normalize by the size of the pics
98    yninety = PosiVertY(min(find(AccuVertY>=round(NuSub*9/10))))/yn;% normalize by the size of the pics
99    FeaturePicsSup = [FeaturePicsSup; xten/SFeaMax(1,l); yten/SFeaMax(1,l+1); xninety/SFeaMax(1,l+2); yninety/SFeaMax(1,l+3)];
100    l = l+4;
101    % 5) number of connected superpixel
102%     if i==56
103%        disp('i=56');
104%     end   
105    SE = strel('diamond',3);
106    mask_dilate = imdilate(mask,SE);
107    mask_dilate_edge = mask_dilate;
108    mask_dilate_edge(mask) = 0;
109    [list_sup] = unique(sup(mask_dilate_edge)); %hard work
110    FeaturePicsSup = [FeaturePicsSup; size(list_sup,1)/SFeaMax(1,l)];
111    l=l+1;
112    % 6) eccentricity
113    [y x] = find(mask);
114    x = x/xn;
115    y = y/yn;
116    C = cov([x y]);
117    [v e] = eig(C);
118    tt = diag(e);
119    if size(tt,1)~=2
120        tt = [tt ;tt];
121    end   
122    [I C] = max(abs(tt));
123    ta = v(:,C).*sign(tt(C));
124   
125    % abs(tt): the standard deviation of the prime axis
126    % v(:,C).*sign(tt(C)) : the direction of the prime axis
127    FeaturePicsSup = [FeaturePicsSup; sqrt(abs(tt))/SFeaMax(1,l); acos(ta(1))/SFeaMax(1,l+1)];
128    if size(FeaturePicsSup,1) ~=13
129        disp('error');
130    end   
131    %l=l+1;
132        %MIN: Convert the eigenvector to a positive angle between 0 to 360
133    %FeaturePicsSup = [FeaturePicsSup; sqrt(abs(tt)); abs(v(:,C))];
134    FeatureSup = [FeatureSup FeaturePicsSup];
135%     toc;
136end
Note: See TracBrowser for help on using the repository browser.