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