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

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

Added original make3d

File size: 5.1 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 [f, fInd] = AbsFeatureGenMex(Default, SmallSup, HiSupi, SupMaskFlag, FeaMax, fInd)
40
41% This function generate the average of the feature within a certain mask of a sample point
42% Input--
43% H2: texture filter output
44% HiSup: the Hi resolution superpixel index matrix
45% SupMaskFlag: if SupMaskFlag is 1, we calculate the averaging using superpixel mask (irregular mask)
46% Output--
47% f: Feature matrix of size(No od depth point, No of feature vector)
48
49global H2;
50
51% Parameter
52[ImgResY ImgResX] = size(H2(:,:,1));
53   
54% define image and sample point and patch size infomation
55gridinfo = [Default.TrainHoriXSize Default.HoriXNuDepth Default.HoriXNuPatch; Default.TrainVerYSize Default.VertYNuDepth Default.VertYNuPatch];
56
57% Grid Info
58ratio(1:2) = floor(gridinfo(:,1)./gridinfo(:,end) );
59ratio(3:4) = floor( gridinfo(:,1)./gridinfo(:,2) );
60   
61% Patch shape infomation
62hcol = ones(floor(ratio(2)),1);
63hrow = ones(1,floor(ratio(1)));
64
65if SupMaskFlag == 1 % Need to use irregular Superpixel Mask
66
67    % calculate how many mask we need
68   NuMask = ceil(gridinfo(:,2)./gridinfo(:,3));
69   
70   % calcuate the position of the mask
71   hight(1) = round((ratio(2)-1)/2);
72   hight(2) = ratio(2) - 1 - hight(1);
73   width(1) = round((ratio(1)-1)/2);
74   width(2) = ratio(1) - 1 - width(1);
75
76   row_start = 1;
77   f = [];
78   f_pics_mask = zeros( gridinfo(1,3)*gridinfo(2,3), 17);
79   for j = 1:NuMask(1)
80       for k = 1:NuMask(2);
81           fIndNew = fInd;
82           % first generate the mask respect to the dominate subsuperpixel
83           [mask,PixelMask,PatchMask] = makeSubSupMaskNew2(gridinfo, HiSupi, SmallSup, [j; k], width, hight);
84%           [mask,SupIndex,PixelM,PatchMask] = makeSubSupMask(gridinfo, HiSupi, SmallSup, [j; k], width, hight);
85           
86
87           % calculaing the normalize value
88 %          NormalizeValue = conv2(hcol,hrow,mask,'same');%///////////////////////////////////////////////
89
90           % generate the 1:34 features for H2  for 1 center and 4 neighbor (left right top bottom)
91           for m = 1:17
92               
93%               temp = conv2(hcol, hrow, H2(:,:,m).*mask, 'same');%///////////////////////////////////////////
94%               tt = temp(PixelM)./NormalizeValue(PixelM);
95%               vv =SparseAverageSample2D(H2(:,:,m), floor(ratio(2)), floor(ratio(1)),PixelMask,mask);
96%               [floor(ratio(1)), floor(ratio(2))]
97               f_pics_mask(:,m) = ...
98                              SparseAverageSample2DOptimized(H2(:,:,m),...
99                              ratio(2), ratio(1), ...
100                              PixelMask,double(mask))...
101                             ./FeaMax(1,fIndNew);
102               fIndNew = fIndNew+1;
103           end
104
105           f(PatchMask, row_start:row_start+size(f_pics_mask,2)-1) = f_pics_mask;
106       end
107   end
108   fInd = fIndNew;
109
110else
111   DepthGridSizeY = ImgResY/Default.VertYNuDepth;
112   DepthGridSizeX= ImgResX/Default.HoriXNuDepth;
113   % 1) generating the PixelMask
114%   PixelMask = logical(zeros(ImgResY,ImgResX));
115   [X Y] = meshgrid(ceil((1/2)*DepthGridSizeX:DepthGridSizeX:ImgResX),...
116                    ceil((1/2)*DepthGridSizeY:DepthGridSizeY:ImgResY));
117   %PixelMask = sub2ind(size(PixelMask),Y(:),X(:));
118   for m = 1:17
119       f(:,m) = SparseAverageSample2DOptimized(H2(:,:,m),ratio(2),ratio(1),[Y(:) X(:)], double(ones(size(H2(:,:,m)))))...
120                        ./FeaMax(1,fInd);
121       fInd = fInd +1;
122   end
123
124end
125
126return;
Note: See TracBrowser for help on using the repository browser.