Interpolation of 2D matrix data

I have a two-dimensional matrix whose elements are data that can be matched and presented as an image. I want to interpolate them, but I get strange behavior at some boundaries that I cannot explain.

Here is the original image, the image after three iterations of the interpolation routine, and the image after 10 interpolation iterations. Original dataData after 3 interpolation iterationsData after 10 interpolation iterations

Here is my code:

close all

ifactor = 0.9;  % Interpolation factor

% Cut out the meaningless stuff at the edges
bshift_i = bshift(1:16, 1:50);

[m, n] = size(bshift_i);

% Plot the initial data using colormapping
figure()
imagesc(bshift_i, [7.5 10.5])
colorbar()

% Main processing loop
for ii = 1:10
    % Every iteration, we generate a grid that has the same size as the
    % existing data, and another one that whose axis step sizes are
    % (ifactor) times smaller than the existing axes.
    [b_x, b_y] = meshgrid(1:ifactor^(ii - 1):n, 1:ifactor^(ii - 1):m);
    [b_xi, b_yi] = meshgrid(1:ifactor^ii:n, 1:ifactor^ii:m);

    % Interpolate our data and reassign to bshift_i so that we can use it
    % in the next iteration
    bshift_i = interp2(b_x, b_y, bshift_i, b_xi, b_yi);
end

% Plot the interpolated image
figure()
imagesc(bshift_i, [7.5 10.5])
colorbar()

I'm mostly wondering why the blue artifacts appear on the bottom and right edges, and if so, how can I get around / avoiding them.

+2
source share
1 answer

, x y .
1:ifactor^(ii - 1):m:

  • 16 , 1 16.
  • 17 , 1 15.4
  • 19 , 1 15.58

, . , . (15.58 > 15.4).
interp2 , NaN ( bshift_i(end,end) NaN). NaN 0, , .

, , x y . :

[b_x, b_y] = meshgrid(linspace(1,n,n./(ifactor^(ii - 1))), ...
                      linspace(1,m,m./(ifactor^(ii - 1))));
[b_xi, b_yi] = meshgrid(linspace(1,n,n./(ifactor^(ii))), ...
                        linspace(1,m,m./(ifactor^(ii))));

linspace . , . , .

+1

All Articles