[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 [] = RunCompleteMRF(BatchNu,LearnType,LearnSkyEx,LearnLog,LearnNear,... |
---|
| 40 | LearnAlg,baseline,step); |
---|
| 41 | |
---|
| 42 | % selected image with low error as train data set |
---|
| 43 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory... |
---|
| 44 | ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default... |
---|
| 45 | Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize PopUpVertY PopUpHoriX taskName; |
---|
| 46 | |
---|
| 47 | if nargin < 8 |
---|
| 48 | step = [3]; |
---|
| 49 | end |
---|
| 50 | %load([ScratchDataFolder '/../MinTest/data/MinTestFileName.mat']); |
---|
| 51 | %load([ScratchDataFolder '/../MinTest/data/MaskGSky.mat']); |
---|
| 52 | load([ScratchDataFolder '/data/MaskGSky.mat']); |
---|
| 53 | previoslyStored = false; |
---|
| 54 | MultiScaleSup = true; |
---|
| 55 | learned = true; |
---|
| 56 | %PicsInd = [10:16 18 54:62]; |
---|
| 57 | PicsInd = 1:size(filename,2); |
---|
| 58 | %BatchSize = 5; |
---|
| 59 | BatchSize = 1; |
---|
| 60 | NuPics = size(filename,2); |
---|
| 61 | BatchRow = 1:BatchSize:NuPics; |
---|
| 62 | STNeeded = false |
---|
| 63 | %for i = 1:NuPics |
---|
| 64 | for i = BatchRow(BatchNu):min(BatchRow(BatchNu)+BatchSize-1,NuPics) |
---|
| 65 | % i |
---|
| 66 | PicsinfoName = strrep(filename{i},'img','picsinfo'); |
---|
| 67 | temp = dir([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 68 | if size(temp,1) == 0 |
---|
| 69 | a = a_default; |
---|
| 70 | b = b_default; |
---|
| 71 | Ox = Ox_default; |
---|
| 72 | Oy = Oy_default; |
---|
| 73 | Horizon = Horizon_default; |
---|
| 74 | else |
---|
| 75 | load([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']); |
---|
| 76 | end |
---|
| 77 | |
---|
| 78 | load([ScratchDataFolder '/data/CleanSup/CleanSup' num2str(PicsInd(i)) '.mat']); |
---|
| 79 | [SegVertYSize, SegHoriXSize] = size(MedSup); |
---|
| 80 | MedSup = double(MedSup); |
---|
| 81 | Sup = double(Sup); |
---|
| 82 | |
---|
| 83 | % load |
---|
| 84 | depthfile = strrep(filename{i},'img','depth_learned'); % the depth filename |
---|
| 85 | if baseline == 1 |
---|
| 86 | DepthFolder = [ LearnType '_' LearnAlg ... |
---|
| 87 | '_Nonsky' num2str(LearnSkyEx) '_Log' num2str(LearnLog) ... |
---|
| 88 | '_Near' num2str(LearnNear) '_baseline']; |
---|
| 89 | load([ScratchDataFolder '/' DepthFolder '/' depthfile '.mat']); |
---|
| 90 | depthMap = depthMap_base; |
---|
| 91 | elseif baseline ==2 |
---|
| 92 | DepthFolder = [ LearnType '_' LearnAlg ... |
---|
| 93 | '_Nonsky' num2str(LearnSkyEx) '_Log' num2str(LearnLog) ... |
---|
| 94 | '_Near' num2str(LearnNear) '_baseline2']; |
---|
| 95 | load([ScratchDataFolder '/' DepthFolder '/' depthfile '.mat']); |
---|
| 96 | depthMap = depthMap_base2; |
---|
| 97 | else |
---|
| 98 | DepthFolder = [ LearnType '_' LearnAlg ... |
---|
| 99 | '_Nonsky' num2str(LearnSkyEx) '_Log' num2str(LearnLog) ... |
---|
| 100 | '_Near' num2str(LearnNear)]; |
---|
| 101 | load([ScratchDataFolder '/' DepthFolder '/' depthfile '.mat']); |
---|
| 102 | end |
---|
| 103 | LearnedDepth = depthMap; clear depthMap; |
---|
| 104 | if ~learned |
---|
| 105 | depthfile = strrep(filename{i},'img','depth_sph_corr'); % the depth filename |
---|
| 106 | load([ScratchDataFolder '/Gridlaserdata/' depthfile '.mat']); |
---|
| 107 | LaserDepth = Position3DGrid(:,:,4); |
---|
| 108 | clear Position3DGrid; |
---|
| 109 | end |
---|
| 110 | |
---|
| 111 | % load Var |
---|
| 112 | Varfile = strrep(filename{i},'img','Var_learned'); % the depth filename |
---|
| 113 | load([ScratchDataFolder '/Var_' LearnType '_' LearnAlg '_Nonsky' num2str(LearnSkyEx) '_Log' num2str(LearnLog) ... |
---|
| 114 | '_Near' num2str(LearnNear) '/' Varfile '.mat']); |
---|
| 115 | % Posi3D = Ray.*repmat(permute(LaserDepth,[3 1 2]),[3 1]); |
---|
| 116 | |
---|
| 117 | % initalize the ray |
---|
| 118 | RayPorjectImgMapY = repmat((1:SegVertYSize)',[1 SegHoriXSize]); |
---|
| 119 | RayPorjectImgMapX = repmat((1:SegHoriXSize),[SegVertYSize 1]); |
---|
| 120 | RayPorjectImgMapY = ((SegVertYSize+1-RayPorjectImgMapY)-0.5)/SegVertYSize - Oy; |
---|
| 121 | RayPorjectImgMapX = (RayPorjectImgMapX-0.5)/SegHoriXSize - Ox; |
---|
| 122 | MedRay = RayImPosition(RayPorjectImgMapY,RayPorjectImgMapX,a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3] |
---|
| 123 | MedRay = permute(MedRay,[3 1 2]); |
---|
| 124 | |
---|
| 125 | RayPorjectImgMapY = repmat((1:VertYNuDepth)',[1 HoriXNuDepth]); |
---|
| 126 | RayPorjectImgMapX = repmat((1:HoriXNuDepth),[VertYNuDepth 1]); |
---|
| 127 | RayProjImgCo = cat(3, RayPorjectImgMapX, RayPorjectImgMapY); |
---|
| 128 | RayProjImgCo = permute(RayProjImgCo,[3 1 2]); |
---|
| 129 | RayProjImgCo = Matrix2ImgCo(HoriXNuDepth, VertYNuDepth, RayProjImgCo(:,:)'); |
---|
| 130 | RayProjImgCo = ImgCo2Matrix(SegHoriXSize, SegVertYSize, RayProjImgCo); |
---|
| 131 | RayProjImgCo = reshape(RayProjImgCo', 2, VertYNuDepth, []); |
---|
| 132 | RayPorjectImgMapY = ((VertYNuDepth+1-RayPorjectImgMapY)-0.5)/VertYNuDepth - Oy; |
---|
| 133 | RayPorjectImgMapX = (RayPorjectImgMapX-0.5)/HoriXNuDepth - Ox; |
---|
| 134 | RayOri = RayImPosition(RayPorjectImgMapY,RayPorjectImgMapX,a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3] |
---|
| 135 | RayOri = permute(RayOri,[3 1 2]); |
---|
| 136 | |
---|
| 137 | % edge detection on the boundary of MedSup |
---|
| 138 | boundary = conv2(MedSup,[1 -1],'same')~=0 | conv2(MedSup,[1; -1],'same')~=0; |
---|
| 139 | boundary([1 2 end-1 end],:) = 0; |
---|
| 140 | boundary(:,[1 2 end-1 end]) = 0; |
---|
| 141 | % [seglist]=edgeSegDetection(boundary,i,1); |
---|
| 142 | Img = imread([GeneralDataFolder '/' ImgFolder '/' filename{i} '.jpg'],'jpg'); |
---|
| 143 | Img = imresize(Img, [ SegVertYSize SegHoriXSize]); |
---|
| 144 | [seglist]=edgeSegDetection(Img,i,0); |
---|
| 145 | DisplaySup(MedSup,300); |
---|
| 146 | hold on; drawseg(seglist,300); |
---|
| 147 | % saveas(300,[ScratchDataFolder '/data/segImg.jpg'],'jpg'); |
---|
| 148 | HBrokeBook = zeros(VertYNuDepth, HoriXNuDepth); |
---|
| 149 | VBrokeBook = zeros(VertYNuDepth, HoriXNuDepth); |
---|
| 150 | MovedPatchBook = []; |
---|
| 151 | % [Sup, MedSup, RayProjImgCo, MovedPatchBook, HBrokeBook, VBrokeBook, StraightLineTable, OccluList] = GenStraightLineFlexibleStick(... |
---|
| 152 | % seglist,MedSup,Sup, RayProjImgCo, LearnedDepth, [], [], [], Ox, Oy, a , b); |
---|
| 153 | if STNeeded |
---|
| 154 | [Sup, MedSup, RayProjImgCo, MovedPatchBook, HBrokeBook, VBrokeBook, StraightLineTable, OccluList] = GenStraightLineFlexibleStickMedSup(... |
---|
| 155 | seglist,MedSup,Sup, RayProjImgCo, LearnedDepth, [], HBrokeBook, VBrokeBook, Ox, Oy, a , b); |
---|
| 156 | save([ScratchDataFolder '/data/RayProjImgCo/RayProjImgCo' num2str(i) '.mat'],'RayProjImgCo','seglist','Img','Sup','MedSup','boundary'); |
---|
| 157 | HBrokeBook(:,end) = []; |
---|
| 158 | VBrokeBook(end,:) = []; |
---|
| 159 | RayPorjectImgMapY = ((SegVertYSize+1-permute(RayProjImgCo(2,:,:),[2 3 1]))-0.5)/SegVertYSize - Oy; |
---|
| 160 | RayPorjectImgMapX = (permute(RayProjImgCo(1,:,:),[2 3 1])-0.5)/SegHoriXSize - Ox; |
---|
| 161 | Ray = RayImPosition(RayPorjectImgMapY,RayPorjectImgMapX,a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3] |
---|
| 162 | Ray = permute(Ray,[3 1 2]); |
---|
| 163 | else |
---|
| 164 | HBrokeBook(:,end) = []; |
---|
| 165 | VBrokeBook(end,:) = []; |
---|
| 166 | OccluList = []; |
---|
| 167 | StraightLineTable =[]; |
---|
| 168 | Ray = RayOri; |
---|
| 169 | end |
---|
| 170 | %return; |
---|
| 171 | % Multiple segmentation |
---|
| 172 | if MultiScaleSup ==1 |
---|
| 173 | load([ScratchDataFolder '/data/DiffLowResImgIndexSuperpixelSep.mat']); |
---|
| 174 | load([ScratchDataFolder '/data/TextLowResImgIndexSuperpixelSepi' num2str(BatchNu) '.mat']); |
---|
| 175 | DiffSup = DiffLowResImgIndexSuperpixelSep(PicsInd(i),end); clear DiffLowResImgIndexSuperpixelSep; |
---|
| 176 | TextSup = TextLowResImgIndexSuperpixelSep(PicsInd(i),:,2:end); clear TextLowResImgIndexSuperpixelSep; |
---|
| 177 | |
---|
| 178 | [MultiScaleSupTable] = MultiScalAnalyze( Sup, permute( cat( 3, DiffSup{1,1},... |
---|
| 179 | TextSup{1,1,1}, TextSup{1,1,2},... |
---|
| 180 | TextSup{1,2,1}, TextSup{1,2,2},... |
---|
| 181 | TextSup{1,3,1}, TextSup{1,3,2},... |
---|
| 182 | TextSup{1,4,1}, TextSup{1,4,2},... |
---|
| 183 | TextSup{1,5,1}, TextSup{1,5,2},... |
---|
| 184 | TextSup{1,6,1}, TextSup{1,6,2}),... |
---|
| 185 | [3 1 2])); |
---|
| 186 | else |
---|
| 187 | MultiScaleSupTable = []; |
---|
| 188 | end |
---|
| 189 | |
---|
| 190 | % load([ScratchDataFolder '/data/temp/List' num2str(i) '.mat']); |
---|
| 191 | if learned |
---|
| 192 | % OccluList = [ 17 18;17 37; 17 97; 17 67; 17 93; 17 266]; |
---|
| 193 | % FitPlaneLearnDepthCoPlane(Sup,MedSup,LearnedDepth, RayOri, Ray, MedRay,... |
---|
| 194 | % FitPlaneLearnDepthCoPlaneWOPreFit(Sup,MedSup,LearnedDepth, RayOri, Ray, MedRay,... |
---|
| 195 | ReportPlaneParaMRFNoSedumi(step, DepthFolder, Sup,MedSup,LearnedDepth, VarMap, RayOri, Ray, MedRay,... |
---|
| 196 | maskSky{PicsInd(i)},maskg{PicsInd(i)},'cvx_allL1Norm',i,... |
---|
| 197 | [], OccluList, MultiScaleSupTable, StraightLineTable, HBrokeBook, VBrokeBook,previoslyStored, baseline); |
---|
| 198 | %ReportPlaneParaMRF(step, DepthFolder, Sup,MedSup,LearnedDepth, VarMap, RayOri, Ray, MedRay,... |
---|
| 199 | % maskSky{PicsInd(i)},maskg{PicsInd(i)},'cvx_allL1Norm',i,... |
---|
| 200 | % [], OccluList, MultiScaleSupTable, StraightLineTable, HBrokeBook, VBrokeBook,previoslyStored, baseline); |
---|
| 201 | else |
---|
| 202 | FitPlaneLaserData_CoPlane(Sup,MedSup,LaserDepth,Ray, MedRay, maskSky{PicsInd(i)},maskg{PicsInd(i)},'cvx_allL1Norm',i,CornerList, CornerList ,previoslyStored); |
---|
| 203 | end |
---|
| 204 | end |
---|