It's not obvious, but you can use imwarp() instead of circshift. See this demo:
clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 20;
grayImage = imread('concordorthophoto.png');
[rows, columns, numberOfColorChannels] = size(grayImage);
subplot(1, 2, 1);
imshow(grayImage);
axis on;
title('Original Image', 'fontSize', fontSize);
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
deltaX = 500;
deltaY = 200;
D = zeros(rows, columns, 2);
D(:,:,1) = -deltaX;
D(:,:,2) = -deltaY;
warpedImage = imwarp(grayImage, D);
subplot(1, 2, 2);
imshow(warpedImage);
axis on;
title('Shifted Image', 'fontSize', fontSize);
So just mask the image in place (see attached demo script freehand_masking_demo.m), then do the shifting with imwarp().
Best Answer