[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 | centerAngle = -171.7 + dataNumber*31; |
---|
| 48 | |
---|
| 49 | %Win05: Recalculate these numbers by looking at images and depthmaps |
---|
| 50 | laserAngleScan = 19; |
---|
| 51 | topAngle = 63; %% earlier 63 |
---|
| 52 | botAngle = 63; %% if we make it 64, the left side of the image is more aligned, however if we make it 62, |
---|
| 53 | %% the right siede of the image is more aligned, so we are choosing it to be 63 |
---|
| 54 | leftAngle = 10; |
---|
| 55 | rightAngle = 7; |
---|
| 56 | horThetaStep = 0.125; %.5 |
---|
| 57 | |
---|
| 58 | % close all; |
---|
| 59 | % depthDirectory = './dataset1/'; |
---|
| 60 | % imgDirectory = './dataset1/'; |
---|
| 61 | % |
---|
| 62 | % if uniqueCode > 0 |
---|
| 63 | % dirList = dir([depthDirectory '*.txt']); |
---|
| 64 | % depthFilename = dirList(uniqueCode).name; |
---|
| 65 | |
---|
| 66 | homeData='/afs/cs/group/reconstruction3d/Data/Dataset_July7/scenario'; |
---|
| 67 | depthDirectory = strcat(homeData,num2str(dataNumber),'/'); |
---|
| 68 | imgDirectory = strcat(homeData,num2str(dataNumber),'/'); |
---|
| 69 | %Win05: |
---|
| 70 | % system([ 'cat ' depthDirectory depthFilename ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFilename 'cleaned']); |
---|
| 71 | % Above command is passed in Linux to clear the text, leaving only numbers, which can be directly |
---|
| 72 | % imported into Matlab by using File > Import Data |
---|
| 73 | |
---|
| 74 | dirList = dir([depthDirectory '*.txt']); |
---|
| 75 | depthFilename = dirList(1).name; |
---|
| 76 | % use to remove PTLASER text from files |
---|
| 77 | % system([ 'cat ' depthDirectory depthFilename ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFilename 'cleaned']); |
---|
| 78 | depthFilename = strcat(depthFilename,'cleaned'); |
---|
| 79 | % dirList = dir([imgDirectory '*right*.jpg']); |
---|
| 80 | dirList = dir([imgDirectory '*.jpg']); |
---|
| 81 | %dirList = dir([imgDirectory 'packard1_10-28-05right*.jpg']); |
---|
| 82 | imNumber = -dataNumber+6; |
---|
| 83 | if imNumber <=0 |
---|
| 84 | imNumber = imNumber+13; |
---|
| 85 | if imNumber == 7 |
---|
| 86 | imNumber = 6; |
---|
| 87 | end |
---|
| 88 | end |
---|
| 89 | imageFilename = dirList(imNumber).name; |
---|
| 90 | %% 5 is 1 going down and coming back in a circle from 13, 7 is not |
---|
| 91 | %% there, but 6 is. So 1-5, 2-4, 3-3, 4-2, 5-1, 6-13, 7-12, 8-11, 9-10, |
---|
| 92 | %% , 10-9, 11-8, 12-6 skipping 7 |
---|
| 93 | |
---|
| 94 | logDepth = load([depthDirectory depthFilename]); %load([directory 'log' num2str(dataNumber) '.mat']); |
---|
| 95 | A = imread([imgDirectory imageFilename]); %A = imread([directory 'img-' num2str(dataNumber) '.jpg']); |
---|
| 96 | x = (centerAngle-laserAngleScan):horThetaStep:(centerAngle+laserAngleScan); |
---|
| 97 | |
---|
| 98 | sizeHor = round( (-min(logDepth(:,2)) + max(logDepth(:,2) ) )/ horThetaStep ); |
---|
| 99 | quantizedLogDepth = zeros( length(x), size(logDepth,2)-4 ); |
---|
| 100 | angleIndex = 0; |
---|
| 101 | |
---|
| 102 | for xc = (centerAngle-laserAngleScan):horThetaStep:(centerAngle+laserAngleScan) |
---|
| 103 | if (xc>max(logDepth(:,2))) |
---|
| 104 | x=(xc-180)-180;%212; |
---|
| 105 | % if (x<min(logDepth(:,2))) |
---|
| 106 | % x=max(logDepth(:,2))+x-min(logDepth(:,2)); |
---|
| 107 | % end |
---|
| 108 | else |
---|
| 109 | x=xc; |
---|
| 110 | end |
---|
| 111 | [tmp ind] = min( abs( logDepth(:,2) - x) ); |
---|
| 112 | %Win05: I remember 2nd column contained the time stamp, therefore it basically matches |
---|
| 113 | % the timestamp |
---|
| 114 | %IMPROVEMENT: instead of nearest one, do AVERAGING |
---|
| 115 | angleIndex = angleIndex + 1; |
---|
| 116 | quantizedLogDepth(angleIndex,:) = logDepth(ind, 5:size(logDepth,2) ); |
---|
| 117 | %Win05: 5 because first 4 numbers are not useful |
---|
| 118 | end |
---|
| 119 | |
---|
| 120 | clippedDepth = quantizedLogDepth( size(quantizedLogDepth,1):-1:1, ... |
---|
| 121 | (size(quantizedLogDepth,2)-topAngle):-1:botAngle )'; |
---|
| 122 | |
---|
| 123 | min(clippedDepth(:)); |
---|
| 124 | depthMap = (clippedDepth); |
---|
| 125 | %depthImg = clippedDepth .^ (1/3); |
---|
| 126 | % displayDepthMaps(depthMap); |
---|
| 127 | % figure; |
---|
| 128 | % imshow(A); |
---|
| 129 | |
---|
| 130 | % if displayFlag |
---|
| 131 | % %subplot(1,2,1); |
---|
| 132 | % image(A); |
---|
| 133 | % axis square; |
---|
| 134 | % %subplot(1,2,2); |
---|
| 135 | % figure, |
---|
| 136 | % imagesc( depthMap( :, leftAngle:(size(depthMap,2)-rightAngle) ) .^ (1/3) ); |
---|
| 137 | % axis square; |
---|
| 138 | % end |
---|
| 139 | % |
---|
| 140 | % % image A = size(500,500,3 ), dephmap D = size(25,25), D_high = imresize(D, 500, 500, 'nearest') |
---|
| 141 | % % B = rgb2ycbcr(A); B(:,:,2) = scaling factor * D_high, % set color channel tp depthmap. |
---|
| 142 | % % imagesc(A), axis equal; imagesc(B), axis equal; displaydepthMap(D); |
---|
| 143 | % % subplot(2,2,..) |
---|
| 144 | % |
---|
| 145 | % |
---|
| 146 | % % size(A) |
---|
| 147 | % % size(depthMap) |
---|
| 148 | % % D_high = imresize(depthMap, [size(A,1) size(A,2)], 'nearest'); |
---|
| 149 | % % minDistance = min(min(D_high)); |
---|
| 150 | % % maxDistance = max(max(D_high)); |
---|
| 151 | % % B = rgb2hsv(A); |
---|
| 152 | % % scaling_factor = 1/maxDistance; |
---|
| 153 | % % B(:,:,1) = scaling_factor*D_high; |
---|
| 154 | % % % B(:,:,2) = scaling_factor*D_high; % The scaling factor should be chosen such that values are in between |
---|
| 155 | % % %% 0 and 255? Here we set color channel to depthmap. |
---|
| 156 | % % % |
---|
| 157 | % % figure; |
---|
| 158 | % % subplot(1,2,1); |
---|
| 159 | % % imagesc(A), axis equal; |
---|
| 160 | % % |
---|
| 161 | % % %% copying from displayDepthMap |
---|
| 162 | % % |
---|
| 163 | % % jetMap = jet; |
---|
| 164 | % % % close; |
---|
| 165 | % % jetMap = 1-jetMap(end:-1:1,:); |
---|
| 166 | % % jetMap = jetMap(end:-1:1,:); |
---|
| 167 | % % jetMap = imresize(jetMap, [256 3], 'bilinear'); |
---|
| 168 | % % displayNorm = size(jetMap,1); |
---|
| 169 | % % warning off; |
---|
| 170 | % % D_high = uint8( displayNorm* (D_high - minDistance) / (maxDistance - minDistance) ); |
---|
| 171 | % % warning on; |
---|
| 172 | % % subplot(1,2,2); |
---|
| 173 | % % imagesc( D_high ); axis equal; colormap( jetMap ); axis off; axis tight; |
---|
| 174 | % % |
---|
| 175 | % % figure; %subplot(2,2,2); |
---|
| 176 | % % imagesc(B), axis equal; |
---|
| 177 | % |
---|
| 178 | % size(A) |
---|
| 179 | % size(depthMap) |
---|
| 180 | % D_high = imresize(depthMap, [size(A,1) size(A,2)], 'nearest'); |
---|
| 181 | % % B = rgb2hsv(A); |
---|
| 182 | % % B = rgb2ycbcr(A); |
---|
| 183 | % % scaling_factor = 3; |
---|
| 184 | % % B(:,:,2) = scaling_factor*D_high; % The scaling factor should be chosen such that values are in between |
---|
| 185 | % %% 0 and 255? Here we set color channel to depthmap. |
---|
| 186 | % % |
---|
| 187 | % % figure; |
---|
| 188 | % % subplot(1,2,1); |
---|
| 189 | % % imagesc(A), axis equal; |
---|
| 190 | % |
---|
| 191 | % %% copying from displayDepthMap |
---|
| 192 | % |
---|
| 193 | % % minDistance = min(min(D_high)); |
---|
| 194 | % % maxDistance = max(max(D_high)); |
---|
| 195 | % % jetMap = jet; |
---|
| 196 | % % close; |
---|
| 197 | % % jetMap = 1-jetMap(end:-1:1,:); |
---|
| 198 | % % jetMap = jetMap(end:-1:1,:); |
---|
| 199 | % % jetMap = imresize(jetMap, [256 3], 'bilinear'); |
---|
| 200 | % % displayNorm = size(jetMap,1); |
---|
| 201 | % % warning off; |
---|
| 202 | % % D_high = uint8( displayNorm* (D_high - minDistance) / (maxDistance - minDistance) ); |
---|
| 203 | % % warning on; |
---|
| 204 | % % subplot(1,2,2); |
---|
| 205 | % % imagesc( D_high ); axis equal; colormap( jetMap ); axis off; axis tight; |
---|
| 206 | % |
---|
| 207 | % % figure; %subplot(2,2,2); |
---|
| 208 | % % imagesc(B), axis equal; |
---|
| 209 | % |
---|
| 210 | % % if dataNumber == 5 |
---|
| 211 | % % waithere = 1; |
---|
| 212 | % % end |
---|
| 213 | % % displaydepthMap(D); |
---|
| 214 | % % |
---|
| 215 | % % subplot(2,2,..); |
---|
| 216 | |
---|
| 217 | directory = '/afs/cs/group/reconstruction3d/scratch/Min/rawlaserdata/'; |
---|
| 218 | save([directory strrep(strrep(imageFilename,'img','depth'),'.jpg','.mat')], 'depthMap' ); |
---|
| 219 | % save([directory strrep(strrep(imageFilename,'img','depth_high_res'),'.jpg','.mat')], 'D_high' ); |
---|
| 220 | % save([directory 'calculatedDepthData-' num2str(dataNumber) '.mat'], 'depthMap' ); |
---|
| 221 | % imwrite( depthMap/ max(depthMap(:) ), [directory 'calculatedDepthImgSet2-' num2str(dataNumber) '.jpg']); |
---|