[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 makeDepthImages(dataNumber, displayFlag) |
---|
| 40 | |
---|
| 41 | if nargin < 2 |
---|
| 42 | displayFlag = false; |
---|
| 43 | end |
---|
| 44 | if nargin < 1 |
---|
| 45 | dataNumber = 1; |
---|
| 46 | end |
---|
| 47 | % if dataNumber == 10 |
---|
| 48 | % waithere = 1; |
---|
| 49 | % end |
---|
| 50 | %% we first read the log file and then read the depth values in a |
---|
| 51 | %% two-dimensional array after binning and averaging values for each bin |
---|
| 52 | %% value |
---|
| 53 | homeData='/afs/cs/group/reconstruction3d/Data/Dataset_July7/scenario'; |
---|
| 54 | depthDirectory = strcat(homeData,num2str(dataNumber),'/'); |
---|
| 55 | imgDirectory = strcat(homeData,num2str(dataNumber),'/'); |
---|
| 56 | %Win05: |
---|
| 57 | % system([ 'cat ' depthDirectory depthFilename ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFilename 'cleaned']); |
---|
| 58 | % Above command is passed in Linux to clear the text, leaving only numbers, which can be directly |
---|
| 59 | % imported into Matlab by using File > Import Data |
---|
| 60 | dirList = dir([depthDirectory '*.txt']); |
---|
| 61 | depthFileInitialname = dirList(1).name; |
---|
| 62 | |
---|
| 63 | % system([ 'cat ' depthDirectory depthFileInitialname ' | sed /PTLASER/\d | cat > ' depthDirectory depthFileInitialname 'image1']); |
---|
| 64 | % system([ 'cat ' depthDirectory depthFileInitialname 'image1' ' | sed s/IMAGE/\/g | cat > ' depthDirectory depthFileInitialname 'image2']); |
---|
| 65 | % system([ 'cat ' depthDirectory depthFileInitialname 'image2' ' | sed s/data/\\n\data/g | cat > ' depthDirectory depthFileInitialname 'image3']); |
---|
| 66 | % system([ 'cat ' depthDirectory depthFileInitialname 'image3' ' | sed /data/\d | cat > ' depthDirectory depthFileInitialname 'image']); |
---|
| 67 | % |
---|
| 68 | % system([ 'cat ' depthDirectory depthFileInitialname ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFileInitialname 'cleaned1']); |
---|
| 69 | % system([ 'cat ' depthDirectory depthFileInitialname 'cleaned1' ' | sed /IMAGE/\d | cat > ' depthDirectory depthFileInitialname 'cleaned']); |
---|
| 70 | % |
---|
| 71 | % system([ 'rm ' depthDirectory depthFileInitialname 'cleaned1']); |
---|
| 72 | % system([ 'rm ' depthDirectory depthFileInitialname 'image1']); |
---|
| 73 | % system([ 'rm ' depthDirectory depthFileInitialname 'image2']); |
---|
| 74 | % system([ 'rm ' depthDirectory depthFileInitialname 'image3']); |
---|
| 75 | |
---|
| 76 | depthFilename = strcat(depthFileInitialname,'cleaned'); |
---|
| 77 | imageFileForAnglesName = strcat(depthFileInitialname,'image'); |
---|
| 78 | rawDepth = load([depthDirectory depthFilename]); %load([directory 'log' num2str(dataNumber) '.mat']); |
---|
| 79 | imageAngList = load([depthDirectory imageFileForAnglesName]); |
---|
| 80 | floor(rawDepth(1,2)) |
---|
| 81 | if (floor(rawDepth(1,2))<-184) |
---|
| 82 | beginAngD=-202.7; |
---|
| 83 | angShiftForImg=31; |
---|
| 84 | elseif (floor(rawDepth(1,2))<-180) |
---|
| 85 | beginAngD=-200.4; |
---|
| 86 | angShiftForImg=31.1; |
---|
| 87 | elseif (floor(rawDepth(1,2))<-40) |
---|
| 88 | beginAngD=-13.8; |
---|
| 89 | angShiftForImg=31; |
---|
| 90 | end |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | for imageNumber=1:length(imageAngList) |
---|
| 94 | |
---|
| 95 | centerAngle = beginAngD + imageNumber*angShiftForImg; |
---|
| 96 | |
---|
| 97 | %Win05: Recalculate these numbers by looking at images and depthmaps |
---|
| 98 | laserAngleScan = 19; |
---|
| 99 | topAngle = 63; %% earlier 63 |
---|
| 100 | botAngle = 63; %% if we make it 64, the left side of the image is more aligned, however if we make it 62, |
---|
| 101 | %% the right siede of the image is more aligned, so we are choosing it to be 63 |
---|
| 102 | leftAngle = 10; |
---|
| 103 | rightAngle = 7; |
---|
| 104 | horThetaStep = 0.125; %.5 |
---|
| 105 | |
---|
| 106 | % close all; |
---|
| 107 | % depthDirectory = './dataset1/'; |
---|
| 108 | % imgDirectory = './dataset1/'; |
---|
| 109 | % |
---|
| 110 | % if uniqueCode > 0 |
---|
| 111 | % dirList = dir([depthDirectory '*.txt']); |
---|
| 112 | % depthFilename = dirList(uniqueCode).name; |
---|
| 113 | |
---|
| 114 | % depthDirectory = './dataset1/'; |
---|
| 115 | % imgDirectory = './dataset1/'; |
---|
| 116 | %Win05: |
---|
| 117 | % system([ 'cat ' depthDirectory depthFilename ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFilename 'cleaned']); |
---|
| 118 | % Above command is passed in Linux to clear the text, leaving only numbers, which can be directly |
---|
| 119 | % imported into Matlab by using File > Import Data |
---|
| 120 | |
---|
| 121 | % dirList = dir([depthDirectory '*.txt']); |
---|
| 122 | % depthFilename = dirList(1).name; |
---|
| 123 | % % use to remove PTLASER text from files |
---|
| 124 | % % system([ 'cat ' depthDirectory depthFilename ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFilename 'cleaned']); |
---|
| 125 | % depthFilename = strcat(depthFilename,'cleaned'); |
---|
| 126 | % % dirList = dir([imgDirectory '*right*.jpg']); |
---|
| 127 | imagePanAngD=imageAngList(:,2); |
---|
| 128 | imagePanAngD=(imagePanAngD<-180).*(imagePanAngD+360)+(imagePanAngD>-180).*(imagePanAngD); |
---|
| 129 | imagePanAngRndD = round(imageAngList(:,2)); |
---|
| 130 | dirList = dir([imgDirectory strcat('*',num2str(abs(imagePanAngRndD(imageNumber))),'*.jpg')]); |
---|
| 131 | |
---|
| 132 | % dirList = dir([imgDirectory '*.jpg']); |
---|
| 133 | % %dirList = dir([imgDirectory 'packard1_10-28-05right*.jpg']); |
---|
| 134 | % imNumber = -imageNumber+7; |
---|
| 135 | % if imNumber <=0 |
---|
| 136 | % imNumber = imNumber+12; |
---|
| 137 | % end |
---|
| 138 | imageFilename = dirList(1).name; |
---|
| 139 | %% 5 is 1 going down and coming back in a circle from 12 |
---|
| 140 | |
---|
| 141 | % rawDepth = load([depthDirectory depthFilename]); %load([directory 'log' num2str(dataNumber) '.mat']); |
---|
| 142 | x = (centerAngle-laserAngleScan):horThetaStep:(centerAngle+laserAngleScan); |
---|
| 143 | |
---|
| 144 | sizeHor = round( (-min(rawDepth(:,2)) + max(rawDepth(:,2) ) )/ horThetaStep ); |
---|
| 145 | quantizedRawDepth = zeros( length(x), size(rawDepth,2)-4 ); |
---|
| 146 | angleIndex = 0; |
---|
| 147 | |
---|
| 148 | for xc = (centerAngle-laserAngleScan):horThetaStep:(centerAngle+laserAngleScan) |
---|
| 149 | if (xc>max(rawDepth(:,2))) |
---|
| 150 | x=xc-360; |
---|
| 151 | elseif (xc<min(rawDepth(:,2))) |
---|
| 152 | x=xc+360; |
---|
| 153 | else |
---|
| 154 | x=xc; |
---|
| 155 | end |
---|
| 156 | [tmp ind] = min( abs( rawDepth(:,2) - x) ); |
---|
| 157 | %Win05: I remember 2nd column contained the time stamp, therefore it basically matches |
---|
| 158 | % the timestamp |
---|
| 159 | %IMPROVEMENT: instead of nearest one, do AVERAGING |
---|
| 160 | angleIndex = angleIndex + 1; |
---|
| 161 | quantizedRawDepth(angleIndex,:) = rawDepth(ind, 5:size(rawDepth,2) ); |
---|
| 162 | %Win05: 5 because first 4 numbers are not useful |
---|
| 163 | end |
---|
| 164 | |
---|
| 165 | clippedDepth = quantizedRawDepth( size(quantizedRawDepth,1):-1:1, ... |
---|
| 166 | (size(quantizedRawDepth,2)-topAngle):-1:botAngle )'; |
---|
| 167 | |
---|
| 168 | min(clippedDepth(:)); |
---|
| 169 | depthMap = (clippedDepth); |
---|
| 170 | %depthImg = clippedDepth .^ (1/3); |
---|
| 171 | % displayDepthMaps(depthMap); |
---|
| 172 | % figure; |
---|
| 173 | % imshow(A); |
---|
| 174 | |
---|
| 175 | if displayFlag |
---|
| 176 | A = imread([imgDirectory imageFilename]); %A = imread([directory 'img-' num2str(dataNumber) '.jpg']); |
---|
| 177 | % A=imrotate(A,-90); |
---|
| 178 | |
---|
| 179 | % %subplot(1,2,1); |
---|
| 180 | % image(A); |
---|
| 181 | % axis square; |
---|
| 182 | % %subplot(1,2,2); |
---|
| 183 | % figure, |
---|
| 184 | % imagesc( depthMap( :, leftAngle:(size(depthMap,2)-rightAngle) ) .^ (1/3) ); |
---|
| 185 | % axis square; |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | % image A = size(500,500,3 ), dephmap D = size(25,25), D_high = imresize(D, 500, 500, 'nearest') |
---|
| 189 | % B = rgb2ycbcr(A); B(:,:,2) = scaling factor * D_high, % set color channel tp depthmap. |
---|
| 190 | % imagesc(A), axis equal; imagesc(B), axis equal; displaydepthMap(D); |
---|
| 191 | % subplot(2,2,..) |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | % size(A) |
---|
| 195 | % size(depthMap) |
---|
| 196 | % D_high = imresize(depthMap, [size(A,1) size(A,2)], 'nearest'); |
---|
| 197 | % minDistance = min(min(D_high)); |
---|
| 198 | % maxDistance = max(max(D_high)); |
---|
| 199 | % B = rgb2hsv(A); |
---|
| 200 | % scaling_factor = 1/maxDistance; |
---|
| 201 | % B(:,:,1) = scaling_factor*D_high; |
---|
| 202 | % % B(:,:,2) = scaling_factor*D_high; % The scaling factor should be chosen such that values are in between |
---|
| 203 | % %% 0 and 255? Here we set color channel to depthmap. |
---|
| 204 | % % |
---|
| 205 | % figure; |
---|
| 206 | % subplot(1,2,1); |
---|
| 207 | % imagesc(A), axis equal; |
---|
| 208 | % |
---|
| 209 | % %% copying from displayDepthMap |
---|
| 210 | % |
---|
| 211 | % jetMap = jet; |
---|
| 212 | % % close; |
---|
| 213 | % jetMap = 1-jetMap(end:-1:1,:); |
---|
| 214 | % jetMap = jetMap(end:-1:1,:); |
---|
| 215 | % jetMap = imresize(jetMap, [256 3], 'bilinear'); |
---|
| 216 | % displayNorm = size(jetMap,1); |
---|
| 217 | % warning off; |
---|
| 218 | % D_high = uint8( displayNorm* (D_high - minDistance) / (maxDistance - minDistance) ); |
---|
| 219 | % warning on; |
---|
| 220 | % subplot(1,2,2); |
---|
| 221 | % imagesc( D_high ); axis equal; colormap( jetMap ); axis off; axis tight; |
---|
| 222 | % |
---|
| 223 | % figure; %subplot(2,2,2); |
---|
| 224 | % imagesc(B), axis equal; |
---|
| 225 | |
---|
| 226 | % size(A) |
---|
| 227 | % size(depthMap) |
---|
| 228 | D_high = imresize(depthMap, [size(A,1) size(A,2)], 'nearest'); |
---|
| 229 | % B = rgb2hsv(A); |
---|
| 230 | B = rgb2ycbcr(A); |
---|
| 231 | scaling_factor = 3; |
---|
| 232 | B(:,:,2) = scaling_factor*D_high; % The scaling factor should be chosen such that values are in between |
---|
| 233 | % 0 and 255? Here we set color channel to depthmap. |
---|
| 234 | |
---|
| 235 | figure; |
---|
| 236 | subplot(1,2,1); |
---|
| 237 | imagesc(A), axis equal; |
---|
| 238 | |
---|
| 239 | % copying from displayDepthMap |
---|
| 240 | |
---|
| 241 | minDistance = min(min(D_high)); |
---|
| 242 | maxDistance = max(max(D_high)); |
---|
| 243 | jetMap = jet; |
---|
| 244 | % close; |
---|
| 245 | jetMap = 1-jetMap(end:-1:1,:); |
---|
| 246 | jetMap = jetMap(end:-1:1,:); |
---|
| 247 | jetMap = imresize(jetMap, [256 3], 'bilinear'); |
---|
| 248 | displayNorm = size(jetMap,1); |
---|
| 249 | warning off; |
---|
| 250 | D_high = uint8( displayNorm* (D_high - minDistance) / (maxDistance - minDistance) ); |
---|
| 251 | warning on; |
---|
| 252 | subplot(1,2,2); |
---|
| 253 | imagesc( D_high ); axis equal; colormap( jetMap ); axis off; axis tight; |
---|
| 254 | |
---|
| 255 | figure; %subplot(2,2,2); |
---|
| 256 | imagesc(B), axis equal; |
---|
| 257 | end |
---|
| 258 | |
---|
| 259 | % if imageNumber == 5 |
---|
| 260 | % waithere = 1; |
---|
| 261 | % end |
---|
| 262 | % displaydepthMap(D); |
---|
| 263 | % |
---|
| 264 | % subplot(2,2,..); |
---|
| 265 | |
---|
| 266 | directory = '/afs/cs/group/reconstruction3d/scratch/Min/rawlaserdata/'; |
---|
| 267 | save([directory strrep(strrep(imageFilename,'img','depth'),'.jpg','.mat')], 'depthMap' ); |
---|
| 268 | % save([directory strrep(strrep(imageFilename,'img','depth_high_res'),'.jpg','.mat')], 'D_high' ); |
---|
| 269 | % save([directory 'calculatedDepthData-' num2str(dataNumber) '.mat'], 'depthMap' ); |
---|
| 270 | % imwrite( depthMap/ max(depthMap(:) ), [directory 'calculatedDepthImgSet2-' num2str(dataNumber) '.jpg']); |
---|
| 271 | end |
---|