[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 []=OcclusionMRF(k);
|
---|
| 40 |
|
---|
| 41 | % not working perfectly. More search needed.
|
---|
| 42 |
|
---|
| 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 | % This function run a boundary MRF using the laser data to estimate the occlusion boundary
|
---|
| 48 | tic
|
---|
| 49 | % set Parameters
|
---|
| 50 | WSLInitialWei = 0.5;
|
---|
| 51 | WCornerInitialWei = 0.3;
|
---|
| 52 | SLExcludeHoriWei = 5; % Hori have a bigger resolusion so have a bigger Exlude region
|
---|
| 53 | SLExcludeVertWei = 10;
|
---|
| 54 | BpWidthV = ceil(0.01*VertYNuDepth); % assume uniform distibution of the shift of estimated Bp with Width = BpWidthV (Precentage in Vert diection)
|
---|
| 55 | BpWidthH = ceil(0.1*HoriXNuDepth); % BpWidthH (Precentage in Vert diection)
|
---|
| 56 |
|
---|
| 57 | % prepare the data
|
---|
| 58 | %1) depth ready
|
---|
| 59 | depthfile = strrep(filename{k},'img','depth_sph_corr'); % the depth filename
|
---|
| 60 | load([ScratchDataFolder '/Gridlaserdata/' depthfile '.mat']);
|
---|
| 61 | LaserDepth = Position3DGrid(:,:,4);
|
---|
| 62 | % 2) ProjXY ready
|
---|
| 63 | PicsinfoName = strrep(filename{k},'img','picsinfo');
|
---|
| 64 | temp = dir([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']);
|
---|
| 65 | if size(temp,1) == 0
|
---|
| 66 | a = a_default;
|
---|
| 67 | b = b_default;
|
---|
| 68 | Ox = Ox_default;
|
---|
| 69 | Oy = Oy_default;
|
---|
| 70 | Horizon = Horizon_default;
|
---|
| 71 | else
|
---|
| 72 | load([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']);
|
---|
| 73 | end
|
---|
| 74 | RayProjY = repmat((1:VertYNuDepth)',[1 HoriXNuDepth]);
|
---|
| 75 | RayProjX = repmat((1:HoriXNuDepth),[VertYNuDepth 1]);
|
---|
| 76 | RayPorjectImgMapYImCo = ((VertYNuDepth+1-RayProjY)-0.5)/VertYNuDepth - Oy;
|
---|
| 77 | RayPorjectImgMapXImCo = (RayProjX-0.5)/HoriXNuDepth - Ox;
|
---|
| 78 | % 3) Ray ready
|
---|
| 79 | Ray = RayImPosition(RayPorjectImgMapYImCo,RayPorjectImgMapXImCo,a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3]
|
---|
| 80 | Ray = permute(Ray,[3 1 2]);
|
---|
| 81 |
|
---|
| 82 | % Vertex X Y position
|
---|
| 83 | VertexY = repmat((1:(VertYNuDepth+1))',[1 HoriXNuDepth+1]);
|
---|
| 84 | VertexX = repmat((1:(HoriXNuDepth+1)),[VertYNuDepth+1 1]);
|
---|
| 85 | % change them into image coordinate
|
---|
| 86 | Vertex = Matrix2ImgCo(HoriXNuDepth+1, VertYNuDepth+1, [VertexX(:) VertexY(:)]);
|
---|
| 87 | VertexY = reshape(Vertex(:,2), VertYNuDepth+1, []);
|
---|
| 88 | VertexX = reshape(Vertex(:,1), VertYNuDepth+1, []);
|
---|
| 89 |
|
---|
| 90 | % 4) Position 3D ready
|
---|
| 91 | %Posi3D = im_cr2w_cr(LaserDepth,permute(Ray,[2 3 1]));
|
---|
| 92 |
|
---|
| 93 | % 5) Sup Ready
|
---|
| 94 | load([ScratchDataFolder '/data/CleanSup/CleanSup' num2str(k) '.mat']);
|
---|
| 95 | load([ScratchDataFolder '/Gridlaserdata/' depthfile '.mat']);
|
---|
| 96 | LaserDepth = Position3DGrid(:,:,4);
|
---|
| 97 | [SegVertYSize, SegHoriXSize] = size(MedSup);
|
---|
| 98 | MedSup = double(MedSup);
|
---|
| 99 | Sup = double(Sup);
|
---|
| 100 | MaxSup = max( Sup(:));
|
---|
| 101 | MaskSky = Sup ==0;
|
---|
| 102 |
|
---|
| 103 | % 6) Img Ready
|
---|
| 104 | Img = imresize(imread([GeneralDataFolder '/' ImgFolder '/' filename{k} ],'jpg'), [SegVertYSize SegHoriXSize]);
|
---|
| 105 |
|
---|
| 106 | % 7) SupBounday with HashIndex Ready
|
---|
| 107 | BoundaryPVert = conv2(Sup,[MaxSup 1],'valid').*( conv2(Sup,[1 -1],'valid') >0)...
|
---|
| 108 | .* ~MaskSky(:,1:(end-1)) .* ~MaskSky(:,2:end); % two step build up hash index 1) Left > Righ index
|
---|
| 109 | BoundaryPVert = BoundaryPVert + conv2(Sup,[1 MaxSup],'valid').* (conv2(Sup,[-1 1],'valid') >0)...
|
---|
| 110 | .* ~MaskSky(:,1:(end-1)) .* ~MaskSky(:,2:end); % 2) Left < Righ index
|
---|
| 111 | BoundaryPHori = conv2(Sup,[MaxSup; 1],'valid').* (conv2(Sup,[1; -1],'valid') >0)...
|
---|
| 112 | .* ~MaskSky(1:(end-1),:) .* ~MaskSky(2:end,:); % two step build up hash index 1) Top > bottom index
|
---|
| 113 | BoundaryPHori = BoundaryPHori + conv2(Sup,[1; MaxSup],'valid').*( conv2(Sup,[-1; 1],'valid') >0)...
|
---|
| 114 | .* ~MaskSky(1:(end-1),:) .* ~MaskSky(2:end,:); % 2) Top < Bottom index
|
---|
| 115 | ClosestNHashList = setdiff(unique([BoundaryPHori(:); BoundaryPVert(:)]),0);
|
---|
| 116 | NuNei = size(ClosestNHashList,1);
|
---|
| 117 | MaxHash = max(ClosestNHashList(:));
|
---|
| 118 | Hash2Ind = sparse(1,MaxHash);
|
---|
| 119 | Hash2Ind(ClosestNHashList) = 1:NuNei;
|
---|
| 120 |
|
---|
| 121 | % 8) Straight Line detection in Multi Scale
|
---|
| 122 | [seglist]=edgeSegDetection(Img,k,0);
|
---|
| 123 |
|
---|
| 124 | figure(100); subplot(2,2,1);
|
---|
| 125 | ImgMapSup = Img;
|
---|
| 126 | ImgMapSup(:,:,1) = 255/max(Sup(:))*imresize(Sup, [ SegVertYSize SegHoriXSize]);
|
---|
| 127 | image(ImgMapSup);
|
---|
| 128 | drawseg(seglist,100);
|
---|
| 129 | PlotGridBoundary( (BoundaryPHori ~=0), (BoundaryPVert ~=0), VertexX, VertexY, [ SegVertYSize SegHoriXSize], 100, 'y');
|
---|
| 130 | % maping Straight line to BoundaryLineCross matrix
|
---|
| 131 | [BoundaryLineCrossHori BoundaryLineCrossVert] = ...
|
---|
| 132 | ST2BoundaryLineCross(seglist, BoundaryPHori, BoundaryPVert); % now seglist change to size of VertYNuDepth HoriXNuDepth
|
---|
| 133 | % same size of BoundaryPHori with
|
---|
| 134 |
|
---|
| 135 | % Show result of all possible Bunday and the Straighe line detected
|
---|
| 136 | figure(100); subplot(2,2,1);
|
---|
| 137 | %PlotGridBoundary( ones(size( BoundaryLineCrossHori)),ones(size(
|
---|
| 138 | %BoundaryLineCrossVert)), VertexX, VertexY, [ SegVertYSize SegHoriXSize],
|
---|
| 139 | %100,'y'); % plot all the boundary
|
---|
| 140 | PlotGridBoundary( BoundaryLineCrossHori, BoundaryLineCrossVert, VertexX, VertexY, [ SegVertYSize SegHoriXSize], 100, 'g');
|
---|
| 141 |
|
---|
| 142 | % Constructing W matrix
|
---|
| 143 | WL = sparse(NuNei,NuNei);
|
---|
| 144 | WI = sparse(NuNei,NuNei);
|
---|
| 145 | WIL = sparse(NuNei,NuNei);
|
---|
| 146 | % 1) inital preference
|
---|
| 147 | ii = 1:(size(BoundaryPVert,1)-1);
|
---|
| 148 | jj = 1:(size(BoundaryPVert,2));
|
---|
| 149 | mask = zeros(size(BoundaryPVert));
|
---|
| 150 | mask(ii,jj) = 1;
|
---|
| 151 | IndVert = find(mask);
|
---|
| 152 | mask = zeros(size(BoundaryPHori));
|
---|
| 153 | mask(ii,jj) = 1;
|
---|
| 154 | IndHori = find(mask);
|
---|
| 155 | ProximitySLHast = sort([[BoundaryPVert(IndVert) BoundaryPVert(IndVert+1)]; [BoundaryPHori(IndHori) BoundaryPHori(IndHori+size(BoundaryPHori,1))]],2);
|
---|
| 156 | ProximitySLHast( (ProximitySLHast(:,1) == 0 | ProximitySLHast(:,2) == 0),:) = [];
|
---|
| 157 | ProximityCornerHast = sort([[BoundaryPVert(IndVert) BoundaryPHori(IndHori)];...
|
---|
| 158 | [BoundaryPVert(IndVert) BoundaryPHori(IndHori+size(BoundaryPHori,1))];...
|
---|
| 159 | [BoundaryPVert(IndVert+1) BoundaryPHori(IndHori)];...
|
---|
| 160 | [BoundaryPVert(IndVert+1) BoundaryPHori(IndHori+size(BoundaryPHori,1))]],2);
|
---|
| 161 | ProximityCornerHast( (ProximityCornerHast(:,1) == 0 | ProximityCornerHast(:,2) == 0),:) = [];
|
---|
| 162 | IndProximitySLHast = sub2ind([NuNei NuNei],Hash2Ind(ProximitySLHast(:,1)),Hash2Ind(ProximitySLHast(:,2)));
|
---|
| 163 | IndProximityCornerHast = sub2ind([NuNei NuNei], Hash2Ind(ProximityCornerHast(:,1)), Hash2Ind(ProximityCornerHast(:,2)));
|
---|
| 164 | WI( IndProximitySLHast) = -WSLInitialWei;
|
---|
| 165 | WI( IndProximityCornerHast) = -WCornerInitialWei;
|
---|
| 166 | WIL( IndProximitySLHast) = -WSLInitialWei;
|
---|
| 167 | WIL( IndProximityCornerHast) = -WCornerInitialWei;
|
---|
| 168 |
|
---|
| 169 | % 2) Straight Line link preference
|
---|
| 170 | NuSL = size(seglist,1);
|
---|
| 171 | for l = 1:NuSL
|
---|
| 172 | IndLineCrossHori = find(BoundaryLineCrossHori == l);
|
---|
| 173 | IndLineCrossVert = find(BoundaryLineCrossVert == l);
|
---|
| 174 | % decide to shift hori or vert
|
---|
| 175 | if any(IndLineCrossVert == IndLineCrossVert+size(BoundaryLineCrossVert,1))
|
---|
| 176 | shiftHori = 1;
|
---|
| 177 | shiftVert = 1;
|
---|
| 178 | else
|
---|
| 179 | shiftHori = size(BoundaryPHori,1);
|
---|
| 180 | shiftVert = size(BoundaryPVert,1);
|
---|
| 181 | end
|
---|
| 182 | SLHashVert = BoundaryPVert(IndLineCrossVert);
|
---|
| 183 | SLHashVert( SLHashVert == 0) = [];
|
---|
| 184 | SLHashHori = BoundaryPHori(IndLineCrossHori);
|
---|
| 185 | SLHashHori( SLHashHori == 0) = [];
|
---|
| 186 | % too strong preference for constructing straight line
|
---|
| 187 | % across long dist
|
---|
| 188 | % [y x] = meshgrid([SLHashVert; SLHashHori],[SLHashVert;SLHashHori]);
|
---|
| 189 | % check = y == x;
|
---|
| 190 | % y( check) =[];
|
---|
| 191 | % x( check) =[];
|
---|
| 192 | % PairHash = unique(sort([y(:) x(:)],2),'rows');
|
---|
| 193 | SLHash = [SLHashVert; SLHashHori];
|
---|
| 194 | PairHash = unique(sort( [SLHash(1:(end-1)) SLHash(2:(end)) ], 2),'rows');
|
---|
| 195 | if isempty(PairHash)
|
---|
| 196 | continue;
|
---|
| 197 | end
|
---|
| 198 | PairHash( PairHash(:,1) == PairHash(:,2),:) = [];
|
---|
| 199 | if isempty(PairHash)
|
---|
| 200 | continue;
|
---|
| 201 | end
|
---|
| 202 | SLInd = sub2ind([NuNei NuNei], Hash2Ind(PairHash(:,1)), Hash2Ind(PairHash(:,2)));
|
---|
| 203 | WL( SLInd) = -1; % -1 if prefer same label
|
---|
| 204 | WIL( SLInd) = -1; % -1 if prefer same label
|
---|
| 205 | % ExludePairHash1 = [ [reshape(SLHashVert(:,ones(1,SLExcludeVertWei)),[],1); reshape(SLHashHori(:,ones(1,SLExcludeHoriWei)),[],1)] ...
|
---|
| 206 | % [BoundaryPVert( reshape( max( min( repmat(IndLineCrossVert,[1 SLExcludeVertWei]) + ...
|
---|
| 207 | % repmat(shiftVert*(1:SLExcludeVertWei),[size(IndLineCrossVert,1) 1]), prod(size(BoundaryPVert))), 1), [],1) ) ;...
|
---|
| 208 | % BoundaryPHori( reshape( max( min( repmat(IndLineCrossHori,[1 SLExcludeHoriWei]) + ...
|
---|
| 209 | % repmat(shiftHori*(1:SLExcludeHoriWei),[size(IndLineCrossHori,1) 1]), prod(size(BoundaryPHori))), 1), [],1) ) ]...
|
---|
| 210 | % ];
|
---|
| 211 | % ExludePairHash1( (ExludePairHash1(:,1) == 0 | ExludePairHash1(:,2) == 0),:) = [];
|
---|
| 212 | % ExludePairHash2 = [[reshape(SLHashVert(:,ones(1,SLExcludeVertWei)),[],1); reshape(SLHashHori(:,ones(1,SLExcludeHoriWei)),[],1)]...
|
---|
| 213 | % [BoundaryPVert( reshape( max( min( repmat(IndLineCrossVert,[1 SLExcludeVertWei]) + ...
|
---|
| 214 | % repmat(-shiftVert*(1:SLExcludeVertWei),[size(IndLineCrossVert,1) 1]), prod(size(BoundaryPVert))), 1), [],1) ) ;...
|
---|
| 215 | % BoundaryPHori( reshape( max( min( repmat(IndLineCrossHori,[1 SLExcludeHoriWei]) + ...
|
---|
| 216 | % repmat(-shiftHori*(1:SLExcludeHoriWei),[size(IndLineCrossHori,1) 1]), prod(size(BoundaryPHori))), 1), [],1) ) ]...
|
---|
| 217 | % ];
|
---|
| 218 | % ExludePairHash2( (ExludePairHash2(:,1) == 0 | ExludePairHash2(:,2) == 0),:) = [];
|
---|
| 219 | % ExludePairHash = unique(sort([ExludePairHash1; ExludePairHash2],2), 'rows');
|
---|
| 220 | % SLExludeInd = sub2ind([NuNei NuNei], Hash2Ind(ExludePairHash(:,1)), Hash2Ind(ExludePairHash(:,2)));
|
---|
| 221 | % DonNotExcludeInd = W(SLExludeInd) == 1;
|
---|
| 222 | % W( SLExludeInd(~DonNotExcludeInd)) = 1;
|
---|
| 223 | end
|
---|
| 224 |
|
---|
| 225 | % 3) line complete and corner complete preference
|
---|
| 226 | % still don't know
|
---|
| 227 |
|
---|
| 228 | % 4) parallel exlude
|
---|
| 229 | NewHash2Ind =Hash2Ind;
|
---|
| 230 | NewHash2Ind(end+1) = NuNei+1;
|
---|
| 231 | NewBoundaryPVert = BoundaryPVert;
|
---|
| 232 | NewBoundaryPVert( NewBoundaryPVert==0) = size(NewHash2Ind,2);
|
---|
| 233 | SV = spalloc((size(NewBoundaryPVert,2)-(SLExcludeVertWei-1))*size(NewBoundaryPVert,1),NuNei+1,...
|
---|
| 234 | (size(NewBoundaryPVert,2)-(SLExcludeVertWei-1))*size(NewBoundaryPVert,1)*SLExcludeVertWei);
|
---|
| 235 | InitialRow = 1;
|
---|
| 236 | for i = 1:SLExcludeVertWei
|
---|
| 237 | ResV = rem(size(BoundaryPVert,2)-i+1,SLExcludeVertWei);
|
---|
| 238 | XI = NewHash2Ind(reshape( NewBoundaryPVert(:,i:(end-ResV) )', SLExcludeVertWei, [] ));
|
---|
| 239 | NuRow = size(XI,2);
|
---|
| 240 | YI = repmat(InitialRow:(InitialRow+NuRow-1), [SLExcludeVertWei 1]);
|
---|
| 241 | InitialRow = InitialRow+NuRow;
|
---|
| 242 | SV(sub2ind(size(SV),YI(:),XI(:))) = 1;
|
---|
| 243 | end
|
---|
| 244 | SV(:,end) = [];
|
---|
| 245 | mask = sum(SV,2) ==0;
|
---|
| 246 | SV(mask,:) = [];
|
---|
| 247 |
|
---|
| 248 | NewBoundaryPHori = BoundaryPHori;
|
---|
| 249 | NewBoundaryPHori( NewBoundaryPHori==0) = size(NewHash2Ind,2);
|
---|
| 250 | SH = spalloc((size(NewBoundaryPHori,1)-(SLExcludeHoriWei-1))*size(NewBoundaryPHori,2),NuNei+1,...
|
---|
| 251 | (size(NewBoundaryPHori,1)-(SLExcludeHoriWei-1))*size(NewBoundaryPHori,2)*SLExcludeHoriWei);
|
---|
| 252 | InitialRow = 1;
|
---|
| 253 | for i = 1:SLExcludeHoriWei
|
---|
| 254 | ResH = rem(size(BoundaryPHori,1)-i+1,SLExcludeHoriWei);
|
---|
| 255 | XI = NewHash2Ind(reshape( NewBoundaryPHori(i:(end-ResH),: ), SLExcludeHoriWei, [] ));
|
---|
| 256 | NuRow = size(XI,2);
|
---|
| 257 | YI = repmat(InitialRow:(InitialRow+NuRow-1), [SLExcludeHoriWei 1]);
|
---|
| 258 | InitialRow = InitialRow+NuRow;
|
---|
| 259 | SH(sub2ind(size(SH),YI(:),XI(:))) = 1;
|
---|
| 260 | end
|
---|
| 261 | SH(:,end) = [];
|
---|
| 262 | mask = sum(SH,2) ==0;
|
---|
| 263 | SH(mask,:) = [];
|
---|
| 264 |
|
---|
| 265 | % make sure diagnal terms are 1
|
---|
| 266 | DiInd = sub2ind([NuNei NuNei],(1:NuNei)',(1:NuNei)');
|
---|
| 267 | WI = WI+WI'; % make symmetric
|
---|
| 268 | WL = WL+WL'; % make symmetric
|
---|
| 269 | WIL = WIL+WIL'; % make symmetric
|
---|
| 270 | WI(DiInd) = 1;
|
---|
| 271 | WL(DiInd) = 1;
|
---|
| 272 | WIL(DiInd) = 1;
|
---|
| 273 |
|
---|
| 274 | % maping Laser occlusion estimation to Bp matrix
|
---|
| 275 | [Bp, OccluMap, BoundaryLaserOccluHori, BoundaryLaserOccluVert] = LaserDetectOcc2Bp( LaserDepth, BpWidthV, BpWidthH, BoundaryPVert, BoundaryPHori, Hash2Ind);
|
---|
| 276 | %[BoundaryLaserOccluHori, BoundaryLaserOccluVert ] = BHash2BMap(Bp, BoundaryPHori, BoundaryPVert, ClosestNHashList); % output two binary mask
|
---|
| 277 |
|
---|
| 278 | % Show Laser occlusion detection labeled Boundary
|
---|
| 279 | figure(100); subplot(2,2,2);
|
---|
| 280 | ImgMapOcclu = Img;
|
---|
| 281 | ImgMapOcclu(:,:,1) = 255*imresize(OccluMap, [ SegVertYSize SegHoriXSize]);
|
---|
| 282 | image(ImgMapOcclu);
|
---|
| 283 | PlotGridBoundary( BoundaryLaserOccluHori, BoundaryLaserOccluVert, VertexX, VertexY, [ SegVertYSize SegHoriXSize], 100,'g');
|
---|
| 284 | save([ScratchDataFolder '/Temp/OccluMRF' num2str(k) '.mat']);
|
---|
| 285 |
|
---|
| 286 | % Run MRF
|
---|
| 287 | [U S V] = svds(WI);
|
---|
| 288 | Wsqrt = (S.^(0.5))*V';
|
---|
| 289 | opt = sdpsettings('solver','sedumi');
|
---|
| 290 | B = sdpvar(NuNei,1);
|
---|
| 291 | t = sdpvar(1,1);
|
---|
| 292 | %F = set( -1 < B < 1) + set(cone(Wsqrt*B,t));
|
---|
| 293 | F = set( -1 < B < 1) + set(cone(Wsqrt*B,t))+set(SV*B <= (-sum(SV,2)+2) )+set(SH*B <= (-sum(SH,2)+2) );
|
---|
| 294 | beta = 1; % trade off weight
|
---|
| 295 | sol = solvesdp(F,t*t - beta*Bp'*B ,opt);
|
---|
| 296 | B = double(B);
|
---|
| 297 | toc
|
---|
| 298 | % beta = 1;
|
---|
| 299 | % cvx_begin
|
---|
| 300 | % variable B(NuNei);
|
---|
| 301 | % minimize(B'*WI*B - beta*Bp'*B)
|
---|
| 302 | % abs(B) <= 1;
|
---|
| 303 | % SV*B <= (-sum(SV,2)+2);
|
---|
| 304 | % SH*B <= (-sum(SH,2)+2);
|
---|
| 305 | % cvx_end
|
---|
| 306 | [BoundaryMRFEstHori, BoundaryMRFEstVert ] = BHash2BMap(B, BoundaryPHori, BoundaryPVert, ClosestNHashList); % output two binary mask
|
---|
| 307 |
|
---|
| 308 | % Show Laser occlusion detection labeled Boundary
|
---|
| 309 | figure(100); subplot(2,2,3);
|
---|
| 310 | image(ImgMapOcclu);
|
---|
| 311 | PlotGridBoundary( BoundaryMRFEstHori, BoundaryMRFEstVert, VertexX, VertexY,[ SegVertYSize SegHoriXSize], 100,'y');
|
---|
| 312 | saveas(100,[ScratchDataFolder '/data/occlu/MRFoccl' num2str(k) '.jpg']);
|
---|
| 313 | close all;
|
---|