以下は、アフィン変換を画像に適用する簡単な実装です。私はこれをメモリから行ったため、一部の行列が逆になる可能性があります。私はあなたのpts配列をどのようにフォーマットしているのか正確には分かりませんので、私ができることは実用的な例があると思います。 interp2
関数は双一次補間を適用し、bilinear
関数はアナログフィルタをデジタルフィルタとして記述する双線形変換を実行します。これはあなたが望むものではありません。
P.S.イメージワーピングを適用するときは逆変換を使用する必要があります(つまり、出力イメージの各ポイントの入力イメージでサンプリングするポイントを定義します)。順変換を実行すると(つまり、入力画像の各ポイントがマッピングする出力画像のポイントを定義すると)、出力画像にいくつかの重大なエイリアシングエフェクトや潜在的な穴が生じます。
これが役に立ちます。あなたに質問がある場合はお知らせください。
img = double(imread('rice.png'))/255;
theta = 30; % rotate 30 degrees
R = [cosd(theta) -sind(theta) 0; ...
sind(theta) cosd(theta) 0; ...
0 0 1];
sx = 15; % skew by 15 degrees in x
Skx = [1 tand(sx) 0; ...
0 1 0; ...
0 0 1];
% Translate by 1/2 size of image
tx = -size(img, 2)/2;
ty = -size(img, 1)/2;
T = [1 0 tx; ...
0 1 ty; ...
0 0 1];
% Scale image down by 1/2
sx = 0.5;
sy = 0.5;
S = [sx 0 0; ...
0 sy 0; ...
0 0 1];
% translate, scale, rotate, skew, then translate back
A = inv(T)*Skx*R*S*T;
% create meshgrid points
[x, y] = meshgrid(1:size(img,2), 1:size(img,1));
% reshape so we can apply matrix op
V = [reshape(x, 1, []); reshape(y, 1, []); ones(1, numel(x))];
Vq = inv(A)*V;
% probably not necessary for these transformations but project back to the z=1 plane
Vq(1,:) = Vq(1,:) ./ V(3,:);
Vq(2,:) = Vq(2,:) ./ V(3,:);
% reshape back into a meshgrid
xq = reshape(Vq(1,:), size(img));
yq = reshape(Vq(2,:), size(img));
% use interp2 to perform bilinear interpolation
imgnew = interp2(x, y, img, xq, yq);
% show the resulting image
imshow(imgnew);
双線形変換は、アナログからデジタル表現(ラプラスからz変換へ)から変換する方法です。私はあなたが 'interp2'を使用したいと思うでしょう – jodag
私は私の文脈に従ってそれの例をappriciateしたいと思います。 –
ここで、双一次補間は、変換された画像の穴埋めに使用されています。 –