[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 [im]=premergsuperpixel(im) |
---|
| 40 | %(This is program conver a non_ordered non_connected superpixel image to |
---|
| 41 | % ordered superpixel image |
---|
| 42 | % input: |
---|
| 43 | % im = N by M matrix depends on the image size |
---|
| 44 | % Position3DTure =3 by Q matrix the 3 column entries are [x y z]' in 3d coordinate |
---|
| 45 | % output: |
---|
| 46 | % im_order = N by M matrix which is ordered |
---|
| 47 | |
---|
| 48 | %%% |
---|
| 49 | % For each of the superpixel indicies, finds all of the |
---|
| 50 | % disconnected components with that label. if the component is |
---|
| 51 | % small (< 200 pixels) or isn't the biggest component with that |
---|
| 52 | % index, call analysesupinpatch with the outline of the component |
---|
| 53 | % to replace it's label with the one that is most common in the outline |
---|
| 54 | %%% |
---|
| 55 | |
---|
| 56 | if nargin < 2 |
---|
| 57 | rankcheck = 0; |
---|
| 58 | end |
---|
| 59 | [yn xn] = size(im); |
---|
| 60 | Ngmax = max(max(im)); % number of superpixel group |
---|
| 61 | SE = strel('octagon',3); |
---|
| 62 | for i=1:double(Ngmax) |
---|
| 63 | if sum(sum(im(:,:)==i)) |
---|
| 64 | % label connected component |
---|
| 65 | temp = zeros(size(im)); |
---|
| 66 | temp(im(:,:)==i)=1; |
---|
| 67 | [L,num] = bwlabel(temp,4); |
---|
| 68 | % find the main piece |
---|
| 69 | for k=1:num |
---|
| 70 | his(1,k)=sum(sum(L==k)); |
---|
| 71 | end |
---|
| 72 | [dum maxL ]= max(his); |
---|
| 73 | for k=1:num |
---|
| 74 | mask = L(:,:)==k; |
---|
| 75 | % filter out the superpixel smaller than 5 |
---|
| 76 | % then assign those pixels to mostlikely 3 by 3 neighborhood |
---|
| 77 | if k~=maxL || sum(sum(L(:,:)==k))<200 |
---|
| 78 | mask_dilate = imdilate(mask,SE); |
---|
| 79 | mask_dilate(mask) = 0; |
---|
| 80 | im(mask) = analysesupinpatch(im(mask_dilate));%hard work |
---|
| 81 | % [list_sup] = analysesupinpatch(im(mask_dilate));%hard work |
---|
| 82 | % [max_num max_sup_index] = max(list_sup(2,:)); |
---|
| 83 | % im(mask)=list_sup(1,max_sup_index); |
---|
| 84 | else |
---|
| 85 | im(mask) = i; |
---|
| 86 | end |
---|
| 87 | end |
---|
| 88 | end |
---|
| 89 | end |
---|
| 90 | return; |
---|