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 [Sup,MedSup, status]=CleanedSup(Sup,MedSup,maskSky) |
---|
40 | |
---|
41 | displayFlag = false; |
---|
42 | status = 0; |
---|
43 | |
---|
44 | % This function clean the sup up to certain cretiria |
---|
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 PopUpVertY PopUpHoriX taskName; |
---|
48 | |
---|
49 | % 0)get ride of all the nonconnedted superpixel in MedSup |
---|
50 | NuMedSup = unique(MedSup)'; |
---|
51 | SE = strel('disk',3); |
---|
52 | for 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 |
---|
66 | end |
---|
67 | |
---|
68 | % 1) Make the MedSup have the same index as Sup |
---|
69 | NuSup = unique(Sup)'; |
---|
70 | NuMedSup = unique(MedSup)'; |
---|
71 | NuResidualSup = setdiff(NuMedSup,NuSup); |
---|
72 | if ~isempty(NuResidualSup) |
---|
73 | [Sup, MedSup]=Medi2SupIndex(Sup,MedSup); |
---|
74 | end |
---|
75 | %check |
---|
76 | NuSup = unique(Sup)'; |
---|
77 | NuMedSup = unique(MedSup)'; |
---|
78 | NuResidualSup = setdiff(NuMedSup,NuSup); |
---|
79 | if ~isempty(NuResidualSup) |
---|
80 | disp('error in CleanSup'); |
---|
81 | end |
---|
82 | |
---|
83 | % get rid of the Sky for both Sup and MedSup |
---|
84 | SkyCandidate = unique(Sup(maskSky)); |
---|
85 | % check connecting for SkyResidual |
---|
86 | % Do we need to deal with these residual?????? |
---|
87 | for 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 |
---|
94 | end |
---|
95 | maskSky = Sup == 0; |
---|
96 | |
---|
97 | if displayFlag, |
---|
98 | DisplaySup(Sup, 2000); |
---|
99 | end |
---|
100 | |
---|
101 | % extend the sky to merger small sup near sky |
---|
102 | ThreSmall = 10; |
---|
103 | SE = strel('disk',5); |
---|
104 | maskSky_dilate = imdilate(maskSky,SE); |
---|
105 | SmallSupNearSky = setdiff(Sup(maskSky_dilate),0); |
---|
106 | if ~isempty(SmallSupNearSky) |
---|
107 | for 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 |
---|
125 | end |
---|
126 | end |
---|
127 | |
---|
128 | if displayFlag, |
---|
129 | figure(250), imagesc(Sup), |
---|
130 | newmap = [rand(max(Sup(:)),3); [0 0 0]]; |
---|
131 | colormap(newmap); |
---|
132 | %DisplaySup(Sup, 3500); |
---|
133 | end |
---|
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 |
---|
138 | NuSup = setdiff(unique(Sup)',0); |
---|
139 | for 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 |
---|
152 | end |
---|
153 | |
---|
154 | %Final check |
---|
155 | NuSup = unique(Sup)'; |
---|
156 | NuMedSup = unique(MedSup)'; |
---|
157 | NuResidualSup = setdiff(NuMedSup,NuSup); |
---|
158 | if ~isempty(NuResidualSup) |
---|
159 | disp('error in CleanSup'); |
---|
160 | % status = 1; |
---|
161 | end |
---|
162 | |
---|