source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/Inference/OldVersion/RunCompleteMRF_try.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 12.4 KB
Line 
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% */
39function [] = RunCompleteMRF(BatchNu,LearnType,LearnSkyEx,LearnLog,LearnNear,...
40                   LearnAlg,baseline,step);
41
42% selected image with low error as train data set
43global 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
47if nargin < 8
48   step = [3];
49end
50%load([ScratchDataFolder '/../MinTest/data/MinTestFileName.mat']);
51%load([ScratchDataFolder '/../MinTest/data/MaskGSky.mat']);
52load([ScratchDataFolder '/data/MaskGSky.mat']);
53previoslyStored = false;
54MultiScaleSup = true;
55learned = true;
56%PicsInd = [10:16 18 54:62];
57PicsInd = 1:size(filename,2);
58%BatchSize = 5;
59BatchSize = 1;
60NuPics = size(filename,2);
61BatchRow = 1:BatchSize:NuPics;
62STNeeded = false
63%for i = 1:NuPics
64for 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        [GeneralDataFolder '/' ImgFolder '/' filename{i} '.jpg']
143        Img = imread([GeneralDataFolder '/' ImgFolder '/' filename{i} '.jpg'],'jpg');
144        Img = imresize(Img, [ SegVertYSize SegHoriXSize]);
145        [seglist]=edgeSegDetection(Img,i,0);
146        DisplaySup(MedSup,300);
147        hold on; drawseg(seglist,300);
148%        saveas(300,[ScratchDataFolder '/data/segImg.jpg'],'jpg');
149        HBrokeBook = zeros(VertYNuDepth, HoriXNuDepth);
150        VBrokeBook = zeros(VertYNuDepth, HoriXNuDepth);
151        MovedPatchBook = [];
152%        [Sup, MedSup, RayProjImgCo, MovedPatchBook, HBrokeBook, VBrokeBook, StraightLineTable, OccluList] = GenStraightLineFlexibleStick(...
153%              seglist,MedSup,Sup, RayProjImgCo, LearnedDepth, [], [], [], Ox, Oy, a , b);
154     if STNeeded
155        [Sup, MedSup, RayProjImgCo, MovedPatchBook, HBrokeBook, VBrokeBook, StraightLineTable, OccluList] = GenStraightLineFlexibleStickMedSup(...
156              seglist,MedSup,Sup, RayProjImgCo, LearnedDepth, [], HBrokeBook, VBrokeBook, Ox, Oy, a , b);
157     save([ScratchDataFolder '/data/RayProjImgCo/RayProjImgCo' num2str(i) '.mat'],'RayProjImgCo','seglist','Img','Sup','MedSup','boundary');
158        HBrokeBook(:,end) = [];
159        VBrokeBook(end,:) = [];
160        RayPorjectImgMapY = ((SegVertYSize+1-permute(RayProjImgCo(2,:,:),[2 3 1]))-0.5)/SegVertYSize - Oy;
161        RayPorjectImgMapX = (permute(RayProjImgCo(1,:,:),[2 3 1])-0.5)/SegHoriXSize - Ox;
162        Ray = RayImPosition(RayPorjectImgMapY,RayPorjectImgMapX,a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3]
163        Ray = permute(Ray,[3 1 2]);
164     else
165        HBrokeBook(:,end) = [];
166        VBrokeBook(end,:) = [];
167        OccluList = [];
168        StraightLineTable =[];
169        Ray = RayOri;
170     end
171
172%==================Special Ray Align ment =========================================================================================
173 % initalize the RayOri and Ray (this is after stitching)
174  SampleIndexYSmall = repmat((1:VertYNuDepth)',[1 HoriXNuDepth]);
175  SampleIndexXSmall = repmat((1:HoriXNuDepth),[VertYNuDepth 1]);
176  SampleImCoordYSmall = (( VertYNuDepth+1-SampleIndexYSmall)-0.5)/VertYNuDepth - Oy;
177  SampleImCoordXSmall = ( SampleIndexXSmall-0.5)/HoriXNuDepth - Ox;
178  RayOri = RayImPosition( SampleImCoordYSmall, SampleImCoordXSmall, a, b, Ox, Oy); %[ horiXSizeLowREs VertYSizeLowREs 3]
179  RayOri = permute(RayOri,[3 1 2]); %[ 3 horiXSizeLowREs VertYSizeLowREs]
180
181%   img = imread([GeneralDataFolder '/' ImgFolder '/' filename{i} '.jpg'],'jpg');
182%   img = imresize(img, [ SegVertYSize SegHoriXSize]);
183%   [seglist]=edgeSegDetection(img,i,0);
184%   DisplaySup(MedSup,300);
185%   hold on; drawseg(seglist,300);
186  seglist(:,1:2) = Matrix2ImgCo(SegHoriXSize, SegVertYSize, seglist(:,1:2));
187  seglist(:,3:4) = Matrix2ImgCo(SegHoriXSize, SegVertYSize, seglist(:,3:4));
188  seglist(:,1:2) = ImgCo2Matrix(HoriXNuDepth, VertYNuDepth, seglist(:,1:2));
189  seglist(:,3:4) = ImgCo2Matrix(HoriXNuDepth, VertYNuDepth, seglist(:,3:4));
190
191  VB = MedSup(:,round(linspace(1, SegHoriXSize, HoriXNuDepth)));
192  HB = MedSup(round(linspace(1, SegVertYSize, VertYNuDepth)),:);
193 
194      TextCoor = SupRayAlign( Sup, VB, HB, seglist, SampleIndexXSmall, SampleIndexYSmall, ones(55,305));
195      SampleImCoordYSmall = (( VertYNuDepth+1-TextCoor(:,:,2))-0.5)/VertYNuDepth - Oy;
196      SampleImCoordXSmall = ( TextCoor(:,:,1)-0.5)/HoriXNuDepth - Ox;
197      Ray = RayImPosition( SampleImCoordYSmall, SampleImCoordXSmall, a, b, Ox, Oy); %[ horiXSizeLowREs VertYSizeLowREs 3]
198      Ray = permute(Ray,[3 1 2]); %[ 3 horiXSizeLowREs VertYSizeLowREs]
199
200% =================================================================================================================================
201%return;
202        % Multiple segmentation
203     if MultiScaleSup ==1
204        load([ScratchDataFolder '/data/DiffLowResImgIndexSuperpixelSep.mat']);
205        load([ScratchDataFolder '/data/TextLowResImgIndexSuperpixelSepi' num2str(BatchNu) '.mat']);
206        DiffSup = DiffLowResImgIndexSuperpixelSep(PicsInd(i),end); clear DiffLowResImgIndexSuperpixelSep;
207        TextSup = TextLowResImgIndexSuperpixelSep(PicsInd(i),:,2:end); clear TextLowResImgIndexSuperpixelSep;
208
209        [MultiScaleSupTable] = MultiScalAnalyze( Sup, permute(  cat( 3, DiffSup{1,1},...
210                              TextSup{1,1,1}, TextSup{1,1,2},...
211                              TextSup{1,2,1}, TextSup{1,2,2},...
212                              TextSup{1,3,1}, TextSup{1,3,2},...
213                              TextSup{1,4,1}, TextSup{1,4,2},...
214                              TextSup{1,5,1}, TextSup{1,5,2},...
215                              TextSup{1,6,1}, TextSup{1,6,2}),...
216                              [3 1 2]));
217     else
218        MultiScaleSupTable = [];
219     end
220 
221%        load([ScratchDataFolder '/data/temp/List' num2str(i) '.mat']);
222        if learned
223%           OccluList = [ 17 18;17 37; 17 97; 17 67; 17 93; 17 266];
224%           FitPlaneLearnDepthCoPlane(Sup,MedSup,LearnedDepth, RayOri, Ray, MedRay,...
225%           FitPlaneLearnDepthCoPlaneWOPreFit(Sup,MedSup,LearnedDepth, RayOri, Ray, MedRay,...
226            Decomp;
227%           ReportPlaneParaMRF_Sedumi(step, DepthFolder, Sup,MedSup,LearnedDepth, VarMap, RayOri, Ray, MedRay,...
228%               maskSky{PicsInd(i)},maskg{PicsInd(i)},'cvx_allL1Norm',i,...
229%               [], OccluList, MultiScaleSupTable, StraightLineTable, HBrokeBook, VBrokeBook,previoslyStored, baseline);
230           %ReportPlaneParaMRF(step, DepthFolder, Sup,MedSup,LearnedDepth, VarMap, RayOri, Ray, MedRay,...
231           %    maskSky{PicsInd(i)},maskg{PicsInd(i)},'cvx_allL1Norm',i,...
232           %    [], OccluList, MultiScaleSupTable, StraightLineTable, HBrokeBook, VBrokeBook,previoslyStored, baseline);
233        else
234           FitPlaneLaserData_CoPlane(Sup,MedSup,LaserDepth,Ray, MedRay, maskSky{PicsInd(i)},maskg{PicsInd(i)},'cvx_allL1Norm',i,CornerList, CornerList ,previoslyStored);
235        end
236end
Note: See TracBrowser for help on using the repository browser.