ダブルマトリックスに変換した画像があります。横にずらしたいのですが、どうしたらいいのかわかりません。位置を操作しようとしていますが、色を操作しているだけであることがわかりました。
代わりにピクセル位置を参照し、定数を追加してシフトを実行する方法はありますか?
Image Processing Toolbox を使用して、空間変換を適用できます。
img = imread('pout.tif');
T = maketform('affine', [1 0 0; 0 1 0; 50 100 1]); %# represents translation
img2 = imtransform(img, T, ...
'XData',[1 size(img,2)], 'YData',[1 size(img,1)]);
subplot(121), imshow(img), axis on
subplot(122), imshow(img2), axis on
circshift
循環シフトを実行するために使用できますim = circshift(im, [vShift hShift])
。
画像が行列 A で、x 列を左に折り返すとします。
A = [A(x+1:end,:) A(1:x,:)];
ツールボックスがなくてもサブピクセル シフトを実行したい場合は、この関数を使用できます。x と y でシフトされた単一のピクセルであるフィルターを作成し、そのフィルターを画像に適用します。
function [IM] = shiftIM(IM,shift)
S = max(ceil(abs(shift(:))));
S=S*2+3;
filt = zeros(S);
shift = shift + (S+1)/2;
filt(floor(shift(1)),floor(shift(2)))=(1-rem(shift(1),1))*(1-rem(shift(2),1));
filt(floor(shift(1))+1,floor(shift(2)))=rem(shift(1),1)*(1-rem(shift(2),1));
filt(floor(shift(1)),floor(shift(2))+1)=(1-rem(shift(1),1))*rem(shift(2),1);
filt(floor(shift(1))+1,floor(shift(2)+1))=rem(shift(1),1)*rem(shift(2),1);
IM=conv2(IM, filt, 'same');
end
%to test
IM = imread('peppers.png');IM = mean(double(IM),3);
for ct = 0:0.2:10
imagesc(shiftIM(IM,[ct/3,ct]))
pause(0.2)
end
%it should shift to the right in x and y