Display polar gray values ​​in a matrix without interpolating each cycle

I have a matrix with gray values ​​between 0and 1. For each entry in the matrix there are certain polar coordinates that indicate the position of the gray values. I already have values Thetaand Rho(polar), as in separate matrices 512 × 960. And the values ​​of shades of gray (in the matrix called C) for each combination of Thetaand Rho. I have the same for Xand Ysince I just use pol2cartto convert. The problem is that I cannot directly build these values, because they still do not fit into the “bins” of the new matrix.

What I want: to put the gray values ​​in a square matrix of size 1024 × 1024. I can not do this directly, because the polar coordinates fall between the grid of this matrix. Therefore, we now use interpolation, but it takes a lot of time and must be performed separately for each data set, although the conversion from the original matrix to this final will always be the same. Therefore, I would like to solve this matrix once (analytically or numerically) and use matrix multiplication or something similar to effectively apply manipulations in each code loop.

One example of which of these transformations might look like this:

enter image description here

- , 1 ( ) - , , (don ).

, .

. TriScatteredInterp . scatteredInterpolant, . , , , , , MATLAB, , , ( ) .

+4
1

, , . .

, : wrapping. , θ = 2π = 0, MATLAB . AFAIK, MATLAB.

? , , N, , N . - , , MATLAB , . , - , .

, , :

function resize_polar()

    %% ORIGINAL IMAGE
    % ==========================================================================

    % Some random greyscale data
    C = double(rgb2gray(imread('stars.png')))/255;

    % Your current size, and desired size    
    sz_x = size(C,2);    new_sz_x = 1024;
    sz_y = size(C,1);    new_sz_y = 1024;

    % Ranges for teat and rho;  
    % replace with your actual values
    rho_start = 0;     theta_start = 0;
    rho_end   = 10;    theta_end   = 2*pi;

    % Generate regularly spaced grid;
    theta = linspace(theta_start, theta_end, sz_x);
    rho   = linspace(rho_start,   rho_end,   sz_y);

    [theta, rho] = meshgrid(theta,rho);


    % Make plot of generated data
    plot_polar(theta, rho, C, 'Original image');

    % Resize data
    [theta,rho,C] = resize_polar_data(theta, rho, C, [new_sz_y new_sz_x]);

    % Make plot of generated data
    plot_polar(theta, rho, C, 'Rescaled image');

end


function [theta,rho,data] = resize_polar_data(theta,rho,data, new_dims)

    % Create fake RGB image cube 
    IMG = cat(3, theta,rho,data);

    % Rescale as if theta and rho are RG color data in the RGB
    % image cube
    IMG = imresize(IMG, new_dims, 'nearest');

    % Split up the data again
    theta = IMG(:,:,1);
    rho   = IMG(:,:,2);
    data  = IMG(:,:,3);

end

function plot_polar(theta, rho, data, label)

    [X,Y] = pol2cart(theta, rho);

    figure('renderer', 'opengl')
    clf, hold on

    surf(X,Y,zeros(size(X)), data, ...
         'edgecolor', 'none');     
    colormap gray

    title(label);

end

:

512 × 960 PNG stars made with MS Paint

Original

Modified image

( ), , 512 × 960 1024 × 1024, .

imresize() :

nearest : 0.008511 seconds.
bilinear: 0.019651 seconds.
bicubic : 0.025390 seconds.  <-- default kernel

; , imresize GPU, , , .

, , :

  • imresize(),
  • . , , (0 2π) .
  • imresize()

: , . , , , . , .

+3

All Articles