[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 []=gen_DiffSup(sigm,k,min,SelectSegmentationPara); |
---|
| 40 | % this function generate superpixel using default parameter |
---|
| 41 | % but can also change to manually input parameter |
---|
| 42 | |
---|
| 43 | % This file generates multiple segmentation (one of them using RGB) |
---|
| 44 | |
---|
| 45 | %%% |
---|
| 46 | % looks like gen_Sup_new but with different scaling params. |
---|
| 47 | % should we delete this file? |
---|
| 48 | %%% |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | % default parameter |
---|
| 52 | if nargin < 4 |
---|
| 53 | SelectSegmentationPara = 0; |
---|
| 54 | end |
---|
| 55 | |
---|
| 56 | % declaim global variable |
---|
| 57 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory... |
---|
| 58 | ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default... |
---|
| 59 | Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize; |
---|
| 60 | |
---|
| 61 | scale_sigm =[1 1.6]; |
---|
| 62 | scale_k = [1.6 5]; |
---|
| 63 | scale_min = [1 5]; |
---|
| 64 | |
---|
| 65 | % generate superpixel of each image |
---|
| 66 | |
---|
| 67 | NuPics = size(filename,2); |
---|
| 68 | for i = 1:NuPics |
---|
| 69 | i |
---|
| 70 | % load([ScratchDataFolder '/data/LowResImgIndexSuperpixelSep.mat']); |
---|
| 71 | |
---|
| 72 | % for j = 1:2%3% number of scale of superpixel |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | % sigm_new = |
---|
| 76 | % load image and process it to Hi Medi and Low Resolution |
---|
| 77 | Img = imread([GeneralDataFolder '/' ImgFolder '/' filename{i} '.jpg']); % Readin the high resolution image |
---|
| 78 | [VertYSizeHiREs HoriXSizeHiREs dummy]= size(Img);% find the dimension size of the Hi Resolution image |
---|
| 79 | clear dummy; |
---|
| 80 | % Loadin the GroundTruth data to know the depthMap size |
---|
| 81 | % depthfile = strrep(filename{i},'img','depth'); % the depth filename(without .file extension) associate with the *jpg file |
---|
| 82 | % load([GeneralDataFolder '/depthMap/' depthfile '.mat']); |
---|
| 83 | % [VertYSizeLowREs HoriXSizeLowREs]= size(depthMap);% find the dimension size of the depth data |
---|
| 84 | % in the new laser data we have scatter depthmap so use a |
---|
| 85 | % predecided LowRes |
---|
| 86 | VertYSizeLowREs = VertYNuDepth; |
---|
| 87 | HoriXSizeLowREs = HoriXNuDepth; |
---|
| 88 | |
---|
| 89 | % using a median size image to generate superpixel to reduce computation |
---|
| 90 | % intensity (the median size has a upper threshould SegVertYSize SegHoriXSize) |
---|
| 91 | if VertYSizeHiREs*HoriXSizeHiREs > SegVertYSize*SegHoriXSize |
---|
| 92 | Img = imresize(Img,[SegVertYSize SegHoriXSize ],'nearest'); % Downsample high resolution image to a median size image |
---|
| 93 | imwrite(Img,[ScratchDataFolder '/ppm/' filename{i} '_Diff.ppm'],'ppm');% store median Resolution image to PPM format to feed in CMU C++ function |
---|
| 94 | else |
---|
| 95 | imwrite(Img,[ScratchDataFolder '/ppm/' filename{i} '_Diff.ppm'],'ppm');% store median Resolution image to PPM format to feed in CMU C++ function |
---|
| 96 | end |
---|
| 97 | |
---|
| 98 | for j = 1:2%3% number of scale of superpixel |
---|
| 99 | % choose superpixel of the images |
---|
| 100 | % default segmentation parameter |
---|
| 101 | ok = 0; % ok ==1 means accept the segmentation |
---|
| 102 | while 1 |
---|
| 103 | % call segment function writen in C++ from MIT |
---|
| 104 | system([LocalFolder '/../third_party/Superpixels/segment ' num2str(sigm*scale_sigm(j)) ' ' num2str(k*scale_k(j)) ... |
---|
| 105 | ' ' num2str(min*scale_min(j)) ' ' ScratchDataFolder '/ppm/' filename{i} '_Diff.ppm' ' ' ... |
---|
| 106 | ScratchDataFolder '/ppm/' filename{i} '_' num2str(sigm*scale_sigm(j)) '_' ... |
---|
| 107 | num2str(k*scale_k(j)) '_' num2str(min*scale_min(j)) '.ppm']); |
---|
| 108 | MediResImgSuperpixel = imread([ScratchDataFolder '/ppm/' filename{i} '_' num2str(sigm*scale_sigm(j)) '_' num2str(k*scale_k(j)) '_' num2str(min*scale_min(j)) '.ppm']); % Readin the high resolution image |
---|
| 109 | figure(1); image(MediResImgSuperpixel); % show the superpixel in Medi Resolution |
---|
| 110 | |
---|
| 111 | % check if need to select segmentation parameter |
---|
| 112 | if SelectSegmentationPara==1; |
---|
| 113 | ok = input('Is the segmentation of image OK');% input new segmentation parameter |
---|
| 114 | else |
---|
| 115 | ok =1 ;% accept default segmentation parameter |
---|
| 116 | end |
---|
| 117 | |
---|
| 118 | % finish segmentation clean up the ppm folder. |
---|
| 119 | if ok==1; |
---|
| 120 | delete([ScratchDataFolder '/ppm/' filename{i} '_' num2str(sigm*scale_sigm(j)) '_' num2str(k*scale_k(j)) '_' num2str(min*scale_min(j)) '.ppm']); |
---|
| 121 | |
---|
| 122 | break; |
---|
| 123 | end |
---|
| 124 | sigm = input('type sigm of segmentation'); |
---|
| 125 | k = input('type k of segmentation'); |
---|
| 126 | min = input('type min of segmentation'); |
---|
| 127 | |
---|
| 128 | end |
---|
| 129 | |
---|
| 130 | % index superpixel |
---|
| 131 | [MediResImgIndexSuperpixelSepTemp dummy]= suprgb2ind(MediResImgSuperpixel); clear dummy; |
---|
| 132 | DiffLowResImgIndexSuperpixelSepTemp = imresize(MediResImgIndexSuperpixelSepTemp,[VertYSizeLowREs HoriXSizeLowREs],'nearest'); %Downsample high resolution image to the same pixel size of predict Depth data |
---|
| 133 | |
---|
| 134 | % merage the superpixel according to diff segmentation |
---|
| 135 | %NuSup = size(unique(LowResImgIndexSuperpixelSep),1); |
---|
| 136 | % LowSup = LowResImgIndexSuperpixelSep{i,1}; |
---|
| 137 | % Sup = zeros(size(LowSup)); |
---|
| 138 | % for l = (unique(LowSup))' |
---|
| 139 | % masksup = LowSup == l; |
---|
| 140 | % Index = analysesupinpatch(DiffLowResImgIndexSuperpixelSepTemp(masksup)); |
---|
| 141 | % Sup(masksup)= Index; |
---|
| 142 | % end |
---|
| 143 | % DiffLowResImgIndexSuperpixelSep{i,j} = Sup; |
---|
| 144 | % |
---|
| 145 | % merage all small point in higher scale segmentation |
---|
| 146 | if j == 1 |
---|
| 147 | DiffLowResImgIndexSuperpixelSep{i,j} = DiffLowResImgIndexSuperpixelSepTemp |
---|
| 148 | else |
---|
| 149 | DiffLowResImgIndexSuperpixelSep{i,j} = premergAllsuperpixel(DiffLowResImgIndexSuperpixelSepTemp); |
---|
| 150 | end |
---|
| 151 | %if j == 1; |
---|
| 152 | % MediResImgIndexSuperpixelSep{i} = MediResImgIndexSuperpixelSepTemp; |
---|
| 153 | %end |
---|
| 154 | % refining superpixel |
---|
| 155 | % superpixel segmentation LowResImgSeperatedSuperpixel |
---|
| 156 | %LowResImgsuperpixel = imresize(MediResImgSuperpixel,[VertYSizeLowREs HoriXSizeLowREs],'nearest'); %Downsample high resolution image to the same pixel size of GroundTruth data |
---|
| 157 | %[LowResImgIndexSuperpixel LowResImgIndexSuperpixel_list]= suprgb2ind(LowResImgsuperpixel); |
---|
| 158 | |
---|
| 159 | % comment: cmu's superpixel might be connected. use premergsuperpixel to |
---|
| 160 | % deal with nonconnected superpixels and very small superpixels |
---|
| 161 | %[LowResImgIndexSuperpixelSepTemp]=premergsuperpixel(LowResImgIndexSuperpixel); % hard work 1min |
---|
| 162 | |
---|
| 163 | % reorder the index number of the LowResImgIndexSuperpixelSep |
---|
| 164 | %[LowResImgIndexSuperpixelSep{i,j} LowResImgIndexSuperpixelSep_list]= ordersup(LowResImgIndexSuperpixelSepTemp); |
---|
| 165 | |
---|
| 166 | % show superpixel |
---|
| 167 | figure(2); |
---|
| 168 | imagesc(DiffLowResImgIndexSuperpixelSep{i,j}); |
---|
| 169 | newmap = rand(max(max(DiffLowResImgIndexSuperpixelSep{i,j})),3); |
---|
| 170 | colormap(newmap); |
---|
| 171 | |
---|
| 172 | % process the MediResImgSuperpixel to have the same number of |
---|
| 173 | % LowResImgIndexSuperpixelSep |
---|
| 174 | % if j==1 |
---|
| 175 | % tic |
---|
| 176 | % [MediResImgIndexSuperpixel dummy]= suprgb2ind(MediResImgSuperpixel); clear dummy; |
---|
| 177 | % MediResImgIndexSuperpixelSep = imresize(LowResImgIndexSuperpixelSep{i,1},size(MediResImgIndexSuperpixel),'nearest'); |
---|
| 178 | % NuSupMedi = max(max(MediResImgIndexSuperpixel)); |
---|
| 179 | % LowToMediResImgIndexSuperpixel = zeros(size(MediResImgIndexSuperpixel)); |
---|
| 180 | % for k = 1:NuSupMedi |
---|
| 181 | % mask = MediResImgIndexSuperpixel==k; |
---|
| 182 | % LowToMediResImgIndexSuperpixel(mask) = analysesupinpatch(MediResImgIndexSuperpixelSep(mask)); |
---|
| 183 | % % [list_sup] = analysesupinpatch(MediResImgIndexSuperpixelSep(mask)); |
---|
| 184 | % % [I C] = max(list_sup(2,:)); |
---|
| 185 | % % LowToMediResImgIndexSuperpixel(mask) = list_sup(1,C); |
---|
| 186 | % end |
---|
| 187 | % LowToMediResImgIndexSuperpixelSep{i} =... |
---|
| 188 | % premergAllsuperpixel(LowToMediResImgIndexSuperpixel); |
---|
| 189 | % toc |
---|
| 190 | % end |
---|
| 191 | end |
---|
| 192 | delete([ScratchDataFolder '/ppm/' filename{i} '_Diff.ppm']); |
---|
| 193 | save([ScratchDataFolder '/data/DiffLowResImgIndexSuperpixelSep.mat'], 'DiffLowResImgIndexSuperpixelSep'); |
---|
| 194 | end |
---|
| 195 | |
---|
| 196 | % save result for later application |
---|
| 197 | save([ScratchDataFolder '/data/DiffLowResImgIndexSuperpixelSep.mat'], 'DiffLowResImgIndexSuperpixelSep'); |
---|
| 198 | %save([ScratchDataFolder '/data/MediResImgIndexSuperpixelSep.mat'], 'MediResImgIndexSuperpixelSep'); |
---|
| 199 | |
---|
| 200 | return; |
---|