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 [TextureFeature, TextSup]=GenTextureFeature_InnerMulSup(Default, Img, SupMedScale, SmallSup, HiSup, FeatureType)%, maskg) |
---|
40 | |
---|
41 | % This function calculate all features that using the |
---|
42 | % output from calculateFilterBanks_old (Time and ram comsuming) |
---|
43 | % These Feature including AbsFeature DiffFeature HistogramFeature |
---|
44 | % FeatureTypr: 1 2 3 |
---|
45 | |
---|
46 | % Interface: |
---|
47 | % Input--- |
---|
48 | % 1) Default is the structure contain all the default parameter setting |
---|
49 | % 2) Img is the RGB image matrix |
---|
50 | % 3) SmallSup is Superpixel index matrix of size Default.VertYNuDepth Default.HoriXNuDepth |
---|
51 | % 4) HiSup is HiResolution Superpixel index matrix of size Default.SegVertYSize Default.SegHoriXSize or smaller |
---|
52 | % 5) FeatureType AbsFeature(1) DiffFeature(2) HistogramFeature(3) |
---|
53 | % Output--- |
---|
54 | % 1) TextureFeature.Abs: |
---|
55 | % 2) TextureFeature.Diff: |
---|
56 | % 3) TextureFeature.Hist: |
---|
57 | |
---|
58 | % Flag set up for testing purpose ======================================== |
---|
59 | % Must be stablized after testing XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
---|
60 | % Default.Flag.NormalizeFlag = 1; % Default.Flags.NormalizeFlag set to 1 if we want to normalize the Feature according to the Trainning Set |
---|
61 | DominateSupFilter = 1; % DominateSupFilter set to 1 if we want to use only the dominate superpixel area for acerage feature calculation |
---|
62 | % ======================================================================== |
---|
63 | |
---|
64 | % load FeaMax to do normalizeing |
---|
65 | load([Default.ParaFolder '/FeaMax.mat']); |
---|
66 | if Default.Flag.NormalizeFlag == 1 |
---|
67 | FeaMax = 10.^floor(log10(FeaMax)); |
---|
68 | else |
---|
69 | FeaMax(:) = 1; |
---|
70 | end |
---|
71 | |
---|
72 | % Initial Setting of TextureFeature Structure: |
---|
73 | % size(TextureFeature.Abs) = (No of Depth Point, No of Features: 17 texture filters, H2 and H4 kinds, 3 Scales) |
---|
74 | TextureFeature.Abs = zeros(Default.VertYNuDepth*Default.HoriXNuDepth, 17*2*3); |
---|
75 | TextureFeature.Diff = zeros(1,1); |
---|
76 | TextureFeature.Hist = zeros(1,1); |
---|
77 | |
---|
78 | % change the resolution in to exactly [TrainVerYSize TrainHoriXSize] |
---|
79 | |
---|
80 | if ~all(size(Img) == [Default.TrainVerYSize Default.TrainHoriXSize 3]) |
---|
81 | if Default.Flag.DisplayFlag |
---|
82 | disp('Resize to 2272 1704'); |
---|
83 | end |
---|
84 | Img = imresize(Img,[Default.TrainVerYSize Default.TrainHoriXSize],'bilinear'); |
---|
85 | end |
---|
86 | |
---|
87 | % Start the loop for 3 Scale |
---|
88 | fInd = 2; |
---|
89 | for i = 1:3 |
---|
90 | |
---|
91 | if DominateSupFilter && i==1 % only if DominateSupFilter and the largest scale will use superpixel mask |
---|
92 | SupMaskFlag = 1; |
---|
93 | else |
---|
94 | SupMaskFlag = 0; |
---|
95 | end |
---|
96 | |
---|
97 | % Generate the 17 texture filter output |
---|
98 | % set to global for InnerMultiple sup generation |
---|
99 | global H2; |
---|
100 | [H2] = calculateFilterBanks_old(Img); % (hard work 1min) use Ashutaosh's code |
---|
101 | |
---|
102 | % InnerMulSup ================================================================= |
---|
103 | if i == 2 |
---|
104 | [TextSup]=gen_TextSup_efficient_GlobalH2( Default); |
---|
105 | end |
---|
106 | % ===================================================================== |
---|
107 | |
---|
108 | % Scale Setting |
---|
109 | ResY = round(Default.TrainVerYSize/(3^(i))); % ResY ResX will be the new image size |
---|
110 | ResX = round(Default.TrainHoriXSize/(3^(i))); |
---|
111 | Img = imresize(Img,[ResY ResX],'nearest'); |
---|
112 | |
---|
113 | H2 = H2.^2; % Now H2 stand for H2 22222222222222222222222222222222222222222222222222222222222222222222222222222 |
---|
114 | |
---|
115 | if any(FeatureType == 1) % calculate the AbsFeatures |
---|
116 | StartAbs = 34*(i-1)+1; |
---|
117 | % [TextureFeature.Abs(:, (StartAbs):(StartAbs+16)) fInd]= AbsFeatureGenMex(Default, H2, SmallSup, HiSup, SupMaskFlag, FeaMax, fInd); |
---|
118 | [TextureFeature.Abs(:, (StartAbs):(StartAbs+16)) fInd]= ... |
---|
119 | AbsFeatureGenMex_MemoryEfficient(Default, SmallSup, HiSup, ... |
---|
120 | SupMaskFlag, FeaMax, fInd); |
---|
121 | end |
---|
122 | |
---|
123 | if any(FeatureType == 3) % calculate the HistogramFeature |
---|
124 | [relativeFeatureVector] = makeRelativeFeatureVector(H2,1); |
---|
125 | end |
---|
126 | |
---|
127 | if any(FeatureType == 2) % calculate the DiffFeature |
---|
128 | |
---|
129 | end |
---|
130 | |
---|
131 | % 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 |
---|
132 | |
---|
133 | H2 = H2.^2; % This H2 is H4 44444444444444444444444444444444444444444444444444444444444444444444444444444444444 |
---|
134 | |
---|
135 | if any(FeatureType == 1) % calculate the AbsFeatures |
---|
136 | StartAbs = 34*(i-1)+1+17; |
---|
137 | % [TextureFeature.Abs(:, (StartAbs):(StartAbs+16)) fInd]= AbsFeatureGenMex(Default, H2, SmallSup, HiSup, SupMaskFlag, FeaMax, fInd); |
---|
138 | [TextureFeature.Abs(:, (StartAbs):(StartAbs+16)) fInd]= AbsFeatureGenMex_MemoryEfficient(Default, SmallSup, HiSup, SupMaskFlag, FeaMax, fInd); |
---|
139 | end |
---|
140 | % 444444444444444444444444444444444444444444444444444444444444444444444 |
---|
141 | |
---|
142 | clear global H2; |
---|
143 | end |
---|
144 | |
---|
145 | % GoundBoundaryFea |
---|
146 | RayCenter = GenerateRay(Default.HoriXNuDepth,Default.VertYNuDepth,'center',... |
---|
147 | Default.a_default,Default.b_default,Default.Ox_default,... |
---|
148 | Default.Oy_default); %[ horiXSizeLowREs VertYSizeLowREs 3] |
---|
149 | big_sup = imresize(SupMedScale,[Default.VertYNuDepth Default.HoriXNuDepth],'nearest'); |
---|
150 | DefaultGroundMask = [zeros(floor(Default.VertYNuDepth/2), Default.HoriXNuDepth); ones(Default.VertYNuDepth-floor(Default.VertYNuDepth/2), Default.HoriXNuDepth)]; |
---|
151 | GroundSupIndex = unique(big_sup(logical(DefaultGroundMask))); |
---|
152 | % GroundSupIndex = unique(big_sup(logical(maskg))); |
---|
153 | for j = 1:Default.HoriXNuDepth |
---|
154 | Gmask = logical(zeros(size( big_sup(:,j)))); |
---|
155 | for k=GroundSupIndex' |
---|
156 | Gmask(big_sup(:,j) == k) = true; |
---|
157 | end |
---|
158 | [rowSub colSub ] = find(Gmask); |
---|
159 | minRow = min(rowSub); |
---|
160 | |
---|
161 | GroundVertEdge(:,j) = (1-(Default.VertYNuDepth-1)/Default.VertYNuDepth)./RayCenter(:,j,3); |
---|
162 | if size(minRow,1) ~= 0 |
---|
163 | GroundVertEdge((minRow+1):Default.VertYNuDepth,j) = (1-((minRow+1):Default.VertYNuDepth)'/Default.VertYNuDepth)./RayCenter((minRow+1):Default.VertYNuDepth,j,3); |
---|
164 | GroundVertEdge(1:(minRow),j) = (1- minRow/Default.VertYNuDepth)./RayCenter(1:(minRow),j,3); |
---|
165 | end |
---|
166 | end |
---|
167 | GroundVertEdgePics = GroundVertEdge; |
---|
168 | |
---|
169 | TextureFeature.Abs = [ TextureFeature.Abs min([GroundVertEdgePics(:)... |
---|
170 | repmat((Default.VertYNuDepth:-1:1)'/Default.VertYNuDepth,[Default.HoriXNuDepth 1])./reshape(RayCenter(:,:,3),[],1)],[],2)]; |
---|
171 | % /FeaMax(end)]; |
---|
172 | |
---|
173 | TextureFeature.Abs = [SmallSup(:) TextureFeature.Abs]; |
---|
174 | |
---|
175 | return; |
---|