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

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

Added original make3d

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