The problem of Matlab's empire

I have a problem with an empyramid using Matlab. I am trying to save one thumbnail version of a binary image, as well as two thumbnail versions of this binary image. This is easy to do in Matlab, as shown in the following code:

scale1_2= impyramid(compressed_image, 'reduce');
scale1_4= impyramid(scale1_2, 'reduce');

Thus, an image of 810x1080 size is saved with 405x540 and 203x270 pixels. The problem I am facing is when I try to rotate these two images back to have the same dimensions as before.

scaled_result1_2=impyramid(scale1_2,'expand');
scaled_result1_4=impyramid(impyramid(scale1_4,'expand'), 'expand');

So, it is expected that scaled_result1_2 and scaled_result1_4 will again display 810x1080, but not:

>>size(scaled_result1_2)
     809        1079
>>size(scaled_result1_4)
     809        1077

, 810x1080 , impyramid . imresize, ? () ?

+4
1

impyramid , imresize. , , , expand impyramid, A :

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);

, outputSize 1, 1 . makePiecewiseConstantFunction , impyramid. . , .

1 .

, , outputSize :

outputSize = 2*[M N];

, , , , , true, 1 false . impyramid, :

function B = impyramid(A, direction, padding)

, , :

if nargin == 2
    padding = false;
end

impyramid , .

, expand if :

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

if , 2M x 2N 2M - 1 x 2N - 1. , , :

scaled_result1_2 = impyramid(scale1_2, 'expand', true);
scaled_result1_4 = impyramid(impyramid(scale1_4,'expand', true), 'expand', true);
+5

All Articles