[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 [relativeFeatureVector] = makeRelativeFeatureVector(H,scales)
|
---|
| 40 |
|
---|
| 41 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory...
|
---|
| 42 | ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default...
|
---|
| 43 | Horizon_default filename batchSize NuRow_default SegVertYSize SegHoriXSize WeiBatchSize PopUpVertY PopUpHoriX taskName;
|
---|
| 44 |
|
---|
| 45 | %global columnWidth rowWidth
|
---|
| 46 | global nDim nLaw
|
---|
| 47 | global nStatistics
|
---|
| 48 | global nHistBins
|
---|
| 49 | global minHist maxHist stepHist
|
---|
| 50 |
|
---|
| 51 | if nargin < 2
|
---|
| 52 | scale = 1;
|
---|
| 53 | end
|
---|
| 54 | %if nargin < 2
|
---|
| 55 | % type = 'laws';
|
---|
| 56 | %end
|
---|
| 57 |
|
---|
| 58 | nLaw = size(H,3);
|
---|
| 59 | numscales = length(scales);
|
---|
| 60 | H1size = nLaw;%nDim / nStatistics;
|
---|
| 61 |
|
---|
| 62 | nHistBins = 10;
|
---|
| 63 | %load([GeneralDataFolder '/maxHist.mat']);
|
---|
| 64 | %load([GeneralDataFolder '/minHist.mat']);
|
---|
| 65 | load([GeneralDataFolder '/MM.mat']);
|
---|
| 66 | if scales == 1
|
---|
| 67 | maxHist = Max{1}';
|
---|
| 68 | minHist = Min{1}';
|
---|
| 69 | elseif scales == 2
|
---|
| 70 | maxHist = Max{2}';
|
---|
| 71 | minHist = Min{2}';
|
---|
| 72 | else
|
---|
| 73 | maxHist = Max{3}';
|
---|
| 74 | minHist = Min{3}';
|
---|
| 75 | end
|
---|
| 76 | maxHist = log(1+maxHist);
|
---|
| 77 | minHist = log(1+minHist);
|
---|
| 78 | maxHist = log(1+maxHist);
|
---|
| 79 | minHist = log(1+minHist);
|
---|
| 80 |
|
---|
| 81 | %maxHist = [17, 12, 12, 12, 12, 12, 12, 12, 12, 15.9, 15.9, 24, 24, 24, 24, 24, 24]'; % How to pick values
|
---|
| 82 | %minHist = [10, 0, 0, 0, 0, 0, 0, 0, 0, 14.7, 14.7, 8, 8, 8, 8, 8, 8]';% How to pick values
|
---|
| 83 | maxHist = maxHist.^2;
|
---|
| 84 | minHist = minHist.^2;
|
---|
| 85 | stepHist = (maxHist - minHist) / (nHistBins-1);
|
---|
| 86 | step = 1/nHistBins;
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | %HistMinMax;
|
---|
| 90 | relativeFeatureVector = zeros( VertYNuDepth, HoriXNuDepth, H1size*numscales*nHistBins );
|
---|
| 91 |
|
---|
| 92 | %for s=1:numscales
|
---|
| 93 | s = 1;
|
---|
| 94 | scale = scales(1);
|
---|
| 95 | %reductionScale = 1/(2*(scale-1) + 1);
|
---|
| 96 | %if scale ~= 1
|
---|
| 97 | % resizedImg = imresize(img, reductionScale, 'bilinear');
|
---|
| 98 | %else
|
---|
| 99 | % resizedImg = img;
|
---|
| 100 | % end
|
---|
| 101 | %resizedImg(:,:,1) = medfilt2(resizedImg(:,:,1), [5, 5], 'symmetric');
|
---|
| 102 | %resizedImg(:,:,2) = medfilt2(resizedImg(:,:,2), [5, 5], 'symmetric');
|
---|
| 103 | %resizedImg(:,:,3) = medfilt2(resizedImg(:,:,3), [5, 5], 'symmetric');
|
---|
| 104 |
|
---|
| 105 | % numoverlaps = 0;
|
---|
| 106 | % if scale == 2
|
---|
| 107 | % numoverlaps = scale - 1;
|
---|
| 108 | % end
|
---|
| 109 | numoverlaps = scale - 1;
|
---|
| 110 |
|
---|
| 111 | edgefactor = (2*numoverlaps + 1);
|
---|
| 112 |
|
---|
| 113 | % Assume that the image is correctly oriented.
|
---|
| 114 | imheight = size(H, 1);
|
---|
| 115 | imwidth = size(H, 2);
|
---|
| 116 | % Step sizes in x and y
|
---|
| 117 | stepwidth = imwidth/HoriXNuDepth;
|
---|
| 118 | stepheight = imheight/VertYNuDepth;
|
---|
| 119 |
|
---|
| 120 | H = log( 1 + H );
|
---|
| 121 | H = log( 1 + H );
|
---|
| 122 | for l=1:nLaw
|
---|
| 123 | H(:,:,l) = (H(:,:,l) - repmat( minHist(l), size(H,1), size(H,2)) ) ./ ...
|
---|
| 124 | repmat( maxHist(l)-minHist(l), size(H,1), size(H,2) );
|
---|
| 125 | end
|
---|
| 126 | %====================================================================
|
---|
| 127 | %==================The Laws' Filters Applied=========================
|
---|
| 128 | %====================================================================
|
---|
| 129 |
|
---|
| 130 | intstepheight = floor((2*numoverlaps+1)*stepheight);
|
---|
| 131 | intstepwidth = floor((2*numoverlaps+1)*stepwidth);
|
---|
| 132 | for g = 1:VertYNuDepth
|
---|
| 133 | for c = 1:HoriXNuDepth
|
---|
| 134 | gridLeft = round( (g - 1 - numoverlaps)*stepheight + 1);
|
---|
| 135 | gridRight = round( (g + numoverlaps)*stepheight );
|
---|
| 136 | tempstep = gridRight - gridLeft + 1;
|
---|
| 137 | residue = tempstep - intstepheight;
|
---|
| 138 | if residue == 1
|
---|
| 139 | gridRight = gridRight - residue;
|
---|
| 140 | end
|
---|
| 141 | if residue > 1 || residue < 0
|
---|
| 142 | residue
|
---|
| 143 | display('oops');
|
---|
| 144 | end
|
---|
| 145 | normfactor = 1.0;
|
---|
| 146 | if gridLeft < 1
|
---|
| 147 | gridLeft = 1;
|
---|
| 148 | normfactor = normfactor * edgefactor / (numoverlaps + g);
|
---|
| 149 | elseif gridRight > (VertYNuDepth * stepheight)
|
---|
| 150 | gridRight = round(VertYNuDepth * stepheight);
|
---|
| 151 | normfactor = normfactor * edgefactor ...
|
---|
| 152 | / (numoverlaps + VertYNuDepth - g + 1);
|
---|
| 153 | end
|
---|
| 154 | gridTop = round( (c - 1 - numoverlaps)*stepwidth + 1);
|
---|
| 155 | gridBot = round( (c + numoverlaps)*stepwidth );
|
---|
| 156 | tempstep = gridBot - gridTop + 1;
|
---|
| 157 | residue = tempstep - intstepwidth;
|
---|
| 158 | if residue == 1
|
---|
| 159 | gridBot = gridBot - residue;
|
---|
| 160 | end
|
---|
| 161 | if residue > 1 || residue < 0
|
---|
| 162 | residue
|
---|
| 163 | display('oops');
|
---|
| 164 | end
|
---|
| 165 | if gridTop < 1
|
---|
| 166 | gridTop = 1;
|
---|
| 167 | normfactor = normfactor * edgefactor / (numoverlaps + c);
|
---|
| 168 | elseif gridBot > (HoriXNuDepth * stepwidth)
|
---|
| 169 | gridBot = round(HoriXNuDepth * stepwidth);
|
---|
| 170 | normfactor = normfactor * edgefactor ...
|
---|
| 171 | / (numoverlaps + HoriXNuDepth - c + 1);
|
---|
| 172 | end
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | % The Laws Histogram
|
---|
| 176 | tmpPatch = reshape( abs(H(gridLeft:gridRight, gridTop:gridBot, :)), ...
|
---|
| 177 | [(gridRight-gridLeft+1)*(gridBot-gridTop+1) nLaw]);
|
---|
| 178 | % histc( tmpPatch, min
|
---|
| 179 | rfv = histc( tmpPatch, [-inf, step:step:(1-step), inf]);
|
---|
| 180 | rfv = permute( reshape( rfv(1:nHistBins,:), nHistBins*H1size, 1), [2 3 1]);
|
---|
| 181 | relativeFeatureVector(g,c,...
|
---|
| 182 | ((s-1)*nHistBins*H1size + 1):( (s-1)*nHistBins*H1size + H1size*nHistBins) ) = ...
|
---|
| 183 | rfv;
|
---|
| 184 | end
|
---|
| 185 | end
|
---|
| 186 | clear H;
|
---|
| 187 |
|
---|
| 188 | %end
|
---|
| 189 | return;
|
---|