source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/Features/OldBatchVersion/CleanedSup.m @ 37

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

Added original make3d

File size: 5.0 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 [Sup,MedSup, status]=CleanedSup(Sup,MedSup,maskSky)
40
41displayFlag = false;
42status = 0;
43
44% This function clean the sup up to certain cretiria
45global 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 PopUpVertY PopUpHoriX taskName;
48
49% 0)get ride of all the nonconnedted superpixel in MedSup
50NuMedSup = unique(MedSup)';
51SE = strel('disk',3);
52for i = NuMedSup
53    mask = MedSup ==i;
54    [L,num] = bwlabel(mask,8);
55    n = histc(L(:),1:num);
56    [V maxL] = max(n);
57    for j = setdiff(1:num,maxL)
58        mask_dilate = imdilate(L == j,SE);
59        mask_dilate(mask) = 0;
60        if all(mask_dilate(:) == 0)
61           %j
62           disp('error using Mode empty')
63        end
64        MedSup(L ==j) = mode(double(MedSup(mask_dilate)));
65    end
66end
67
68% 1) Make the MedSup have the same index as Sup
69NuSup = unique(Sup)';
70NuMedSup = unique(MedSup)';
71NuResidualSup = setdiff(NuMedSup,NuSup);
72if ~isempty(NuResidualSup)
73    [Sup, MedSup]=Medi2SupIndex(Sup,MedSup);
74end
75%check
76NuSup = unique(Sup)';
77NuMedSup = unique(MedSup)';
78NuResidualSup = setdiff(NuMedSup,NuSup);
79if ~isempty(NuResidualSup)
80   disp('error in CleanSup');
81end
82
83% get rid of the Sky for both Sup and MedSup
84SkyCandidate = unique(Sup(maskSky));
85% check connecting for SkyResidual
86% Do we need to deal with these residual??????
87for i = SkyCandidate'
88    mask = Sup == i;
89    if sum(mask(maskSky))/sum(mask(:))>0.5
90       Medmask = MedSup == i;
91       Sup(mask) = 0;
92       MedSup(Medmask) = 0;
93    end
94end
95maskSky = Sup == 0;
96
97if displayFlag,
98DisplaySup(Sup, 2000);
99end
100
101% extend the sky to merger small sup near sky
102ThreSmall = 10;
103SE = strel('disk',5);
104maskSky_dilate = imdilate(maskSky,SE);
105SmallSupNearSky = setdiff(Sup(maskSky_dilate),0);
106if ~isempty(SmallSupNearSky)
107for i = SmallSupNearSky'
108    mask = Sup ==i;
109    if sum(mask(:)) < ThreSmall
110       Medmask = MedSup == i;
111       % naive merge
112       SE = strel('disk',3);
113       mask_dilate = imdilate(mask,SE);
114       mask_dilate(mask) = 0;
115       mask_dilate(maskSky) = 0;
116       target = mode(Sup(mask_dilate));
117       if isnan(target)
118          Sup(mask) = 0;
119          MedSup(Medmask) = 0;
120       else
121          Sup(mask) = target;
122          MedSup(Medmask) = target;
123       end
124    end
125end
126end
127
128if displayFlag,
129figure(250), imagesc(Sup),
130newmap = [rand(max(Sup(:)),3); [0 0 0]];
131colormap(newmap);
132%DisplaySup(Sup, 3500);
133end
134
135% 1) clearn the Sup first (default mask close)
136%    with option to merge under other condition
137%    use just a greedy closing algorithm
138NuSup = setdiff(unique(Sup)',0);
139for i = NuSup
140    Medmask = MedSup == i;
141    se = strel('diamond',10*3);
142    CloseMask = imclose(Medmask,se);
143    ClosedCandidate = setdiff(unique(MedSup(CloseMask)),i);
144    if ~isempty(ClosedCandidate)
145    for j = ClosedCandidate'
146        if all(CloseMask(MedSup == j))
147           Sup( Sup == j) = i;
148           MedSup( MedSup == j) = i;
149        end
150    end
151    end
152end
153
154%Final check
155NuSup = unique(Sup)';
156NuMedSup = unique(MedSup)';
157NuResidualSup = setdiff(NuMedSup,NuSup);
158if ~isempty(NuResidualSup)
159   disp('error in CleanSup');
160%   status = 1;
161end
162
Note: See TracBrowser for help on using the repository browser.