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

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

Added original make3d

File size: 6.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 [TextSup]=gen_TextSup_efficient_GlobalH2( Default, SelectSegmentationPara);
40% process H's superpixels into Hi and Medi Resolution
41% this function generate superpixel using default parameter
42% but can also change to manually input parameter
43
44% set to global for gen_TextSup_efficient_GlobalH2 only
45global H2;
46
47% default parameter
48if nargin < 3
49    SelectSegmentationPara = 0;
50end
51DisplayFlag = Default.Flag.DisplayFlag; % set to display or not
52
53scale_sigm =[ 1 1.6];
54scale_k = [ 1.6 3];
55scale_minV = [ 1 3];
56
57%==================== choose 6 different feature channels
58 Pick= [1 10 11;
59        1 2 5;
60        1 3 7;
61        10 14 17;
62        12 15 13;
63        10 10 11];
64 NuPick = size(Pick,1);
65 reduce = 1; %100 percentage (used to reduce the size to process superpixel)
66% ================================
67
68% find the dimension size of the Hi Resolution H
69[VertYSizeHiREs HoriXSizeHiREs dummy]= size(H2);
70clear dummy;
71       
72% using a median size image to generate superpixel to reduce computation
73% intensity (the median size has a upper threshould SegVertYSize SegHoriXSize)
74if VertYSizeHiREs*HoriXSizeHiREs > Default.SegVertYSize*Default.SegHoriXSize
75
76   % Downsample high resolution image to a median size image
77   H2 = imresize(H2,([Default.SegVertYSize Default.SegHoriXSize ]*reduce+4),'nearest'); % +4 because edge error
78end
79[VertYImg HoriXImg dummy]= size(H2);
80clear dummy;
81
82%========================================
83temp = max(H2,[],1);
84temp = max(temp,[],2);
85H2 = H2./repmat(temp,[VertYImg HoriXImg 1]);
86%=======================================
87   
88% Process 6 different feature channel superpixel each with large and median scale
89for m=1:NuPick
90
91    img=H2(:,:,Pick(m,:));   
92   
93    if DisplayFlag
94        figure(1); image(img);
95    end
96
97    %=================================   
98    % choose superpixel of the images
99    % default segmentation parameter
100    for j = 1:2% number of scale of superpixel
101       
102        ok = 0; % ok ==1 means accept the segmentation
103        while 1
104        % call the efficient segment function writen in C++ from MIT
105        % Output the high resolution image ( + 1 since the smallest index can be zero)
106        a = segmentImgOpt( Default.sigm*scale_sigm(j), Default.k*scale_k(j), Default.minp*scale_minV(j), uint8(img*255), ...
107                           [ Default.OutPutFolder Default.filename{1} '.ppm'], 0) + 1;
108        a = a(2:(end-2),2:(end-2)); % clean the edge superpixel index errors
109
110        % Arrange the superpixel index in order
111        %Downsample to size size as prediected depth map
112        a = imresize(a,[Default.VertYNuDepth Default.HoriXNuDepth],'nearest');
113        ma = max(a(:));
114        Unique_a = unique(a);
115        SparseIndex = sparse(ma,1);
116        SparseIndex(Unique_a) = 1:size(Unique_a);
117        TextSup{m,j} = full(SparseIndex(a));
118        clear a SparseIndex Unique_a ma;
119
120        % clean superpixel section ====================================================================
121        % merage all small point in higher scale segmentation
122%         if j ~= 1
123%            TextSup{m,j} = premergAllsuperpixel(TextSup{m,j});
124%         end
125        % =============================================================================================
126
127        % show superpixel
128        if DisplayFlag
129           figure(1);
130           imagesc(TextSup{m,j});
131           newmap = rand(max(max(TextSup{m,j})),3);
132           colormap(newmap);
133        end
134
135        % check if need to select segmentation parameter
136        if SelectSegmentationPara==1;
137           ok = input('Is the segmentation of image OK');% input new segmentation parameter
138        else
139           ok =1 ;% accept default segmentation parameter
140        end
141
142        if ok==1;
143           break;
144        end
145
146        % Get the user selected parameter
147        sigm = input('type sigm of segmentation');
148        k = input('type k of segmentation');
149        minp = input('type min of segmentation');
150
151        end % end of while 1   
152    end % end of j = 1:2 (large and median scale)
153end % end of m=1:NuPick (NuPick different feature channel)   
154
155H2 = H2.*repmat(temp,[VertYImg HoriXImg 1]);
156% save([ScratchDataFolder '/data/TextLowResImgIndexSuperpixelSepi' num2str(BatchNu) '.mat'], 'TextLowResImgIndexSuperpixelSep');
157return;
Note: See TracBrowser for help on using the repository browser.