source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/Rendering/Oldversion/new_vrml_test_faceset_goodSkyBoundary.m @ 37

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

Added original make3d

File size: 9.5 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 [vrml_filename] = vrml_test_faceset_goodSkyBoundary(ScratchDataFolder,...
40          filename, Position3D, depth, ray, DepthDirectory,...
41          HBrokeBook, VBrokeBook, Grid, maskSky, maskG,...
42          Np, Sep, a, b, Ox,...
43          Oy, AppendFlag)
44%function [] = vrml_test_faceset_triangle(filename,PlaneParameterTure,LowResImgIndexSuperpixelSep,DepthDirectory,a,b,Ox,Oy)
45% this function play with the VRML
46% using only FaceSet
47
48%%% Param descriptions from Rajiv
49% filename - the name of the image file
50% Position3D - the matrix of 3d coordinates for all the point (55x305)
51% depth - the matrix of depth values for each point (55x305)
52% ray - the ray vector for each point in the image (55x305)
53% DepthDirectory - the name of the directory used to store final
54%   vrml files in a subfolder vrml
55% HBrokeBook - an array that contains the information if the
56%   triangle made during writing the vrml file should be reversed
57%   in order to align to a straight line
58% VBrokeBook - same as HBrokeBook but in the vertical direction
59% Grid - boolean variable which decides if there shud be a grid drawn in the vrml
60% maskSky - the skymask cell array, we need this not to draw the sky from the image
61% maskG - ground mask
62% Np - parameter which is used when deciding if Np neighbor pixels
63%   of a pixel are sky, then the pixel being considered should also
64%   be declared to be sky, this is because the sky mask is not accurate
65% Sep - parameter not used any more, shud be removed
66% a, -->
67% b, -->
68% Ox,-->
69% Oy,--> camera parameters used to generate the Ray, not used anymore as we directly pass the ray, should be removed
70%%%
71
72displayFlag = true;
73
74global GeneralDataFolder  LocalFolder ClusterExecutionDirectory...
75    ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default...
76    Horizon_default batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize;
77
78if nargin < 13
79    a = 0.70783777 %0.129; % horizontal physical size of image plane normalized to focal length (in meter)
80    b = 0.946584169%0.085; % vertical physical size of image plane normalized to focal length (in meter)
81    Ox = -0.010727086; % camera origin offset from the image center in horizontal direction
82    Oy = -0.0111130176; % camera origin offset from the image center in vertical direction
83elseif nargin < 14
84    b = a;
85    Ox = -0.010727086; % camera origin offset from the image center in horizontal direction
86    Oy = -0.0111130176; % camera origin offset from the image center in vertical direction
87elseif nargin < 15
88    Ox = -0.010727086; % camera origin offset from the image center in horizontal direction
89    Oy = -0.0111130176; % camera origin offset from the image center in vertical direction
90elseif nargin < 16
91    Oy = Ox;
92end
93
94if displayFlag
95disp('In VRML generation Code');
96end
97
98% define global variable
99global GeneralDataFolder  LocalFolder;
100
101%maskSky = imerode(maskSky, strel('disk', 3) );
102%maskG = imerode(maskSky, strel('disk', 3) );
103
104%calculating the mean of the sky color
105% imageActual = imread([GeneralDataFolder '/' ImgFolder '/' filename '.jpg']);
106% meanSkyColor = permute( sum( sum( repmat(maskSky, [1 1 3]) .* ...
107%                               double( imresize(imageActual, size(maskSky) ) ), 1), 2), [3 1 2]) ;
108% meanGroundColor = permute( sum( sum( repmat(maskG, [1 1 3]) .* ...
109%                               double( imresize(imageActual, size(maskG) ) ), 1), 2), [3 1 2]) ;
110% meanSkyColor = meanSkyColor / sum(sum( maskSky ) );
111% if any(isnan(meanSkyColor))
112%    if displayFlag
113%       disp('meanSkyColor NaN');
114%    end
115%    meanSkyColor = [0.31 0.54 0.76];
116% end
117% meanGroundColor = meanGroundColor / sum(sum( maskG ));
118% if any(isnan(meanGroundColor))
119%    if displayFlag
120%       disp('meanGroundColor NaN');
121%    end
122%    meanGroundColor = [0 0 0];
123% end
124
125vrml_filename = [DepthDirectory '.wrl'];
126%LowResImgIndexSuperpixelSepTemp = LowResImgIndexSuperpixelSep;
127%[VertYSize HoriXSize] = size(LowResImgIndexSuperpixelSepTemp);
128[dum VertYSize HoriXSize] = size(Position3D);
129%nu_patch = VertYSize* HoriXSize;
130
131Position3DCoord = reshape(Position3D,3,VertYSize*HoriXSize);   
132%Position3DCoord(3,:) = -Position3DCoord(3,:); % important to make z direction negative
133
134table = reshape(0:(VertYSize*HoriXSize-1),VertYSize,[]);
135Position3DCoordOrdeerIndex = zeros(1,92568); %RAJIV
136GridPosition3DCoordOrdeerIndex = zeros(1,92576);
137
138
139if displayFlag,
140disp('Going into FOR LOOP, which is bad in Matlab. This code should not take longer than 3 seconds');
141end
142
143for i = 1:VertYSize-1
144    for j = 1:HoriXSize-1
145           Index = [ table(i,j) table(i+1,j+1) table(i,j+1) table(i,j) table(i+1,j) table(i+1,j+1)];
146           GridIndex = [table(i,j) table(i+1,j+1) table(i,j+1) table(i,j)];
147           Position3DCoordOrdeerIndex = [Position3DCoordOrdeerIndex Index];
148           GridPosition3DCoordOrdeerIndex = [Position3DCoordOrdeerIndex GridIndex];
149    end
150end
151
152temp = ray(:,:,1:2)./repmat(ray(:,:,3),[1 1 2]);
153PositionTex = permute(temp./repmat(cat(3,a,b),[VertYSize HoriXSize 1])+repmat(cat(3,Ox,Oy),[VertYSize HoriXSize 1]),[3 1 2]);
154PositionTexCoord = PositionTex;   
155
156
157% inital header
158disp('writing vrml..');
159disp([ScratchDataFolder '/' vrml_filename])
160
161if ~AppendFlag
162fp = fopen([ScratchDataFolder '/' vrml_filename],'w+');
163
164fprintf(fp, '#VRML V2.0 utf8\n');
165
166% add navigate_info
167fprintf(fp, 'NavigationInfo {\n');
168fprintf(fp, '  headlight TRUE\n');
169fprintf(fp, '  type ["FLY", "ANY"]}\n\n');
170
171% add viewpoint
172fprintf(fp, 'Viewpoint {\n');
173fprintf(fp, '    position        0 0.0 0.0\n');
174fprintf(fp, '    orientation     0 0 0 0\n');
175fprintf(fp, '    fieldOfView     0.7\n');
176fprintf(fp, '    description "Original"}\n');
177
178%============== add background color======
179fprintf(fp, 'DEF Back1 Background {\n');
180fprintf(fp, 'groundColor [.3 .29 .27]\n');
181% fprintf(fp, 'groundColor [%f %f %f]\n', meanGroundColor/255);
182fprintf(fp, 'skyColor [0.31 0.54 0.76]}\n');
183% fprintf(fp, 'skyColor [%f %f %f]}\n', meanSkyColor/255);
184%=========================================
185else
186fp = fopen([ScratchDataFolder '/' vrml_filename],'a+');
187end
188
189% add Shape for texture faceset
190fprintf(fp, 'Shape{\n');
191fprintf(fp, '  appearance Appearance {\n');
192fprintf(fp, ['   texture ImageTexture { url "./' filename '.jpg' '" }\n']);
193fprintf(fp, '  }\n');
194fprintf(fp, '  geometry IndexedFaceSet {\n');
195fprintf(fp, '    coord Coordinate {\n');
196
197% insert coordinate in 3d
198% =======================
199fprintf(fp, '      point [ \n');
200fprintf(fp, '        %.2f %.2f %.2f,\n',Position3DCoord);
201fprintf(fp, '      ]\n');
202fprintf(fp, '    }\n');
203
204% insert coordinate index in 3d
205fprintf(fp, '    coordIndex [\n');
206fprintf(fp, '              %g %g %g -1,\n',Position3DCoordOrdeerIndex);
207fprintf(fp, '    ]\n');
208
209% insert texture coordinate
210fprintf(fp, '    texCoord TextureCoordinate {\n');
211fprintf(fp, '      point [\n');
212fprintf(fp, '              %.4g %.4g,\n',PositionTexCoord);
213fprintf(fp, '        ]\n');
214fprintf(fp, '    }\n');
215fprintf(fp, '    texCoordIndex [\n');
216fprintf(fp, '              %g %g %g -1,\n',Position3DCoordOrdeerIndex);
217fprintf(fp, '    ]\n');
218fprintf(fp, '  }\n');
219fprintf(fp, '}\n');
220
221if Grid == 1
222% ========================================
223fprintf(fp, 'Shape{\n');
224fprintf(fp, '  appearance Appearance { material Material {emissiveColor 1 0 0  }}\n');
225fprintf(fp, '    geometry IndexedLineSet {\n');
226fprintf(fp, '    coord Coordinate {\n');
227fprintf(fp, '      point [ \n');
228fprintf(fp, '        %.2f %.2f %.2f,\n',Position3DCoord);
229fprintf(fp, '      ]\n');
230fprintf(fp, '    }\n');
231fprintf(fp, '    coordIndex [\n');
232fprintf(fp, '              %g %g %g %g -1,\n',GridPosition3DCoordOrdeerIndex);
233fprintf(fp, '    ]\n');
234%fprintf(fp, '   color Color { color [1 0 0, 0 1 0, 0 0 1]}\n');
235%fprintf(fp, '   colorIndex [0 0 0 0 0 ]\n');
236fprintf(fp, '    colorPerVertex FALSE\n');
237fprintf(fp, '    }\n');
238%==================================
239fprintf(fp, '  }\n');
240fprintf(fp, '}\n');
241end
242% close the file
243fclose(fp);
244
245disp('Finished writing vrml');
Note: See TracBrowser for help on using the repository browser.