I have a code where I read in two images and display it side-by-side. I draw a region of interest within the first image, and the region is automatically shown on the second image. When I move the rectangle to another region within the first image, only that rectangle moves (not the second image's rectangle). How can I fix this so that when I move the first rectangle, the second move moves to the same position as well.
What I have now
% Read images
I = imread('cameraman.tif');I2 = imread('cameraman.tif');% plot image 1 & draw a rectangular ROI on images
subplot(1,2,1); imshow(I);roi = drawrectangle('LineWidth',2,'Color','white');subplot(1,2,2); imshow(I2);roi2 = drawrectangle(gca,'Position',roi.Position);% set up listeners for ROI moving events
addlistener(roi,'MovingROI',@allevents);addlistener(roi,'ROIMoved',@allevents);% allevents callback function displays the previous position & the current position of the ROI
function allevents(~,evt) evname = evt.EventName; switch(evname) case{'MovingROI'} disp(['ROI moving previous position: ' mat2str(evt.PreviousPosition)]); disp(['ROI moving current position: ' mat2str(evt.CurrentPosition)]); case{'ROIMoved'} disp(['ROI moved previous position: ' mat2str(evt.PreviousPosition)]); disp(['ROI moved current position: ' mat2str(evt.CurrentPosition)]); endend
Best Answer