[37] | 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 []=gen_feature_general(tskName,imgFolder,trainSet,learnType,learnSkyEx,learnLog,learnNear,... |
---|
| 40 | learnAlg,learnDate,absFeaType,absFeaDate,HistFeaType,histFeaDate, ... |
---|
| 41 | generalDataFolder, scratchDataFolder, localFolder, clusterExecutionDir, batchNumber,Absolute) |
---|
| 42 | |
---|
| 43 | % This function calculate the feature of each subsuperpixel using texture |
---|
| 44 | % infomation |
---|
| 45 | |
---|
| 46 | % decide the Hist |
---|
| 47 | if strcmp(HistFeaType,'Whole') |
---|
| 48 | Hist = 1; |
---|
| 49 | HistFeaType |
---|
| 50 | else |
---|
| 51 | Hist = 0; |
---|
| 52 | end |
---|
| 53 | |
---|
| 54 | if Hist ~= 1 && Absolute ~=1 |
---|
| 55 | return |
---|
| 56 | end |
---|
| 57 | |
---|
| 58 | if nargin < 1 |
---|
| 59 | batchNumber = 1; |
---|
| 60 | elseif nargin < 2 |
---|
| 61 | Hist = 1; |
---|
| 62 | Absolute =1; |
---|
| 63 | elseif nargin < 3 |
---|
| 64 | Absolute =1; |
---|
| 65 | end |
---|
| 66 | |
---|
| 67 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory... |
---|
| 68 | ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default... |
---|
| 69 | Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize PopUpVertY PopUpHoriX taskName... |
---|
| 70 | TrainVerYSize TrainHoriXSize MempryFactor; |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | % load estimated sky |
---|
| 74 | %load([ScratchDataFolder '/data/MaskGSky.mat']); % maskg is the estimated ground maskSky is the estimated sky |
---|
| 75 | |
---|
| 76 | % load([ScratchDataFolder '/data/filename.mat']);% load the filename |
---|
| 77 | % load([ScratchDataFolder '/data/PlaneParameterTure.mat']); % planeParameter |
---|
| 78 | load([ScratchDataFolder '/data/LowResImgIndexSuperpixelSep.mat']); % superpixel_index |
---|
| 79 | %load([ScratchDataFolder '/data/MediResImgIndexSuperpixelSep.mat']); % MediResImgIndexSuperpixelSep |
---|
| 80 | load([ScratchDataFolder '/data/DiffLowResImgIndexSuperpixelSep.mat']); % DiffLowResImgIndexSuperpixelSep |
---|
| 81 | DiffLowResImgIndexSuperpixelSep = DiffLowResImgIndexSuperpixelSep(:,1);% need only the middle scale segmentation |
---|
| 82 | |
---|
| 83 | %load([ScratchDataFolder '/data/FeatureSuperpixel.mat']); %load feature of superpixel |
---|
| 84 | % load FeaMax to do normalizeing |
---|
| 85 | load([GeneralDataFolder '/FeaMax.mat']); |
---|
| 86 | FeaMax = 10.^floor(log10(FeaMax)); |
---|
| 87 | |
---|
| 88 | % prepare data step |
---|
| 89 | nu_pics = size(filename,2); % number of pictures |
---|
| 90 | |
---|
| 91 | % ====================== change able parameter ===================== |
---|
| 92 | %batchSize = 10;% decide the batch size as 10 image pre batch |
---|
| 93 | % ================================================================== |
---|
| 94 | |
---|
| 95 | % for batchImg = 1:batchSize:nu_pics |
---|
| 96 | batchImg = 1:batchSize:nu_pics; |
---|
| 97 | |
---|
| 98 | f = []; % total feature: feature of superpixel followed by texture feature of patch |
---|
| 99 | f_pics = []; |
---|
| 100 | PicsNu = 1 |
---|
| 101 | for i = batchImg(batchNumber):min(batchImg(batchNumber)+batchSize-1, nu_pics) |
---|
| 102 | % load MediResImgIndexSuperpixelSep |
---|
| 103 | load([ScratchDataFolder '/data/MedSeg/MediResImgIndexSuperpixelSep' num2str(i) '.mat']); |
---|
| 104 | |
---|
| 105 | % calculate all the features, ray, plane parameter, and row column value |
---|
| 106 | img = imread([GeneralDataFolder '/' ImgFolder '/' filename{i} '.jpg']);% read in the hi resolution image of the ith file |
---|
| 107 | size(img) |
---|
| 108 | % change the resolution in to exactly [TrainVerYSize TrainHoriXSize] |
---|
| 109 | |
---|
| 110 | if ~all(size(img) == [TrainVerYSize TrainHoriXSize 3]) |
---|
| 111 | disp('resize to 2272 1704') |
---|
| 112 | img = imresize(img,[TrainVerYSize TrainHoriXSize],'bilinear'); |
---|
| 113 | end |
---|
| 114 | % the images resolusion must be bigger then a certain size to have reasonable predicted depth |
---|
| 115 | % if prod(size(img))<SegVertYSize*SegHoriXSize*3 |
---|
| 116 | % img = imresize(img,[SegVertYSize SegHoriXSize],'bilinear'); |
---|
| 117 | % the images resolusion must be smaller then a certain size to avoid out of memory |
---|
| 118 | % elseif prod(size(img)) > TrainVerYSize*TrainHoriXSize*3*(MempryFactor); |
---|
| 119 | % disp('origin size') |
---|
| 120 | % size(img) |
---|
| 121 | % img = imresize(img,[TrainVerYSize TrainHoriXSize],'bilinear'); |
---|
| 122 | % disp('image too big') |
---|
| 123 | % size(img) |
---|
| 124 | % end |
---|
| 125 | [vertical_size_hi_res horizontal_size_hi_res t] = size(img); clear t; |
---|
| 126 | % get the horizontal(vertical_size_hi_res) and vertical(horizontal_size_hi_res) size of hi resolution image |
---|
| 127 | sup_hi_res = imresize(MediResImgIndexSuperpixelSep, ... |
---|
| 128 | [vertical_size_hi_res horizontal_size_hi_res],'nearest');% enlarge the low res superpixel into hi res superpixel |
---|
| 129 | clear MediResImgIndexSuperpixelSep; |
---|
| 130 | |
---|
| 131 | % generate the superpixel in the depth_grid size |
---|
| 132 | sup = imresize(LowResImgIndexSuperpixelSep{i,1},[VertYNuDepth HoriXNuDepth],'nearest'); |
---|
| 133 | |
---|
| 134 | % load picsinfo just for the horizontal value |
---|
| 135 | PicsinfoName = strrep(filename{i},'img','picsinfo'); |
---|
| 136 | temp = dir([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 137 | if size(temp,1) == 0 |
---|
| 138 | a = a_default; |
---|
| 139 | b = b_default; |
---|
| 140 | Ox = Ox_default; |
---|
| 141 | Oy = Oy_default; |
---|
| 142 | Horizon = Horizon_default; |
---|
| 143 | else |
---|
| 144 | load([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 145 | end |
---|
| 146 | |
---|
| 147 | RayCenter = GenerateRay(HoriXNuDepth,VertYNuDepth,'center',a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3] |
---|
| 148 | |
---|
| 149 | Default=SetupDefault(tskName,imgFolder,trainSet,learnType,learnSkyEx,learnLog,learnNear,learnAlg,learnDate,absFeaType, ... |
---|
| 150 | absFeaDate,HistFeaType,histFeaDate,generalDataFolder,scratchDataFolder,localFolder,clusterExecutionDir); |
---|
| 151 | [TextureFeature]=GenTextureFeature(Default, img, sup, sup_hi_res, 1); |
---|
| 152 | |
---|
| 153 | f_pics=TextureFeature.Abs; |
---|
| 154 | |
---|
| 155 | %% write ground boundary here |
---|
| 156 | if Absolute == 1 |
---|
| 157 | % superpixel features |
---|
| 158 | %fsup = FeatureSuperpixel{i}; |
---|
| 159 | %f_pics = [f_pics fsup(:,f_pics(:,1))']; |
---|
| 160 | % other features without relation with neiborfeatures |
---|
| 161 | % 1) the closest ground position to the (i, j) patch |
---|
| 162 | % How can we remove DiffLowResImgIndexSuperpixelSep since generate another superpixel takes time |
---|
| 163 | big_sup = imresize(DiffLowResImgIndexSuperpixelSep{i,1},[VertYNuDepth HoriXNuDepth],'nearest'); |
---|
| 164 | %%%%% GroundSupIndex = unique(big_sup(maskg{i})); |
---|
| 165 | DefaultGroundMask = [zeros(floor(VertYNuDepth/2), HoriXNuDepth); ones(VertYNuDepth-floor(VertYNuDepth/2), HoriXNuDepth)]; |
---|
| 166 | GroundSupIndex = unique(big_sup(logical(DefaultGroundMask))); |
---|
| 167 | |
---|
| 168 | % NonGround = []; |
---|
| 169 | % for j = 1:HoriXNuDepth |
---|
| 170 | % Ground(j) = analysesupinpatch(big_sup(round(gridinfo(2,2)*(1-Horizon)):end,j)); |
---|
| 171 | % NonGround(j) = analysesupinpatch(big_sup(round(1:(gridinfo(2,2)*(1-Horizon)-1)),j)); |
---|
| 172 | % NonGround = [NonGround (unique(big_sup(round(1:(gridinfo(2,2)*(1-Horizon)-1)),j)))']; |
---|
| 173 | % end |
---|
| 174 | % Ground = setdiff(Ground,NonGround); |
---|
| 175 | for j = 1:HoriXNuDepth |
---|
| 176 | Gmask = logical(zeros(size( big_sup(:,j)))); |
---|
| 177 | for k=GroundSupIndex' |
---|
| 178 | Gmask(big_sup(:,j) == k) = true; |
---|
| 179 | end |
---|
| 180 | [rowSub colSub ] = find(Gmask); |
---|
| 181 | minRow = min(rowSub); |
---|
| 182 | % if size(minRow,1) == 0 |
---|
| 183 | % Gmask = logical(zeros(size( big_sup(:,j)))); |
---|
| 184 | % MaybeGround = unique(big_sup(round(gridinfo(2,2)*(1-Horizon)):end,j)); |
---|
| 185 | % MaybeGround = setdiff(MaybeGround,NonGround); |
---|
| 186 | % for k=MaybeGround |
---|
| 187 | % Gmask(big_sup(:,j) == k) = true; |
---|
| 188 | % end |
---|
| 189 | % [rowSub colSub ] = find(Gmask); |
---|
| 190 | % minRow = min(rowSub); |
---|
| 191 | % if size(minRow,1) == 0 |
---|
| 192 | % lastguessGround = analysesupinpatch(big_sup(round(gridinfo(2,2)*(1-Horizon)):end,j)); |
---|
| 193 | % [rowSub colSub ] = find(big_sup(round(gridinfo(2,2)*(1-Horizon)):end,j)==lastguessGround); |
---|
| 194 | % minRow = min(rowSub); |
---|
| 195 | % end |
---|
| 196 | % end |
---|
| 197 | %minRow = max(minRow,round(gridinfo(2,2)*(1-Horizon))); |
---|
| 198 | |
---|
| 199 | GroundVertEdge(:,j) = (1-(VertYNuDepth-1)/VertYNuDepth)./RayCenter(:,j,3); |
---|
| 200 | if size(minRow,1) ~= 0 |
---|
| 201 | GroundVertEdge((minRow+1):VertYNuDepth,j) = (1-((minRow+1):VertYNuDepth)'/VertYNuDepth)./RayCenter((minRow+1):VertYNuDepth,j,3); |
---|
| 202 | GroundVertEdge(1:(minRow),j) = (1- minRow/VertYNuDepth)./RayCenter(1:(minRow),j,3); |
---|
| 203 | end |
---|
| 204 | end |
---|
| 205 | GroundVertEdgePics = GroundVertEdge; |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | %f_pics(:,end+1) = max([GroundVertEdgePics(:) repmat((1:VertYNuDepth)',[HoriXNuDepth 1])],[],2); |
---|
| 209 | %f_pics(:,end+1) = Gr undVertEdgePics(:);%./reshape(RayCenter(:,:,3),[],1); |
---|
| 210 | f_pics(:,end+1) = min([GroundVertEdgePics(:)... |
---|
| 211 | repmat((VertYNuDepth:-1:1)'/VertYNuDepth,[HoriXNuDepth 1])./reshape(RayCenter(:,:,3),[],1)],[],2); |
---|
| 212 | |
---|
| 213 | disp(['Image Number ' num2str(i)]); |
---|
| 214 | %size(f_pics) |
---|
| 215 | %size(sup(:)) |
---|
| 216 | f{PicsNu} = [sup(:) f_pics]; |
---|
| 217 | |
---|
| 218 | end |
---|
| 219 | |
---|
| 220 | PicsNu = PicsNu + 1 |
---|
| 221 | batchNumber |
---|
| 222 | |
---|
| 223 | end |
---|
| 224 | save([ScratchDataFolder '/data/feature_Abs_Whole' num2str(batchNumber) '_.mat'],'f'); |
---|
| 225 | return; |
---|