source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/EdgeLearning/userReadImage.m

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

Added original make3d

File size: 5.1 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 supNew = userReadImage(image_name, img_label)
40% function userReadImage read the original image and the manually labeled
41% image segmentation and compute the corresponding edge image.
42% input: image_name -- the name of the original image
43%        image_label -- labeled image
44% by Nan Hu on 10/31/2007
45
46% load the images
47orgim = imread(image_name);
48labim = imread(img_label);
49
50% adding paths
51addpath(genpath('../../ec2/bin/mex'));
52
53% get the segmented image
54sup = gen_Sup_efficient_mod(orgim);
55
56% get the indexed label image
57%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58numSeg = 4; % this is manually input, needs improve
59%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60labels = get_indexed(labim,numSeg);
61labels = imresize(labels,size(sup),'nearest');
62
63% merge superpixels with the same labels
64[supNew thrd] = merge_sup_label(sup,labels);     %needs to be improved.........
65
66% generate edge map with 1 indicate the edge point
67% edgemap = gen_edgemap(sup, thrd);
68% imshow(edgemap);
69
70subplot(2,2,1), imshow(orgim);
71subplot(2,2,2), imshow(labim);
72subplot(2,2,3), imagesc(sup);
73subplot(2,2,4), imagesc(supNew);
74
75       
76%==========================================================================
77%subfunctions
78%--------------------------------------------------------------------------
79function labelimg = get_indexed(img,numSeg)
80%tmp = rgb2hsv(img);
81color = sum(img,3); %color = tmp(:,:,3);             %find the color info in the img
82sizeColor = size(color);
83labelimg = zeros(sizeColor);
84numColor = numel(color);
85color = reshape(color,numColor,1);
86clear tmp;
87for i=1:numSeg
88    [label, freq] = mode(color(logical(color)));    %   extract the i-th most frequent color rather than zero
89    labelimgtmp = zeros(sizeColor);
90    if freq > numColor/100
91        tmp = logical(abs(color - label)<1);      %   find the elements with the same color
92        labelimgtmp(tmp)=i;                    % set an index for this color
93        color(tmp)=0;                       % get rid of this color, for finding the next
94    end
95    %cleaning singular points
96    labelimgtmp = medfilt2(labelimgtmp,[3,3]);      %median filtering to kick off singular points
97    labelimg = labelimg + labelimgtmp;
98end   
99       
100%--------------------------------------------------------------------------
101function [sup threshold] = merge_sup_label(sup,labelimg)
102numSeg = unique(labelimg)';      % the total indeces
103numSeg = numSeg(2:end);
104indold = [];
105threshold = NaN;
106for i = numSeg
107    tmp = ~logical(labelimg - i);       % find the elements with the index
108    suplabeltmp = unique(sup(tmp))';     % get the indeces of the covered superpixels
109    if numel(suplabeltmp)>1             % merge the index of those superpixels
110        ind = median(suplabeltmp);
111        for j = suplabeltmp
112            if ~(j==ind)
113                sup(~logical(sup-j))=ind;
114            end
115        end
116    end
117    if ~isempty(indold)
118        threshold = min(threshold,abs(ind-indold)); %threshold is used in edge detection
119    end
120    indold = ind;
121    clear tmp suplabeltmp;
122end
123threshold = threshold/max(sup(:));       
124%--------------------------------------------------------------------------
125function edgemap = gen_edgemap(sup,thrd)
126if nargin<2
127    edgemap = edge(sup,'canny');
128elseif nargin==2
129    edgemap = edge(sup,'canny',thrd);
130end
Note: See TracBrowser for help on using the repository browser.