I am trying to use imfreehand(...) to replace a selected region in one image with the corresponding region in another image.
This is my code so far:
% Sample images:
I1=imread('office_1.jpg');
I2=imread('office_5.jpg');
imshow(I1)
h = imfreehand;
wait(h);
pixels = getPosition(h);
x = pixels(:,1);
y = pixels(:,2);
for i = 1:numel(x)
I1(y(i), x(i), :) = I2(y(i), x(i), :);
end
imshow(I1)
However, I get the error that: "index must be a positive integer or logical." In this case, I am not sure why this error arises and how to correct it.
Any explanation would be greatly appreciated.