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