× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS
Ray Phan
Mar 31, 2015
<p>If you actually open up <code>impyramid</code> and see the source code, it boils down to an <code>imresize</code> call. Specifically, this is what happens when you use <code>expand</code> when calling <code>impyramid</code> when <code>A</code> is defined as the image:</p> <pre><code>M = size(A,1); N = size(A,2); scaleFactor = 2; outputSize = 2*[M N] - 1; kernel = makePiecewiseConstantFunction( ... [1.25 0.75 0.25 -0.25 -0.75 -1.25 -Inf], ... [0.0 0.125 0.5 0.75 0.5 0.125 0.0]); kernelWidth = 3; B = imresize(A, scaleFactor, {kernel, kernelWidth}, ... 'OutputSize', outputSize, 'Antialiasing', false); </code></pre> <p>As you can see, <code>outputSize</code> is defined as twice the image dimensions subtract 1, which is why you are off by 1 pixel per dimension. The function <code>makePiecewiseConstantFunction</code> is a local function that is defined in <code>impyramid</code>. I'll let you open it up and see that for yourself. Make sure this is defined before calling the above code.</p> <p>Therefore, simply remove the subtraction of 1 to achieve what you want.</p> <p>As such, call the above code, but change <code>outputSize</code> to:</p> <pre><code>outputSize = 2*[M N]; </code></pre> <hr> <p>However, if you want to be adventurous, you can modify this source code yourself to take in a flag where if you set it to <code>true</code>, it won't subtract by 1 and <code>false</code> performs the subtraction. Therefore, you can modify the header of <code>impyramid</code> to do this:</p> <pre><code>function B = impyramid(A, direction, padding) </code></pre> <p>Then, at the beginning before any computation is done, you can do this:</p> <pre><code>if nargin == 2 padding = false; end </code></pre> <p>This allows you to call <code>impyramid</code> without a third argument, which will default to no padding.</p> <p>Once you're done, in the <code>expand</code> section of the <code>if</code> statement, you can do:</p> <pre><code>else scaleFactor = 2; outputSize = 2*[M N]; if ~padding %// Change outputSize = outputSize - 1; end kernel = makePiecewiseConstantFunction( ... [1.25 0.75 0.25 -0.25 -0.75 -1.25 -Inf], ... [0.0 0.125 0.5 0.75 0.5 0.125 0.0]); kernelWidth = 3; end </code></pre> <p>The nested <code>if</code> statement then checks to see whether or not you want to allow the output image to be of size <code>2M x 2N</code> or <code>2M - 1 x 2N - 1</code>. As such, when you're done modifying the code, you can do:</p> <pre><code>scaled_result1_2 = impyramid(scale1_2, 'expand', true); scaled_result1_4 = impyramid(impyramid(scale1_4,'expand', true), 'expand', true); </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/29265346/Matlab%20impyramid%20issue/29265957">Stack Overflow</a>.</p>
comments powered by Disqus