[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 []=PredictPlane(DepthDirectory,logScale) |
---|
| 40 | %this function generate the predicted plane |
---|
| 41 | % It is the depth MRF |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | % define global variable |
---|
| 45 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory... |
---|
| 46 | ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default... |
---|
| 47 | Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize; |
---|
| 48 | |
---|
| 49 | % load data |
---|
| 50 | load([ScratchDataFolder '/data/LowResImgIndexSuperpixelSep.mat']); % load LowResImgIndexSuperpixelSep |
---|
| 51 | load([ScratchDataFolder '/data/DiffLowResImgIndexSuperpixelSep.mat']); % load DiffLowResImgIndexSuperpixelSep(medi$large) |
---|
| 52 | load([ScratchDataFolder '/data/TextLowResImgIndexSuperpixelSep.mat']); % load TextLowResImgIndexSuperpixelSep using Textrea |
---|
| 53 | load([ScratchDataFolder '/data/MaskGSky.mat']); % load maskg maskSky from CMU's output |
---|
| 54 | load([ScratchDataFolder '/data/maskO.mat']); |
---|
| 55 | % load useful features |
---|
| 56 | load([ScratchDataFolder '/data/FeatureSuperpixel.mat']); % load the feature relate to position and shape of superpixe |
---|
| 57 | |
---|
| 58 | % prepare to store the predictedM |
---|
| 59 | system(['mkdir ' ScratchDataFolder '/_predicted_' DepthDirectory]); |
---|
| 60 | |
---|
| 61 | % set parameter |
---|
| 62 | ZTiltFactor = 1; % both can be estimated after group fit that estimate the Norm_floor |
---|
| 63 | YTiltFactor = 1; |
---|
| 64 | % initial parameter |
---|
| 65 | NuPics = size(filename,2); |
---|
| 66 | for i = [10]%1 : NuPics |
---|
| 67 | i |
---|
| 68 | % load picsinfo just for the horizontal value |
---|
| 69 | PicsinfoName = strrep(filename{i},'img','picsinfo'); |
---|
| 70 | temp = dir([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 71 | if size(temp,1) == 0 |
---|
| 72 | a = a_default; |
---|
| 73 | b = b_default; |
---|
| 74 | Ox = Ox_default; |
---|
| 75 | Oy = Oy_default; |
---|
| 76 | Horizon = Horizon_default; |
---|
| 77 | else |
---|
| 78 | load([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 79 | end |
---|
| 80 | |
---|
| 81 | % load useful feature |
---|
| 82 | BatchNumber = ceil(i/batchSize); |
---|
| 83 | PicsNumber = mod(i,batchSize); |
---|
| 84 | if PicsNumber ==0 |
---|
| 85 | PicsNumber = 10; |
---|
| 86 | end |
---|
| 87 | % load([ScratchDataFolder '/data/feature_sqrt_H4_ray' int2str(BatchNumber) '.mat']); % 'f' |
---|
| 88 | % f = f{PicsNumber}; |
---|
| 89 | % f = f(:,1); |
---|
| 90 | % fsup = FeatureSuperpixel{i}; |
---|
| 91 | % f = (fsup(1,f))'; |
---|
| 92 | |
---|
| 93 | % load depthMap |
---|
| 94 | depthfile = strrep(filename{i},'img','depth_learned'); % the depth filename |
---|
| 95 | if logScale == 1 |
---|
| 96 | load([ScratchDataFolder '/_LearnDLogScale_' DepthDirectory '/' depthfile '.mat']); |
---|
| 97 | else |
---|
| 98 | load([ScratchDataFolder '/_LearnD_' DepthDirectory '/' depthfile '.mat']); |
---|
| 99 | end |
---|
| 100 | |
---|
| 101 | LearnedDepth = depthMap; clear depthMap; |
---|
| 102 | |
---|
| 103 | % initialize parameter |
---|
| 104 | NuPatch = VertYNuDepth*HoriXNuDepth; |
---|
| 105 | |
---|
| 106 | % generate specific ray for whole pics |
---|
| 107 | RayCenter = GenerateRay(HoriXNuDepth,VertYNuDepth,'center',a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3] |
---|
| 108 | Rx = RayCenter(:,:,1); |
---|
| 109 | Rx = Rx(:); |
---|
| 110 | Ry = RayCenter(:,:,2); |
---|
| 111 | Ry = Ry(:); |
---|
| 112 | Rz = RayCenter(:,:,3); |
---|
| 113 | Rz = Rz(:); |
---|
| 114 | %RayCorner = GenerateRay(HoriXNuDepth,VertYNuDepth,'corner',a,b,Ox,Oy); %[ horiXSizeLowREs+1 VertYSizeLowREs+1 3] |
---|
| 115 | %===================================================== |
---|
| 116 | % MRF reshape the 3d cloud |
---|
| 117 | |
---|
| 118 | %============================ |
---|
| 119 | % setting the estimated Ground Verticl Sky segmentation (generated from CMU's code) |
---|
| 120 | maskEstGVS = 2*ones(VertYNuDepth,HoriXNuDepth); |
---|
| 121 | maskEstGVS(maskg{i}) = 1; |
---|
| 122 | maskEstGVS(maskSky{i}) = 3; |
---|
| 123 | %GSize = sum(maskg{i}); |
---|
| 124 | %SkySize = sum(maskSky{i}); |
---|
| 125 | %============================ |
---|
| 126 | |
---|
| 127 | NuSupType = size(LowResImgIndexSuperpixelSep,2)+size(DiffLowResImgIndexSuperpixelSep,2)... |
---|
| 128 | +size(TextLowResImgIndexSuperpixelSep,2)*size(TextLowResImgIndexSuperpixelSep,3); |
---|
| 129 | |
---|
| 130 | for j = 1:NuSupType % total 21 seg : 3 RGB 6*3= 18 texture filters |
---|
| 131 | |
---|
| 132 | % pick the specific segmentation |
---|
| 133 | if j==1 |
---|
| 134 | sup = LowResImgIndexSuperpixelSep{i,1}; |
---|
| 135 | elseif j<=3 |
---|
| 136 | sup = DiffLowResImgIndexSuperpixelSep{i,j-1}; |
---|
| 137 | else |
---|
| 138 | Subm = mod((j-3),6); |
---|
| 139 | if Subm==0 |
---|
| 140 | Subm=6; |
---|
| 141 | end |
---|
| 142 | sup = TextLowResImgIndexSuperpixelSep{i,Subm,ceil((j-3)/6)}; |
---|
| 143 | end |
---|
| 144 | |
---|
| 145 | % extend the estimated maskGVS to the new segmentation |
---|
| 146 | NewSupInd = (unique(sup))'; |
---|
| 147 | NewEstGSup = zeros(VertYNuDepth,HoriXNuDepth); |
---|
| 148 | NewEstVSup = zeros(VertYNuDepth,HoriXNuDepth); |
---|
| 149 | NewEstSSup = zeros(VertYNuDepth,HoriXNuDepth); |
---|
| 150 | for m = NewSupInd |
---|
| 151 | mask = sup == m; |
---|
| 152 | if any(maskEstGVS(mask)==1) && any(maskEstGVS(mask)==3) |
---|
| 153 | GVSInd = analysesupinpatch(maskEstGVS(mask)); |
---|
| 154 | elseif any(maskEstGVS(mask)==1) |
---|
| 155 | GVSInd =1; |
---|
| 156 | elseif any(maskEstGVS(mask)==3) |
---|
| 157 | GVSInd =3; |
---|
| 158 | else |
---|
| 159 | GVSInd =2; |
---|
| 160 | end |
---|
| 161 | %GVSInd = analysesupinpatch(maskEstGVS(mask)); |
---|
| 162 | if GVSInd == 1 |
---|
| 163 | NewEstGSup(mask) = m; |
---|
| 164 | NewEstVSup(mask) = 0; |
---|
| 165 | NewEstSSup(mask) = 0; |
---|
| 166 | elseif GVSInd == 2 |
---|
| 167 | NewEstVSup(mask) = m; |
---|
| 168 | NewEstGSup(mask) = -1; |
---|
| 169 | NewEstSSup(mask) = -1; |
---|
| 170 | else |
---|
| 171 | NewEstSSup(mask) = m; |
---|
| 172 | NewEstGSup(mask) = -2; |
---|
| 173 | NewEstVSup(mask) = -2; |
---|
| 174 | end |
---|
| 175 | end |
---|
| 176 | %if j == 2 |
---|
| 177 | % SpreadFactor = gen_SFactor(LearnedDepth,sup,Rz); |
---|
| 178 | %end |
---|
| 179 | %clear LowResImgIndexSuperpixelSep; |
---|
| 180 | |
---|
| 181 | % 2nd order smooth |
---|
| 182 | [SecXG(j,:) SecYG(j,:)]= gen_2ndSmooth(NewEstGSup); |
---|
| 183 | [SecXV(j,:) SecYV(j,:)]= gen_2ndSmooth(NewEstVSup); |
---|
| 184 | [SecXS(j,:) SecYS(j,:)]= gen_2ndSmooth(NewEstSSup); |
---|
| 185 | |
---|
| 186 | % 1st order smooth |
---|
| 187 | [FirstYG(j,:) FirstXG(j,:)] = gen_1stSmooth(NewEstGSup); |
---|
| 188 | [FirstYV(j,:) FirstXV(j,:)] = gen_1stSmooth(NewEstVSup); |
---|
| 189 | [FirstYS(j,:) FirstXS(j,:)] = gen_1stSmooth(NewEstSSup); |
---|
| 190 | %[GPy{j} ] = gen_GravityP_vertical(maskV); |
---|
| 191 | %[PlanePriorX PlanePriorY]= gen_PlanePrior(LowResImgIndexSuperpixelSep{i,1}); |
---|
| 192 | end |
---|
| 193 | |
---|
| 194 | % set weight for different segmentation |
---|
| 195 | small=50; med=25; large=5; |
---|
| 196 | temp =[small; med; large; small*ones(6,1); med*ones(6,1) ;large*ones(6,1)] |
---|
| 197 | Wei2ndSmoothGX = temp; |
---|
| 198 | Wei2ndSmoothGY = temp; |
---|
| 199 | Wei2ndSmoothVX = temp; |
---|
| 200 | Wei2ndSmoothVY = temp; |
---|
| 201 | Wei2ndSmoothSX = temp; |
---|
| 202 | Wei2ndSmoothSY = temp; |
---|
| 203 | Wei1stSmoothGX = temp; |
---|
| 204 | Wei1stSmoothGY = temp; |
---|
| 205 | Wei1stSmoothVX = temp; |
---|
| 206 | Wei1stSmoothVY = temp; |
---|
| 207 | Wei1stSmoothSX = temp; |
---|
| 208 | Wei1stSmoothSY = temp; |
---|
| 209 | |
---|
| 210 | % generate the smooth matrix |
---|
| 211 | M2ndSmoothY = spdiags([ones(NuPatch,1) -2*ones(NuPatch,1) ones(NuPatch,1)],[-1 0 1],NuPatch,NuPatch); |
---|
| 212 | M2ndSmoothX = spdiags([ones(NuPatch,1) -2*ones(NuPatch,1) ones(NuPatch,1)],... |
---|
| 213 | [-VertYNuDepth 0 VertYNuDepth],NuPatch,NuPatch); |
---|
| 214 | M1stSmoothY = spdiags([ones(NuPatch,1) -ones(NuPatch,1)],[0 1],NuPatch,NuPatch); |
---|
| 215 | M1stSmoothX = spdiags([ones(NuPatch,1) -ones(NuPatch,1)],[0 VertYNuDepth],NuPatch,NuPatch); |
---|
| 216 | |
---|
| 217 | % generate beta |
---|
| 218 | beta2ndSmoothGX = Wei2ndSmoothGX'*SecXG; |
---|
| 219 | beta2ndSmoothGY = Wei2ndSmoothGY'*SecYG; |
---|
| 220 | beta2ndSmoothVX = Wei2ndSmoothVX'*SecXV; |
---|
| 221 | beta2ndSmoothVY = Wei2ndSmoothVY'*SecYV; |
---|
| 222 | beta2ndSmoothSX = Wei2ndSmoothSX'*SecXS; |
---|
| 223 | beta2ndSmoothSY = Wei2ndSmoothSY'*SecYS; |
---|
| 224 | beta1stSmoothGY = Wei2ndSmoothGY'*FirstYG; |
---|
| 225 | beta1stSmoothVY = Wei2ndSmoothVY'*FirstYV; |
---|
| 226 | beta1stSmoothSY = Wei2ndSmoothSY'*FirstYS; |
---|
| 227 | beta1stSmoothGX = Wei2ndSmoothGX'*FirstXG; |
---|
| 228 | beta1stSmoothVX = Wei2ndSmoothVX'*FirstXV; |
---|
| 229 | beta1stSmoothSX = Wei2ndSmoothSX'*FirstXS; |
---|
| 230 | |
---|
| 231 | % generate Q |
---|
| 232 | Q2ndXx = spdiags((beta2ndSmoothGX+beta2ndSmoothVX+beta2ndSmoothSX)'... |
---|
| 233 | ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rx,0,NuPatch,NuPatch); |
---|
| 234 | Q2ndXy = spdiags((beta2ndSmoothGX+beta2ndSmoothVX+beta2ndSmoothSX)'... |
---|
| 235 | ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Ry,0,NuPatch,NuPatch); |
---|
| 236 | Q2ndXz = spdiags((beta2ndSmoothGX+beta2ndSmoothVX+beta2ndSmoothSX)'... |
---|
| 237 | ,0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rz,0,NuPatch,NuPatch); |
---|
| 238 | Q2ndYx = spdiags((beta2ndSmoothGY+beta2ndSmoothVY+beta2ndSmoothSY)'... |
---|
| 239 | ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rx,0,NuPatch,NuPatch); |
---|
| 240 | Q2ndYy = spdiags((beta2ndSmoothGY+beta2ndSmoothVY+beta2ndSmoothSY)'... |
---|
| 241 | ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Ry,0,NuPatch,NuPatch); |
---|
| 242 | Q2ndYz = spdiags((beta2ndSmoothGY+beta2ndSmoothVY+beta2ndSmoothSY)'... |
---|
| 243 | ,0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rz,0,NuPatch,NuPatch); |
---|
| 244 | |
---|
| 245 | Q1stYz = spdiags((beta1stSmoothVY+beta1stSmoothSY)'... |
---|
| 246 | ,0,NuPatch,NuPatch)*M1stSmoothY*spdiags(Rz*ZTiltFactor,0,NuPatch,NuPatch); |
---|
| 247 | Q1stYy = spdiags((beta1stSmoothGY)'... |
---|
| 248 | ,0,NuPatch,NuPatch)*M1stSmoothY*spdiags(Ry*YTiltFactor,0,NuPatch,NuPatch); |
---|
| 249 | Q1stXz = spdiags((beta1stSmoothGX+beta1stSmoothVX+beta1stSmoothSX)'... |
---|
| 250 | ,0,NuPatch,NuPatch)*M1stSmoothX*spdiags(Rz*ZTiltFactor,0,NuPatch,NuPatch); |
---|
| 251 | % Q2ndGXx = spdiags(beta2ndSmoothGX',0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rx,0,NuPatch,NuPatch); |
---|
| 252 | % Q2ndGXy = spdiags(beta2ndSmoothGX',0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Ry,0,NuPatch,NuPatch); |
---|
| 253 | % Q2ndGXz = spdiags(beta2ndSmoothGX',0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rz,0,NuPatch,NuPatch); |
---|
| 254 | % Q2ndVXx = spdiags(beta2ndSmoothVX',0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rx,0,NuPatch,NuPatch); |
---|
| 255 | % Q2ndVXy = spdiags(beta2ndSmoothVX',0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Ry,0,NuPatch,NuPatch); |
---|
| 256 | % Q2ndVXz = spdiags(beta2ndSmoothVX',0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rz,0,NuPatch,NuPatch); |
---|
| 257 | % Q2ndSXx = spdiags(beta2ndSmoothSX',0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rx,0,NuPatch,NuPatch); |
---|
| 258 | % Q2ndSXy = spdiags(beta2ndSmoothSX',0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Ry,0,NuPatch,NuPatch); |
---|
| 259 | % Q2ndSXz = spdiags(beta2ndSmoothSX',0,NuPatch,NuPatch)*M2ndSmoothX*spdiags(Rz,0,NuPatch,NuPatch); |
---|
| 260 | % |
---|
| 261 | % Q2ndGYx = spdiags(beta2ndSmoothGY',0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rx,0,NuPatch,NuPatch); |
---|
| 262 | % Q2ndGYy = spdiags(beta2ndSmoothGY',0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Ry,0,NuPatch,NuPatch); |
---|
| 263 | % Q2ndGYz = spdiags(beta2ndSmoothGY',0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rz,0,NuPatch,NuPatch); |
---|
| 264 | % Q2ndVYx = spdiags(beta2ndSmoothVY',0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rx,0,NuPatch,NuPatch); |
---|
| 265 | % Q2ndVYy = spdiags(beta2ndSmoothVY',0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Ry,0,NuPatch,NuPatch); |
---|
| 266 | % Q2ndVYz = spdiags(beta2ndSmoothVY',0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rz,0,NuPatch,NuPatch); |
---|
| 267 | % Q2ndSYx = spdiags(beta2ndSmoothSY',0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rx,0,NuPatch,NuPatch); |
---|
| 268 | % Q2ndSYy = spdiags(beta2ndSmoothSY',0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Ry,0,NuPatch,NuPatch); |
---|
| 269 | % Q2ndSYz = spdiags(beta2ndSmoothSY',0,NuPatch,NuPatch)*M2ndSmoothY*spdiags(Rz,0,NuPatch,NuPatch); |
---|
| 270 | % ============================START MRF OPTMIZATIOM========================================================= |
---|
| 271 | %================= |
---|
| 272 | % generate mask for depth difference |
---|
| 273 | YDiff = repmat(logical([ones(VertYNuDepth-1,1); 0]),1,HoriXNuDepth); |
---|
| 274 | XDiff = repmat(([ones(1,HoriXNuDepth-1) 0]),VertYNuDepth,1); |
---|
| 275 | DMatrixY = spdiags([ones(NuPatch,1) -ones(NuPatch,1)],[0 1],NuPatch,NuPatch); |
---|
| 276 | DMatrixY = DMatrixY(~maskO,:); |
---|
| 277 | DMatrixX = spdiags([ones(NuPatch,1) -ones(NuPatch,1)],[0 VertYNuDepth],NuPatch,NuPatch); |
---|
| 278 | %================= |
---|
| 279 | tic; |
---|
| 280 | % B = [DMatrixY;spdiags(maskO(:),[0],NuPatch,NuPatch)]; |
---|
| 281 | % Q = [Q2ndXz;Q2ndYz]; |
---|
| 282 | % A = [B -speye(size(B,1)) sparse(size(B,1),size(Q,1));... |
---|
| 283 | % -B -speye(size(B,1)) sparse(size(B,1),size(Q,1));... |
---|
| 284 | % Q sparse(size(Q,1),size(B,1)) -speye(size(Q,1));... |
---|
| 285 | % -Q sparse(size(Q,1),size(B,1)) -speye(size(Q,1));... |
---|
| 286 | % -speye(NuPatch) sparse(NuPatch,size(B,1)+size(Q,1))]; |
---|
| 287 | % bb = [B*LearnedDepth(:); - B*LearnedDepth(:);... |
---|
| 288 | % sparse(size(Q,1)*2,1); -5*ones(NuPatch,1)]; |
---|
| 289 | % f = [sparse(NuPatch,1); ones(size(B,1)+size(Q,1),1)]; |
---|
| 290 | % x = linprog(f,A,bb); |
---|
| 291 | % predictedM = spdiags([ones(1,NuPatch) sparse(1,size(B,1)+size(Q,1))]',0,NuPatch... |
---|
| 292 | % ,NuPatch+size(B,1)+size(Q,1))*x; |
---|
| 293 | %predictedM = (LearnedDepth(:)); |
---|
| 294 | cvx_begin |
---|
| 295 | cvx_quiet(false); |
---|
| 296 | variable predictedM(NuPatch,1); |
---|
| 297 | minimize(norm(DMatrixY*(predictedM - LearnedDepth(:)),1)... |
---|
| 298 | +norm((predictedM(maskO) - LearnedDepth(maskO)),1)... |
---|
| 299 | +norm([Q2ndXz;Q2ndYz]*predictedM)... |
---|
| 300 | +norm([Q1stXz]*predictedM)); |
---|
| 301 | |
---|
| 302 | %+norm((beta1stSmoothGY+beta1stSmoothGX)'.*(predictedM - LearnedDepth(:)))... |
---|
| 303 | %+norm([Q1stYy ;Q1stYz; Q1stXz]*predictedM)); |
---|
| 304 | %minimize(norm(predictedM - LearnedDepth(:))... |
---|
| 305 | % +norm([Q1stYy ;Q1stYz; Q1stXz]*predictedM)... |
---|
| 306 | % +norm([Q2ndXz;Q2ndYz]*predictedM));%... % 2nd smooth Ground |
---|
| 307 | % %+norm([Q1stYz]*predictedM)); |
---|
| 308 | % % +norm([Q2ndXz;Q2ndVYz]*predictedM,1)... % vertical |
---|
| 309 | % % +norm([Q2ndSXz;Q2ndSYz]*predictedM,1)); % Sky |
---|
| 310 | % % +norm([Q2ndGXx;Q2ndGXy;Q2ndGXz;Q2ndGYx;Q2ndGYy;Q2ndGYz]*predictedM)... % 2nd smooth Ground |
---|
| 311 | % % +norm([Q2ndVXx;Q2ndVXy;Q2ndVXz;Q2ndVYx;Q2ndVYy;Q2ndVYz]*predictedM)... % vertical |
---|
| 312 | % % +norm([Q2ndSXx;Q2ndSXy;Q2ndSXz;Q2ndSYx;Q2ndSYy;Q2ndSYz]*predictedM)); % Sky |
---|
| 313 | % % + 100*norm(IPx{1}*(predictedM),1)...%+ 10*norm(IPx{2}*(predictedM.*Ry))+ 10*norm(IPx{2}*(predictedM.*Rz)).. |
---|
| 314 | % % + 100*norm(IPy{1}*(predictedM),1)...%+ 10*norm(IPy{2}*(predictedM.*Ry))+ 10*norm(IPy{2}*(predictedM.*Rz))... |
---|
| 315 | % % + 50*norm(IPx{2}*(predictedM),1)...%+ 10*norm(IPx{2}*(predictedM.*Ry))+ 10*norm(IPx{2}*(predictedM.*Rz)).. |
---|
| 316 | % % + 50*norm(IPy{2}*(predictedM),1)...%+ 10*norm(IPy{2}*(predictedM.*Ry))+ 10*norm(IPy{2}*(predictedM.*Rz))... |
---|
| 317 | % % + 5000*norm(GPy{5}*(predictedM.*Rz))... |
---|
| 318 | % % + 5000*norm(spdiags([ones(GSize,1) -ones(GSize,1)],[0 1],GSize-1,GSize)*(predictedM(maskg).*Ry(maskg)))... |
---|
| 319 | % % + 5000*norm(spdiags([ones(SkySize,1) -ones(SkySize,1)],[0 1],SkySize-1,SkySize)*(predictedM(masksky).*Rz(masksky)))); |
---|
| 320 | % % %+ 5000*norm(Gpy*(predictedM.*Ry))... |
---|
| 321 | % %+ 5000*norm(spdiags([ones(SkySize,1) -1*ones(SkySize,1)],[0 1],SkySize-1,SkySize)*(predictedM(masksky).*Rz(masksky)))); |
---|
| 322 | % %spdiags([ones(GSize,1) -ones(GSize,1)],[0 1],GSize-1,GSize)*(predictedM(maskg).*Ry(maskg)) == 0; |
---|
| 323 | % %spdiags([ones(SkySize,1) -ones(SkySize,1)],[0 1],SkySize-1,SkySize)*(predictedM(masksky).*Rz(masksky)) == 0; |
---|
| 324 | predictedM>=5; |
---|
| 325 | % %predictedM<=81; |
---|
| 326 | cvx_end |
---|
| 327 | toc; |
---|
| 328 | Date =date; |
---|
| 329 | predictedM =reshape(predictedM,VertYNuDepth,[]); |
---|
| 330 | depthMap = predictedM; |
---|
| 331 | save([ScratchDataFolder '/_predicted_' DepthDirectory '/' depthfile '_' num2str(logScale) '_' Date '.mat'],'depthMap'); |
---|
| 332 | clear depthMap; |
---|
| 333 | |
---|
| 334 | %===================================================== |
---|
| 335 | % 2d to would 3d |
---|
| 336 | [Position3DPredicted] = im_cr2w_cr(predictedM,RayCenter); |
---|
| 337 | |
---|
| 338 | % generate new LowResImgIndexSuperpixelSep_deoffset |
---|
| 339 | %LowResImgIndexSuperpixelSep_deoffset = LowResImgIndexSuperpixelSep{i}; |
---|
| 340 | |
---|
| 341 | % add on image feature |
---|
| 342 | %global Imf; |
---|
| 343 | %Imf= cat(1,Position3DPredicted,permute(ones(VertY,1)*[1:HoriX],[3 1 2]), permute([1:VertY]'*ones(1,HoriX),[3 1 2]),permute(double(zeros(VertY,HoriX,3)),[3 1 2]),permute(double(LowResImgIndexSuperpixelSep_deoffset),[3 1 2]),permute(double(LowResImgIndexSuperpixelSep{i}),[3 1 2]) ); |
---|
| 344 | |
---|
| 345 | % calculate each plane parameter for each superpixel |
---|
| 346 | %[PlaneParameterPredicted] = fit_all_planes(RayLoResCorner); % hard work around 2min |
---|
| 347 | |
---|
| 348 | % generate VRML |
---|
| 349 | Date = date; |
---|
| 350 | [VrmlName] = vrml_test_faceset_triangle(filename{i},Position3DPredicted,RayCenter,['PredictM_' DepthDirectory '_' num2str(logScale) '_' Date '_Diff'],a,b,Ox,Oy); |
---|
| 351 | system(['gzip -9 -c ' ScratchDataFolder '/vrml/' VrmlName ' > ' ScratchDataFolder '/vrml/' VrmlName '.gz']); |
---|
| 352 | delete([ScratchDataFolder '/vrml/' VrmlName]); |
---|
| 353 | %vrml_test_faceset_triangle(filename{i},PlaneParameterPredicted,LowResImgIndexSuperpixelSep{i},LowResImgIndexSuperpixelSep_deoffset,[DepthDirectory '_' Date]); |
---|
| 354 | end |
---|