1

У меня есть 2D-данные, хранящиеся в матрице [K,K]. Индексы представляют координаты (q_1, q_2) в наклонной системе координат, определяемой его напряжением -0.5<gamma<0.5. Цель состоит в том, чтобы преобразовать данные в прямоугольной системе координат, которая определяется координатами:Преобразование матрицы в прямоугольную координату

q_x = q_1 
q_y = q_2 - gamma*q_1 

Результат показан на рисунке:

oblique and rectangular systems

Код ниже достигает этой трансформации на пиксельной основе. Может ли кто-нибудь узнать более элегантный и векторный подход получить тот же результат?

% Oblique-to-rectangular coordinate transformation 
K = 10; % number of pixels 
gamma = 0.37; % some arbitrary strain position range (-0.5; 0.5) 
Koffset = (1-(-1).^(K-1))/4; % =0.5 when K is even, =0.0 when K is odd 

% Mock data 
S0 = rand(K,K); % data collected in the oblique coordinate system 

qindex = -ceil((K-1)/2) : floor((K-1)/2); % all the possible q-values, with the zero'th element in the middle. Must be in this order to comply with FFT's convention 

S = zeros(K,K); % data to be transformed to the rectangular coordinate system 

% let indices (i,j) run through all the positions of the oblique matrix 
for i=1:K 
    for j=1:K 
     % obtain the q-values corresponding to the current matrix position (i,j) 
     q1 = qindex(i); 
     q2 = qindex(j); 

     % apply the coordinate transformation to get the q-values in the rectangular system 
     qx = round(q1); 
     qy = round(q2-gamma*q1); 

     % apply periodic boundary condition 
     qy = qy - K*round((qy+Koffset)/K); % should be a unique value in the range of qindex 

     % find out the indices in the rectangular system 
     ii = i; 
     jj = find(qindex == qy); 

     % add the element 
     S(ii,jj) = S(ii,jj) + S0(i,j); 
    end 
end 

ответ

1

Лучший способ сделать это, чтобы создать сетку точек с помощью meshgrid, деформировать сетку, используя свои преобразования, а затем использовать interp2 попробовать оригинальное изображение в этих местах.

% Desired output range 
[xx,yy] = meshgrid(-3:0.01:3, -3:0.01:3); 

% Transform these X and Y coordinates to q1 and q2 coordinates 
q1 = xx; 
q2 = yy + gamma*q1; 

% Sample the original image using these coordinates where q1range and q2 
% range and the q1 and q2 values corresponding to each element in the image qdata 
output = interp2(q1range, q2range, qdata, q1, q2); 

 Смежные вопросы

  • Нет связанных вопросов^_^