[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 [] = GenAveFeaSup(batchNumber, Nei, AbsFeaType, AbsFeaDate) |
---|
| 40 | |
---|
| 41 | % This function calculate the feature of each subsuperpixel using texture |
---|
| 42 | % infomation |
---|
| 43 | |
---|
| 44 | if nargin < 1 |
---|
| 45 | batchNumber = 1; |
---|
| 46 | end |
---|
| 47 | |
---|
| 48 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory... |
---|
| 49 | ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default... |
---|
| 50 | Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize PopUpVertY PopUpHoriX taskName; |
---|
| 51 | |
---|
| 52 | % ================================================================================== |
---|
| 53 | % may chage for different usage |
---|
| 54 | %load([ScratchDataFolder '/data/LowResImgIndexSuperpixelSep.mat']); % superpixel_index |
---|
| 55 | %load([ScratchDataFolder '/data/DiffLowResImgIndexSuperpixelSep.mat']); |
---|
| 56 | %load([ScratchDataFolder '/data/TextLowResImgIndexSuperpixelSep.mat']); |
---|
| 57 | % ================================================================================== |
---|
| 58 | % load FeaMax to do normalizeing |
---|
| 59 | load([GeneralDataFolder '/FeaMax.mat']); |
---|
| 60 | FeaMax = 10.^floor(log10(FeaMax)); |
---|
| 61 | |
---|
| 62 | %load([ScratchDataFolder '/data/MaskGSky.mat']); % load maskg maskSky from CMU's output |
---|
| 63 | %clear maskg; |
---|
| 64 | |
---|
| 65 | % prepare data step |
---|
| 66 | nu_pics = size(filename,2); % number of picture |
---|
| 67 | |
---|
| 68 | batchImg = 1:batchSize:nu_pics; |
---|
| 69 | l = 1; |
---|
| 70 | for i = batchImg(batchNumber):min(batchImg(batchNumber)+batchSize-1, nu_pics) |
---|
| 71 | %for i = [10:18 54:62] |
---|
| 72 | tic |
---|
| 73 | i |
---|
| 74 | % ================================================================================== |
---|
| 75 | % may chage for different usage |
---|
| 76 | %load([ScratchDataFolder '/data/LowResImgIndexSuperpixelSep.mat']); % superpixel_index |
---|
| 77 | load([ScratchDataFolder '/data/DiffLowResImgIndexSuperpixelSep.mat']); |
---|
| 78 | %load([ScratchDataFolder '/data/TextLowResImgIndexSuperpixelSep.mat']); |
---|
| 79 | % ================================================================================== |
---|
| 80 | % load([ScratchDataFolder '/data/MedSeg/MediResImgIndexSuperpixelSep' num2str(i) '.mat']); |
---|
| 81 | % Sup = LowResImgIndexSuperpixelSep{i}; clear LowResImgIndexSuperpixelSep; |
---|
| 82 | % MedSup = MediResImgIndexSuperpixelSep; clear MediResImgIndexSuperpixelSep; |
---|
| 83 | DiffSup = DiffLowResImgIndexSuperpixelSep(i,end); clear DiffLowResImgIndexSuperpixelSep; |
---|
| 84 | % TextSup = TextLowResImgIndexSuperpixelSep(i,:,2:end); clear TextLowResImgIndexSuperpixelSep; |
---|
| 85 | batchNumber,% MedSup = imresize(MedSup, [vertical_size_hi_res horizontal_size_hi_res]); |
---|
| 86 | |
---|
| 87 | % load MediResImgIndexSuperpixelSep |
---|
| 88 | % decide to claen the Sup or not (means imclosing) |
---|
| 89 | %[Sup,MedSup]=CleanedSup(Sup,MedSup,maskSky{i}); |
---|
| 90 | load([ScratchDataFolder '/data/CleanSup/CleanSup' num2str(i) '.mat']); |
---|
| 91 | % check if the MedSup and Sup have the same index |
---|
| 92 | % !!!!!!!Don't need to check it since later working on Sup scale only |
---|
| 93 | % Res = setdiff(unique(MedSup(:)),unique(Sup(:))); |
---|
| 94 | % if ~isempty(Res) |
---|
| 95 | % disp('error index from MedSup to Sup'); |
---|
| 96 | % return; |
---|
| 97 | % end |
---|
| 98 | |
---|
| 99 | MedSup = double(MedSup); |
---|
| 100 | Sup = double(Sup); |
---|
| 101 | maskSky{i} = Sup == 0; % the new skymap |
---|
| 102 | |
---|
| 103 | % load picsinfo just for the horizontal value |
---|
| 104 | PicsinfoName = strrep(filename{l},'img','picsinfo'); |
---|
| 105 | temp = dir([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 106 | if size(temp,1) == 0 |
---|
| 107 | a = a_default; |
---|
| 108 | b = b_default; |
---|
| 109 | Ox = Ox_default; |
---|
| 110 | Oy = Oy_default; |
---|
| 111 | Horizon = Horizon_default; |
---|
| 112 | else |
---|
| 113 | load([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 114 | end |
---|
| 115 | |
---|
| 116 | % 1) Analyze Sup : SupFact with NuPatchEachSup and all 13 features calcuate in gen_fsup_new |
---|
| 117 | [SupFact, nList] = AnalyzeSup(Sup,maskSky{i}); % Calculate for H2 |
---|
| 118 | % load([ScratchDataFolder '/data/temp/List' num2str(i) '.mat']); |
---|
| 119 | % ====================== |
---|
| 120 | BounaryPHori = conv2(Sup,[1 -1],'same') ~=0; |
---|
| 121 | BounaryPHori(:,end) = 0; |
---|
| 122 | BounaryPVert = conv2(Sup,[1; -1],'same') ~=0; |
---|
| 123 | BounaryPVert(end,:) = 0; |
---|
| 124 | ClosestNList = [ Sup(find(BounaryPHori==1)) Sup(find(BounaryPHori==1)+VertYNuDepth);... |
---|
| 125 | Sup(find(BounaryPVert==1)) Sup(find(BounaryPVert==1)+1)]; |
---|
| 126 | ClosestNList = sort(ClosestNList,2); |
---|
| 127 | ClosestNList = unique(ClosestNList,'rows'); |
---|
| 128 | ClosestNList(ClosestNList(:,1) == 0,:) = []; |
---|
| 129 | % MedBounaryPHori = conv2(MedSup,[1 -1],'same') ~=0; |
---|
| 130 | % MedBounaryPHori(:,end) = 0; |
---|
| 131 | % MedBounaryPVert = conv2(MedSup,[1; -1],'same') ~=0; |
---|
| 132 | % MedBounaryPVert(end,:) = 0; |
---|
| 133 | % MedClosestNList = [ MedSup(find(MedBounaryPHori==1)) MedSup(find(MedBounaryPHori==1)+SegVertYSize);... |
---|
| 134 | % MedSup(find(MedBounaryPVert==1)) MedSup(find(MedBounaryPVert==1)+1)]; |
---|
| 135 | % MedClosestNList = sort(MedClosestNList,2); |
---|
| 136 | % MedClosestNList = unique(MedClosestNList,'rows'); |
---|
| 137 | % MedClosestNList(MedClosestNList(:,1) == 0,:) = []; |
---|
| 138 | % nList = [ClosestNList; MedClosestNList]; |
---|
| 139 | % nList = unique(nList,'rows'); |
---|
| 140 | nList = ClosestNList; |
---|
| 141 | % ======================================================================================================= |
---|
| 142 | % calculate all the features, ray, plane parameter, and row column value |
---|
| 143 | img = imread([GeneralDataFolder '/' ImgFolder '/' filename{l} '.jpg']);% read hi resolution image |
---|
| 144 | |
---|
| 145 | % check if the images resolusion is smaller then a certain size |
---|
| 146 | if prod(size(img))<SegVertYSize*SegHoriXSize*3 |
---|
| 147 | disp('imresize hard work'); |
---|
| 148 | img = imresize(img,[SegVertYSize SegHoriXSize],'bilinear'); |
---|
| 149 | end |
---|
| 150 | [vertical_size_hi_res horizontal_size_hi_res t] = size(img); clear t; |
---|
| 151 | |
---|
| 152 | % generate lineseg |
---|
| 153 | % seglist=edgeSegDetection(img,i); |
---|
| 154 | |
---|
| 155 | % generate the texture features |
---|
| 156 | disp('going to cal Fea') |
---|
| 157 | |
---|
| 158 | % Start Sup relation with the 7 * 2 = 14 Multi Sup |
---|
| 159 | [MultiScaleSupTable] = MultiScalAnalyze( Sup, permute( cat( 3, DiffSup{1,1}),...% DiffSup{1,2},... |
---|
| 160 | [3 1 2])); |
---|
| 161 | % TextSup{1,1,1}, TextSup{1,1,2},... |
---|
| 162 | % TextSup{1,2,1}, TextSup{1,2,2},... |
---|
| 163 | % TextSup{1,3,1}, TextSup{1,3,2},... |
---|
| 164 | % TextSup{1,4,1}, TextSup{1,4,2},... |
---|
| 165 | % TextSup{1,5,1}, TextSup{1,5,2},... |
---|
| 166 | % TextSup{1,6,1}, TextSup{1,6,2}),... |
---|
| 167 | clear DiffSup;% TextSup; |
---|
| 168 | |
---|
| 169 | global H2; |
---|
| 170 | [H2] = calculateFilterBanks_old(img); % (hard work 1min) use Ashutaosh's code |
---|
| 171 | clear img; |
---|
| 172 | H2 = permute(H2,[3 1 2]); |
---|
| 173 | |
---|
| 174 | % run Rajiv Code |
---|
| 175 | % FeaNList = findBoundaryFeaturesMore( Sup, MedSup, nList(:,1:2), seglist, FeaMax, 0); |
---|
| 176 | % clear seglist; |
---|
| 177 | |
---|
| 178 | % Calculate the AveSupFea % H1 first |
---|
| 179 | [SupFea ] = AveSupFea(Sup, MedSup, SupFact, MultiScaleSupTable, FeaMax, 1); % Maight can be faster when doing calcuating fea from MultiScaleSupTable |
---|
| 180 | H2 = H2.^2; % then H2 |
---|
| 181 | [TempSupFea ] = AveSupFea(Sup, MedSup, SupFact, MultiScaleSupTable, FeaMax, 2); % Maight can be faster when doing calcuating fea from MultiScaleSupTable |
---|
| 182 | SupFea = [SupFea TempSupFea(:,2:end)]; % Maight can be faster when doing calcuating fea from MultiScaleSupTable |
---|
| 183 | H2 = H2.^2; % then H4 |
---|
| 184 | TempSupFea = AveSupFea(Sup, MedSup, SupFact, MultiScaleSupTable, FeaMax, 4); |
---|
| 185 | SupFea = [SupFea TempSupFea(:,2:end)]; % Maight can be faster when doing calcuating fea from MultiScaleSupTable |
---|
| 186 | clear MultiScaleSupTable TempSupFea; |
---|
| 187 | clear global H2; |
---|
| 188 | toc |
---|
| 189 | |
---|
| 190 | % gnerate Feature as the same row of nList , and |
---|
| 191 | tic |
---|
| 192 | if Nei |
---|
| 193 | load([ScratchDataFolder '/data/feature_Abs_' AbsFeaType int2str(batchNumber) '_' AbsFeaDate '.mat']); % 'f' |
---|
| 194 | else |
---|
| 195 | f = []; |
---|
| 196 | end |
---|
| 197 | |
---|
| 198 | % add new option to include Col feature 103*2 col features and 103*2 row features and 103*4 Nei features |
---|
| 199 | [FeaNList, nList] = GenFeaParaNList( Sup, MedSup, maskSky{i}, nList, SupFact, SupFea, FeaMax, Nei, f{i-10*(batchNumber-1)}, i); |
---|
| 200 | clear f; |
---|
| 201 | % FeaNList = [ FeaNListTemp FeaNList]; |
---|
| 202 | toc |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | disp([ScratchDataFolder '/data/SupFea/FeaNList' num2str(i) 'new.mat']); |
---|
| 206 | save([ScratchDataFolder '/data/SupFea/FeaNList' num2str(i) 'new.mat'],'FeaNList','nList'); |
---|
| 207 | %return; |
---|
| 208 | % save([ScratchDataFolder '/data/SupFea/DiffA_Alpha' num2str(i) '.mat'],'DiffA','DiffAlpha'); |
---|
| 209 | clear FeaNListTemp nList Sup MedSup nList SupFact SupFea FeaNList; |
---|
| 210 | l= l+1; |
---|
| 211 | end |
---|
| 212 | %save([ScratchDataFolder '/data/SupFea/FeaNList' num2str(i) '.mat'],'FeaNList','nList'); |
---|
| 213 | %save([ScratchDataFolder '/data/SupFea/DiffA_Alpha' num2str(i) '.mat'],'DiffA','DiffAlpha'); |
---|
| 214 | return; |
---|