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

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

Added original make3d

File size: 4.7 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_oldModify(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 = 0;
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    [y x] = find(mask);
82    y50 = prctile(y,50)/yn;
83    x50 = prctile(x,50)/xn;
84    FeaturePicsSup = [FeaturePicsSup; x50/SFeaMax(1,l); y50/SFeaMax(1,l+1)];
85    l = l+2;
86    % 3) x^2 y^2 position of superpixel
87    FeaturePicsSup = [FeaturePicsSup; (x50)^2/SFeaMax(1,l); (y50)^2/SFeaMax(1,l+1)];
88    l = l+1;
89    % 4) x y 10th & 90th
90    y90 = prctile(y,90)/yn;
91    x90 = prctile(x,90)/xn;
92    y10 = prctile(y,10)/yn;
93    x10 = prctile(x,10)/xn;
94    FeaturePicsSup = [FeaturePicsSup; x10/SFeaMax(1,l); y10/SFeaMax(1,l+1); x90/SFeaMax(1,l+2); y90/SFeaMax(1,l+3)];
95    l = l+4;
96    % 5) number of connected superpixel
97%     if i==56
98%        disp('i=56');
99%     end   
100    SE = strel('diamond',3);
101    mask_dilate = imdilate(mask,SE);
102    mask_dilate_edge = mask_dilate;
103    mask_dilate_edge(mask) = 0;
104    [list_sup] = unique(sup(mask_dilate_edge)); %hard work
105    FeaturePicsSup = [FeaturePicsSup; size(list_sup,1)/SFeaMax(1,l)];
106    l=l+1;
107    % 6) eccentricity
108    [y x] = find(mask);
109    x = x/xn;
110    y = y/yn;
111    C = cov([x y]);
112    [v e] = eig(C);
113    tt = diag(e);
114    if size(tt,1)~=2
115        tt = [tt ;tt];
116    end   
117    [I C] = max(abs(tt));
118    ta = v(:,C).*sign(tt(C));
119   
120    % abs(tt): the standard deviation of the prime axis
121    % v(:,C).*sign(tt(C)) : the direction of the prime axis
122    FeaturePicsSup = [FeaturePicsSup; sqrt(abs(tt))/SFeaMax(1,l); acos(ta(1))/SFeaMax(1,l+1)];
123    if size(FeaturePicsSup,1) ~=13
124        disp('error');
125    end   
126    %l=l+1;
127        %MIN: Convert the eigenvector to a positive angle between 0 to 360
128    %FeaturePicsSup = [FeaturePicsSup; sqrt(abs(tt)); abs(v(:,C))];
129    FeatureSup = [FeatureSup FeaturePicsSup];
130%     toc;
131end
Note: See TracBrowser for help on using the repository browser.