[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 [H] = calculateFilterBanks_old(img) %, type, numberOfStatistics) |
---|
| 40 | |
---|
| 41 | %if nargin < 3 |
---|
| 42 | % numberOfStatistics = 1; |
---|
| 43 | %end |
---|
| 44 | |
---|
| 45 | persistent L3 E3 S3 gMask % the Laws' masks |
---|
| 46 | persistent NB1 NB2 NB3 NB4 NB5 NB6 |
---|
| 47 | |
---|
| 48 | nLaw = 17; |
---|
| 49 | |
---|
| 50 | %nLaw = 0; |
---|
| 51 | %nRadon = 0; |
---|
| 52 | %nHarris = 0; |
---|
| 53 | %harrisSmoothingWidth = 9; |
---|
| 54 | |
---|
| 55 | %switch lower(type) |
---|
| 56 | % case 'purelaws' |
---|
| 57 | % nLaw = 9; |
---|
| 58 | % case {'laws', 'texture'} |
---|
| 59 | % nLaw = 17; |
---|
| 60 | % case {'harris', 'texture'} |
---|
| 61 | % nHarris = 10; |
---|
| 62 | % case {'radon'} |
---|
| 63 | % nRadon = nTopRadon*180/thetaStep; |
---|
| 64 | % case {'lawsradon'} |
---|
| 65 | % nLaw = 17; |
---|
| 66 | % nRadon = nTopRadon*180/thetaStep; |
---|
| 67 | % case {'lawsharris'} |
---|
| 68 | % nLaw = 17; |
---|
| 69 | % nHarris = 10; |
---|
| 70 | %end |
---|
| 71 | %nDim = nLaw + nHarris; |
---|
| 72 | |
---|
| 73 | %convultional filters |
---|
| 74 | if length(L3) <= 0 |
---|
| 75 | MatrixConditioner = .2; |
---|
| 76 | L3 = [1 2 1]/128/MatrixConditioner; |
---|
| 77 | E3 = [-1 0 1]; |
---|
| 78 | S3 = [-1 2 -1]; |
---|
| 79 | %L5 = [1 2 3 2 1]; %can be improved |
---|
| 80 | %L7 = [1 2 3 4 3 2 1]; % can be improved |
---|
| 81 | gMask = gaussMask(4,1.4); |
---|
| 82 | |
---|
| 83 | %Navatia Babu filters oriented at six angles (0,30,60,90,120,150) |
---|
| 84 | NB1 = [ -100, -100, 0, 100, 100; ... |
---|
| 85 | -100, -100, 0, 100, 100; ... |
---|
| 86 | -100, -100, 0, 100, 100; ... |
---|
| 87 | -100, -100, 0, 100, 100; ... |
---|
| 88 | -100, -100, 0, 100, 100]; |
---|
| 89 | NB2 = [ -100, 32, 100, 100, 100; ... |
---|
| 90 | -100,-78, 92, 100, 100; ... |
---|
| 91 | -100,-100, 0, 100, 100; ... |
---|
| 92 | -100,-100,-92, 78, 100; ... |
---|
| 93 | -100,-100,-100,-32, 100]; |
---|
| 94 | |
---|
| 95 | NB1 = NB1/2000; |
---|
| 96 | NB2 = NB2/2000; |
---|
| 97 | |
---|
| 98 | NB3 = -NB2'; |
---|
| 99 | NB4 = -NB1'; |
---|
| 100 | NB5 = -NB3(end:-1:1,:); |
---|
| 101 | NB6 = NB5'; |
---|
| 102 | end |
---|
| 103 | |
---|
| 104 | ycbcr_img = double(rgb2ycbcr(img)); %This computer has no image processing functions!! |
---|
| 105 | |
---|
| 106 | %ycbcr_img(:,:,1) = ycbcr_img(:,:,1) - mean( mean( ycbcr_img(:,:,1) )); |
---|
| 107 | %ycbcr_img(:,:,2) = ycbcr_img(:,:,2) - mean( mean( ycbcr_img(:,:,2) )); |
---|
| 108 | %ycbcr_img(:,:,3) = ycbcr_img(:,:,3) - mean( mean( ycbcr_img(:,:,3) )); |
---|
| 109 | |
---|
| 110 | imgY = ycbcr_img(:,:,1);% - mean( mean( ycbcr_img(:,:,1) )); |
---|
| 111 | %imgEdge = edge(imgY, 'sobel'); |
---|
| 112 | |
---|
| 113 | clear img; |
---|
| 114 | H = zeros( size(imgY,1), size(imgY,2), nLaw); |
---|
| 115 | %L3img = conv2(imgY, L3, 'valid'); |
---|
| 116 | %E3img = conv2(imgY, E3, 'valid'); |
---|
| 117 | %S3img = conv2(imgY, S3, 'valid'); |
---|
| 118 | %E3imgT = conv2(imgY, E3', 'valid'); |
---|
| 119 | |
---|
| 120 | temp = conv2(imgY, L3'*L3, 'valid'); |
---|
| 121 | temp = [ temp(1*ones(1,round((size(L3,2)-1)/2)),:); temp;... |
---|
| 122 | temp(end*ones(1,(size(L3,2)-1-round((size(L3,2)-1)/2))),:)]; |
---|
| 123 | H(:,:,1) = [temp(:,1*ones(1,round((size(L3,2)-1)/2))) temp... |
---|
| 124 | temp(:,end*ones(1,(size(E3,2)-1-round((size(E3,2)-1)/2))))]; |
---|
| 125 | |
---|
| 126 | temp = conv2(imgY, L3'*E3, 'valid'); |
---|
| 127 | temp = [ temp(1*ones(1,round((size(L3,2)-1)/2)),:); temp;... |
---|
| 128 | temp(end*ones(1,(size(L3,2)-1-round((size(L3,2)-1)/2))),:)]; |
---|
| 129 | H(:,:,2) = [temp(:,1*ones(1,round((size(E3,2)-1)/2))) temp... |
---|
| 130 | temp(:,end*ones(1,(size(E3,2)-1-round((size(E3,2)-1)/2))))]; |
---|
| 131 | |
---|
| 132 | temp = conv2(imgY, L3'*S3, 'valid'); |
---|
| 133 | temp = [ temp(1*ones(1,round((size(L3,2)-1)/2)),:); temp;... |
---|
| 134 | temp(end*ones(1,(size(L3,2)-1-round((size(L3,2)-1)/2))),:)]; |
---|
| 135 | H(:,:,3) = [temp(:,1*ones(1,round((size(S3,2)-1)/2))) temp... |
---|
| 136 | temp(:,end*ones(1,(size(S3,2)-1-round((size(S3,2)-1)/2))))]; |
---|
| 137 | |
---|
| 138 | temp = conv2(imgY, E3'*L3, 'valid'); |
---|
| 139 | temp = [ temp(1*ones(1,round((size(E3,2)-1)/2)),:); temp;... |
---|
| 140 | temp(end*ones(1,(size(E3,2)-1-round((size(E3,2)-1)/2))),:)]; |
---|
| 141 | H(:,:,4) = [temp(:,1*ones(1,round((size(L3,2)-1)/2))) temp... |
---|
| 142 | temp(:,end*ones(1,(size(L3,2)-1-round((size(L3,2)-1)/2))))]; |
---|
| 143 | |
---|
| 144 | temp = conv2(imgY, E3'*E3, 'valid'); |
---|
| 145 | temp = [ temp(1*ones(1,round((size(E3,2)-1)/2)),:); temp;... |
---|
| 146 | temp(end*ones(1,(size(E3,2)-1-round((size(E3,2)-1)/2))),:)]; |
---|
| 147 | H(:,:,5) = [temp(:,1*ones(1,round((size(E3,2)-1)/2))) temp... |
---|
| 148 | temp(:,end*ones(1,(size(E3,2)-1-round((size(E3,2)-1)/2))))]; |
---|
| 149 | |
---|
| 150 | temp = conv2(imgY, E3'*S3, 'valid'); |
---|
| 151 | temp = [ temp(1*ones(1,round((size(E3,2)-1)/2)),:); temp;... |
---|
| 152 | temp(end*ones(1,(size(E3,2)-1-round((size(E3,2)-1)/2))),:)]; |
---|
| 153 | H(:,:,6) = [temp(:,1*ones(1,round((size(S3,2)-1)/2))) temp... |
---|
| 154 | temp(:,end*ones(1,(size(S3,2)-1-round((size(S3,2)-1)/2))))]; |
---|
| 155 | |
---|
| 156 | temp = conv2(imgY, S3'*L3, 'valid'); |
---|
| 157 | temp = [ temp(1*ones(1,round((size(S3,2)-1)/2)),:); temp;... |
---|
| 158 | temp(end*ones(1,(size(S3,2)-1-round((size(S3,2)-1)/2))),:)]; |
---|
| 159 | H(:,:,7) = [temp(:,1*ones(1,round((size(L3,2)-1)/2))) temp... |
---|
| 160 | temp(:,end*ones(1,(size(L3,2)-1-round((size(L3,2)-1)/2))))]; |
---|
| 161 | |
---|
| 162 | temp = conv2(imgY, S3'*E3, 'valid'); |
---|
| 163 | temp = [ temp(1*ones(1,round((size(S3,2)-1)/2)),:); temp;... |
---|
| 164 | temp(end*ones(1,(size(S3,2)-1-round((size(S3,2)-1)/2))),:)]; |
---|
| 165 | H(:,:,8) = [temp(:,1*ones(1,round((size(E3,2)-1)/2))) temp... |
---|
| 166 | temp(:,end*ones(1,(size(E3,2)-1-round((size(E3,2)-1)/2))))]; |
---|
| 167 | |
---|
| 168 | temp = conv2(imgY, S3'*S3, 'valid'); |
---|
| 169 | temp = [ temp(1*ones(1,round((size(S3,2)-1)/2)),:); temp;... |
---|
| 170 | temp(end*ones(1,(size(S3,2)-1-round((size(S3,2)-1)/2))),:)]; |
---|
| 171 | H(:,:,9) = [temp(:,1*ones(1,round((size(S3,2)-1)/2))) temp... |
---|
| 172 | temp(:,end*ones(1,(size(S3,2)-1-round((size(S3,2)-1)/2))))]; |
---|
| 173 | |
---|
| 174 | temp = conv2( (ycbcr_img(:,:,2)), L3'*L3, 'valid'); |
---|
| 175 | temp = [ temp(1*ones(1,round((size(L3,2)-1)/2)),:); temp;... |
---|
| 176 | temp(end*ones(1,(size(L3,2)-1-round((size(L3,2)-1)/2))),:)]; |
---|
| 177 | H(:,:,10) = [temp(:,1*ones(1,round((size(L3,2)-1)/2))) temp... |
---|
| 178 | temp(:,end*ones(1,(size(L3,2)-1-round((size(L3,2)-1)/2))))]; |
---|
| 179 | |
---|
| 180 | temp = conv2( (ycbcr_img(:,:,3)), L3'*L3, 'valid'); |
---|
| 181 | temp = [ temp(1*ones(1,round((size(L3,2)-1)/2)),:); temp;... |
---|
| 182 | temp(end*ones(1,(size(L3,2)-1-round((size(L3,2)-1)/2))),:)]; |
---|
| 183 | H(:,:,11) = [temp(:,1*ones(1,round((size(L3,2)-1)/2))) temp... |
---|
| 184 | temp(:,end*ones(1,(size(L3,2)-1-round((size(L3,2)-1)/2))))]; |
---|
| 185 | |
---|
| 186 | %H(:,:,12) = conv2(E3img, L5', 'valid'); |
---|
| 187 | %H(:,:,13) = conv2(E3img, L7', 'valid'); |
---|
| 188 | %H(:,:,13) = conv2(E3imgT, L5, 'valid'); |
---|
| 189 | %H(:,:,15) = conv2(E3imgT, L7, 'valid'); |
---|
| 190 | |
---|
| 191 | temp = conv2(imgY, NB1, 'valid'); |
---|
| 192 | temp = [ temp(1*ones(1,round((size(NB1,1)-1)/2)),:); temp;... |
---|
| 193 | temp(end*ones(1,(size(NB1,1)-1-round((size(NB1,1)-1)/2))),:)]; |
---|
| 194 | H(:,:,12) = [temp(:,1*ones(1,round((size(NB1,2)-1)/2))) temp... |
---|
| 195 | temp(:,end*ones(1,(size(NB1,2)-1-round((size(NB1,2)-1)/2))))]; |
---|
| 196 | |
---|
| 197 | temp = conv2(imgY, NB2, 'valid'); |
---|
| 198 | temp = [ temp(1*ones(1,round((size(NB2,1)-1)/2)),:); temp;... |
---|
| 199 | temp(end*ones(1,(size(NB2,1)-1-round((size(NB2,1)-1)/2))),:)]; |
---|
| 200 | H(:,:,13) = [temp(:,1*ones(1,round((size(NB2,2)-1)/2))) temp... |
---|
| 201 | temp(:,end*ones(1,(size(NB2,2)-1-round((size(NB2,2)-1)/2))))]; |
---|
| 202 | |
---|
| 203 | temp = conv2(imgY, NB3, 'valid'); |
---|
| 204 | temp = [ temp(1*ones(1,round((size(NB3,1)-1)/2)),:); temp;... |
---|
| 205 | temp(end*ones(1,(size(NB3,1)-1-round((size(NB3,1)-1)/2))),:)]; |
---|
| 206 | H(:,:,14) = [temp(:,1*ones(1,round((size(NB3,2)-1)/2))) temp... |
---|
| 207 | temp(:,end*ones(1,(size(NB3,2)-1-round((size(NB3,2)-1)/2))))]; |
---|
| 208 | |
---|
| 209 | temp = conv2(imgY, NB4, 'valid'); |
---|
| 210 | temp = [ temp(1*ones(1,round((size(NB4,1)-1)/2)),:); temp;... |
---|
| 211 | temp(end*ones(1,(size(NB4,1)-1-round((size(NB4,1)-1)/2))),:)]; |
---|
| 212 | H(:,:,15) = [temp(:,1*ones(1,round((size(NB4,2)-1)/2))) temp... |
---|
| 213 | temp(:,end*ones(1,(size(NB4,2)-1-round((size(NB4,2)-1)/2))))]; |
---|
| 214 | |
---|
| 215 | temp = conv2(imgY, NB5, 'valid'); |
---|
| 216 | temp = [ temp(1*ones(1,round((size(NB5,1)-1)/2)),:); temp;... |
---|
| 217 | temp(end*ones(1,(size(NB5,1)-1-round((size(NB5,1)-1)/2))),:)]; |
---|
| 218 | H(:,:,16) = [temp(:,1*ones(1,round((size(NB5,2)-1)/2))) temp... |
---|
| 219 | temp(:,end*ones(1,(size(NB5,2)-1-round((size(NB5,2)-1)/2))))]; |
---|
| 220 | |
---|
| 221 | temp = conv2(imgY, NB6, 'valid'); |
---|
| 222 | temp = [ temp(1*ones(1,round((size(NB6,1)-1)/2)),:); temp;... |
---|
| 223 | temp(end*ones(1,(size(NB6,1)-1-round((size(NB6,1)-1)/2))),:)]; |
---|
| 224 | H(:,:,17) = [temp(:,1*ones(1,round((size(NB6,2)-1)/2))) temp... |
---|
| 225 | temp(:,end*ones(1,(size(NB6,2)-1-round((size(NB6,2)-1)/2))))]; |
---|
| 226 | H = abs(H); |
---|
| 227 | %H = H.^2; %Energy |
---|
| 228 | return; |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | %=======for Harris texture gradient =========== |
---|
| 233 | %Ix2 = conv2(H2(:,:,12), gMask, 'valid'); |
---|
| 234 | %Iy2 = conv2(H2(:,:,14), gMask, 'valid'); |
---|
| 235 | %Ixy = conv2(H(:,:,12) .* H(:,:,14), gMask, 'valid'); |
---|
| 236 | |
---|
| 237 | %anglesHarris = zeros( size(Ix2,1), size(Ix2,2), 2); |
---|
| 238 | %eigValue = zeros( size(Ix2,1), size(Ix2,2), 2); |
---|
| 239 | %upsilon = 1e-23; |
---|
| 240 | |
---|
| 241 | %gradientMagImage = sqrt(H2(:,:,12) + H2(:,:,14) ); |
---|
| 242 | %angleImage = round( (nHarris-1) * (pi/2+atan( H(:,:,12) ./ (H(:,:,14)+upsilon))) /pi) + 1; |
---|
| 243 | |
---|