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

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

Added original make3d

File size: 6.3 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 [MedSup, Sup, Default SupNeighborTableFlag]=gen_Sup_efficient(Default, img, SelectSegmentationPara);
40% this function generate superpixel using default parameter
41% but can also change to manually input parameter
42
43%%% Jeff's Comments (Min modified)
44% Send that image to the CMU
45% segmentation program with params 0.8*[sigm, k, min].  If
46% SelectSegmenationPara is true, then display the results and ask
47% the user to enter new sigm, k, and min; repeat until user is happy.
48%
49% Output the MedSup(only the smallest scale) and Sup(three scale)
50%%%%
51
52% default parameter
53if nargin < 3
54    SelectSegmentationPara = 0; % if SelectSegmentationPara == 1, enable the parameter interation with user.
55end
56DisplayFlag = Default.Flag.DisplayFlag; % set to display or not
57
58scale =[0.8 1.6 5]; % use different scale to generate small(0.8) middle(1.6) 5(large) scale of superpixel
59
60    [VertYSizeHiREs HoriXSizeHiREs dummy]= size(img);% find the dimension size of the Hi Resolution image
61    clear dummy;
62
63    % using a fixed range of median size image [SegVertYSize SegHoriXSize ]
64    %  to generate superpixel to reduce computation
65    if VertYSizeHiREs*HoriXSizeHiREs > Default.SegVertYSize*Default.SegHoriXSize
66
67       % Downsample high resolution image to a fixed median size image
68       %**** +4 because segmentImgOpt gives constant additinal rows and column
69       %**** so add 4 rows and columns a prior then delete then at line 55
70       img = imresize(img,[Default.SegVertYSize+4 Default.SegHoriXSize+4 ],'nearest');
71    else
72       Default.SegVertYSize = VertYSizeHiREs-4;
73       Default.SegHoriXSize = HoriXSizeHiREs-4;
74    end
75
76% generate superpixel of each image
77for j = 1:3% number of scale of superpixel
78           
79    % choose superpixel of the images
80    % default segmentation parameter
81    ok = 0; % ok ==1 means accept the segmentation
82    while 1
83
84        % call the efficient segment function writen in C++ from MIT
85        % Output the high resolution image ( + 1 since the smallest index can be zero)
86        if j ==1
87           a = segmentImgOpt( Default.sigm*scale(j), Default.k*scale(j), Default.minp*scale(j), img,...
88                            [ Default.OutPutFolder Default.filename{1} '.ppm'],Default.PpmOption) + 1;
89        else
90           a = segmentImgOpt( Default.sigm*scale(j), Default.k*scale(j), Default.minp*scale(j), img,...
91                            [ Default.OutPutFolder Default.filename{1} '.ppm'], 0) + 1;
92        end
93        a = a(3:(end-2),3:(end-2)); %*** clean the edge superpixel index errors ***
94       
95        % Arrange the superpixel index in order
96        if j == 1 % For the smallest Scale           
97
98           ma = max(a(:));
99           Unique_a = unique(a);
100           SparseIndex = sparse(ma,1);
101           SparseIndex(Unique_a) = 1:size(Unique_a);
102           MedSup = full(SparseIndex(a));
103
104           %Downsample to size as prediected depth map
105           Sup{j} = imresize(MedSup,[Default.VertYNuDepth Default.HoriXNuDepth],'nearest');
106           % clean superpixel section ====================================================================
107           % merage all small and disconneted points in 1st scale segmentation
108           [Sup{j} SupNeighborTableFlag] = premergAllsuperpixel_efficient(Sup{j}, Default);
109           % ==============================================================
110           % ===============================
111
112        else  % o/w don't need the MedSup
113
114           %Downsample to size size as prediected depth map
115           a = imresize(a,[Default.VertYNuDepth Default.HoriXNuDepth],'nearest');
116           ma = max(a(:));
117           Unique_a = unique(a);
118           SparseIndex = sparse(ma,1);
119           SparseIndex(Unique_a) = 1:size(Unique_a);
120           Sup{j} = full(SparseIndex(a));
121        end
122        clear a SparseIndex Unique_a ma;
123
124
125        % show superpixel
126        if DisplayFlag
127           figure(1);
128           imagesc(Sup{j});
129           newmap = rand(max(max(Sup{j})),3);
130           colormap(newmap);
131        end
132
133        % check if need to select segmentation parameter
134        if SelectSegmentationPara==1;
135           ok = input('Is the segmentation of image OK');% input new segmentation parameter
136        else   
137           ok =1 ;% accept default segmentation parameter
138        end
139   
140        if ok==1;
141           break;
142        end
143
144        % Get the user selected parameter       
145        sigm = input('type sigm of segmentation');
146        k = input('type k of segmentation');
147        minp = input('type min of segmentation');
148           
149    end % end of while 1
150       
151end % end of for j=1:3   
152
153return;
Note: See TracBrowser for help on using the repository browser.