[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_predictedVar(learningType,SkyExclude,logScale,LearnNear,... |
---|
| 40 | LearnAlg,LearnDate,AbsFeaType,AbsFeaDate,HistFeaType,HistFeaDate,... |
---|
| 41 | FeaBatchNumber,WeiBatchNumber); |
---|
| 42 | %learningType,logScale,SkyExclude,LearnAlg,AbsFeaType,AbsFeaDate,WeiBatchNumber,logScale,SkyExclude,LearnNear) |
---|
| 43 | % this function generate the learned Var |
---|
| 44 | |
---|
| 45 | % ========================================================= |
---|
| 46 | %logScale = 1; % for now it's always this case since the variance must be positive |
---|
| 47 | %========================================================= |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | % define global variable |
---|
| 51 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory... |
---|
| 52 | ImgFolder TrainSet VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default... |
---|
| 53 | Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize; |
---|
| 54 | |
---|
| 55 | % load estimated sky |
---|
| 56 | load([ScratchDataFolder '/data/MaskGSky.mat']); % maskg is the estimated ground maskSky is the estimated sky |
---|
| 57 | |
---|
| 58 | % load superpixel Feadture |
---|
| 59 | load([ScratchDataFolder '/data/FeatureSuperpixel.mat']); % load the feature relate to position and shape of superpixel |
---|
| 60 | |
---|
| 61 | % load all the thi in different rows |
---|
| 62 | nut = []; |
---|
| 63 | nut_base = []; |
---|
| 64 | for i = 1:ceil(NuRow_default/WeiBatchSize) % only consider two learning type 'Abs' = Depth 'Fractional' = FractionalRegDepth |
---|
| 65 | load([ScratchDataFolder '/../learned_parameter/Variance/Var_' TrainSet '_' LearnAlg ... |
---|
| 66 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
| 67 | '_Near' num2str(LearnNear) '_WeiBatNu' num2str(i) ... |
---|
| 68 | '_' AbsFeaType '_AbsFeaDate' AbsFeaDate '_LearnDate' LearnDate '.mat']); |
---|
| 69 | nut = [nut nu]; |
---|
| 70 | nut_base = [nut_base nu_base]; |
---|
| 71 | end |
---|
| 72 | nut = cell2mat(nut); |
---|
| 73 | nut_base = cell2mat(nut_base); |
---|
| 74 | |
---|
| 75 | % mkdir to store the Variance in scratch space |
---|
| 76 | system(['mkdir ' ScratchDataFolder '/Var_' learningType '_' LearnAlg ... |
---|
| 77 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
| 78 | '_Near' num2str(LearnNear)]); |
---|
| 79 | system(['mkdir ' ScratchDataFolder '/Var_' learningType '_' LearnAlg ... |
---|
| 80 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
| 81 | '_Near' num2str(LearnNear) '_baseline']); |
---|
| 82 | %if strcmp(learningType,'Fractional') |
---|
| 83 | % system(['mkdir ' ScratchDataFolder '/_LearnFDLinearNonSky_']); |
---|
| 84 | % disp('Fractional') |
---|
| 85 | %else |
---|
| 86 | % if logScale==1 |
---|
| 87 | % if SkyExclude == 1 |
---|
| 88 | % system(['mkdir ' ScratchDataFolder '/_LearnDLogScaleNonskySep_' learningType]); |
---|
| 89 | % else |
---|
| 90 | % system(['mkdir ' ScratchDataFolder '/_LearnDLogScale_' learningType]); |
---|
| 91 | % end |
---|
| 92 | % else |
---|
| 93 | % if SkyExclude ==1 |
---|
| 94 | % system(['mkdir ' ScratchDataFolder '/_LearnDNonsky_' learningType]); |
---|
| 95 | % else |
---|
| 96 | % system(['mkdir ' ScratchDataFolder '/_LearnD_' learningType]); |
---|
| 97 | % end |
---|
| 98 | % end |
---|
| 99 | %end |
---|
| 100 | |
---|
| 101 | NuPics = size(filename,2); % number of pictures |
---|
| 102 | NuFeaBatch = ceil(NuPics/batchSize); |
---|
| 103 | for j =1:NuFeaBatch |
---|
| 104 | % load([ScratchDataFolder '/data/feature_sqrt_H4_ray' int2str(j) '.mat']); % 'f' |
---|
| 105 | load([ScratchDataFolder '/data/feature_Abs_Whole' int2str(j) '_.mat']); |
---|
| 106 | for k = 1:size(f,2)%batchSize |
---|
| 107 | |
---|
| 108 | %================ |
---|
| 109 | % load picsinfo just for the horizontal value |
---|
| 110 | (j-1)*batchSize+k % pics Number |
---|
| 111 | |
---|
| 112 | PicsinfoName = strrep(filename{(j-1)*batchSize+k},'img','picsinfo'); |
---|
| 113 | temp = dir([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 114 | if size(temp,1) == 0 |
---|
| 115 | a = a_default; |
---|
| 116 | b = b_default; |
---|
| 117 | Ox = Ox_default; |
---|
| 118 | Oy = Oy_default; |
---|
| 119 | Horizon = Horizon_default; |
---|
| 120 | else |
---|
| 121 | load([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 122 | end |
---|
| 123 | |
---|
| 124 | % prepare the nuMatrix |
---|
| 125 | NuRow = NuRow_default; |
---|
| 126 | for i = 1:NuRow; |
---|
| 127 | RowskyBottom = ceil(NuRow/2); |
---|
| 128 | PatchSkyBottom = ceil(VertYNuDepth*(1-Horizon)); |
---|
| 129 | if i <= RowskyBottom |
---|
| 130 | PatchRowRatio = PatchSkyBottom/RowskyBottom; |
---|
| 131 | RowTop(i) = ceil((i-1)*PatchRowRatio+1); |
---|
| 132 | RowBottom(i) = ceil(i*PatchRowRatio); |
---|
| 133 | else |
---|
| 134 | PatchRowRatio = (VertYNuDepth-PatchSkyBottom)/(NuRow-RowskyBottom); |
---|
| 135 | RowTop(i) = ceil((i-RowskyBottom-1)*PatchRowRatio+1)+PatchSkyBottom; |
---|
| 136 | RowBottom(i) = ceil((i-RowskyBottom)*PatchRowRatio)+PatchSkyBottom; |
---|
| 137 | end |
---|
| 138 | end |
---|
| 139 | RowNumber = RowBottom'-RowTop'+1; |
---|
| 140 | nuRow = []; |
---|
| 141 | nu_baseRow = []; |
---|
| 142 | for i = 1:NuRow; |
---|
| 143 | nuRow = [ nuRow nut(:,i*ones(RowNumber(i),1))]; |
---|
| 144 | nu_baseRow = [ nu_baseRow nut_base(:,i*ones(RowNumber(i),1))]; |
---|
| 145 | end |
---|
| 146 | %================ |
---|
| 147 | if (j-1)*batchSize+k ==4 |
---|
| 148 | disp('error'); |
---|
| 149 | end |
---|
| 150 | % FeaVectorPics = genFeaVector(f{k},FeatureSuperpixel{(j-1)*batchSize+k},... |
---|
| 151 | % 1,VertYNuDepth,1,HoriXNuDepth,(j-1)*batchSize+k); |
---|
| 152 | FeaVectorPics = genFeaVector(f{k},FeatureSuperpixel{(j-1)*batchSize+k},... |
---|
| 153 | [1:VertYNuDepth],[1:HoriXNuDepth],(j-1)*batchSize+k,0); |
---|
| 154 | if logScale ==1 |
---|
| 155 | VarMap = exp(reshape(sum([ones(size(FeaVectorPics,2),1) FeaVectorPics'].*... |
---|
| 156 | repmat(nuRow',[HoriXNuDepth 1]),2),VertYNuDepth,[])); |
---|
| 157 | VarMap_base = exp(reshape(sum([ones(size(FeaVectorPics,2),1) ].*... |
---|
| 158 | repmat(nu_baseRow',[HoriXNuDepth 1]),2),VertYNuDepth,[])); |
---|
| 159 | else |
---|
| 160 | size(nuRow) |
---|
| 161 | size(FeaVectorPics) |
---|
| 162 | VarMap = reshape(sum([ones(size(FeaVectorPics,2),1) FeaVectorPics'].*... |
---|
| 163 | repmat(nuRow',[HoriXNuDepth 1]),2),VertYNuDepth,[]); |
---|
| 164 | VarMap_base = reshape(sum([ones(size(FeaVectorPics,2),1) ].*... |
---|
| 165 | repmat(nu_baseRow',[HoriXNuDepth 1]),2),VertYNuDepth,[]); |
---|
| 166 | end |
---|
| 167 | %=====================SkyExclude===================== |
---|
| 168 | if SkyExclude ==1 |
---|
| 169 | VarMap(maskSky{(j-1)*batchSize+k}) = max(max(VarMap))+30; |
---|
| 170 | VarMap_base(maskSky{(j-1)*batchSize+k}) = max(max(VarMap))+30; |
---|
| 171 | end |
---|
| 172 | %==================================================== |
---|
| 173 | Varfile = strrep(filename{(j-1)*batchSize+k},'img','Var_learned'); % |
---|
| 174 | save([ScratchDataFolder '/Var_' learningType '_' LearnAlg ... |
---|
| 175 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
| 176 | '_Near' num2str(LearnNear) '/' Varfile '.mat'],'VarMap'); |
---|
| 177 | save([ScratchDataFolder '/Var_' learningType '_' LearnAlg ... |
---|
| 178 | '_Nonsky' num2str(SkyExclude) '_Log' num2str(logScale) ... |
---|
| 179 | '_Near' num2str(LearnNear) '_baseline/' Varfile '.mat'],'VarMap_base'); |
---|
| 180 | % if strcmp(learningType,'Fractional') |
---|
| 181 | % save([ScratchDataFolder '/_LearnFDLinearNonSky_/' Varfile '.mat'], 'VarMap'); |
---|
| 182 | % else |
---|
| 183 | % if logScale == 1 |
---|
| 184 | % if SkyExclude == 1 |
---|
| 185 | % save([ScratchDataFolder '/_LearnDLogScaleNonskySep_' learningType '/' Varfile '.mat'],'VarMap'); |
---|
| 186 | % else |
---|
| 187 | % save([ScratchDataFolder '/_LearnDLogScale_' learningType '/' Varfile '.mat'],'VarMap'); |
---|
| 188 | % end |
---|
| 189 | % else |
---|
| 190 | % if SkyExclude == 1 |
---|
| 191 | % save([ScratchDataFolder '/_nLearnDNonsky_' learningType '/' Varfile '.mat'],'VarMap'); |
---|
| 192 | % else |
---|
| 193 | % save([ScratchDataFolder '/_LearnD_' learningType '/' Varfile '.mat'],'VarMap'); |
---|
| 194 | % end |
---|
| 195 | % end |
---|
| 196 | % end |
---|
| 197 | end |
---|
| 198 | end |
---|