MATLAB: Zoom in on two images simultaneously displayed using imshowpair

image processingImage Processing ToolboximshowpairMATLABzoom

I have two images of the same dimensions. I'm using the code below to display them side by side.
imshowpair(imageA, imageB, "montage")
Currently if I zoom into an area of imageA in the figure ouput, it zooms solely into this area, treating the two images as one image. I want to be able to zoom into an area in imageA, and for the display to also zoom into the corresponding area of imageB at the same time, so I can compare the same areas of both images when zooming in.
Can I do this using imshowpair, the tools in the figure output, or some other way?
Thanks for the help!

Best Answer

> If I zoom into an area of imageA in the figure ouput, it zooms solely into this area, treating the two images as one image
That's because the two images are merged into one image on the same axes.
To achieve a dual display with independent axis tools, you need to plot the images in different axes. Then use linkaxes to yoke the axis limits when zooming/panning.
% Read in demo image
img = imread('cameraman.tif');
fig = figure();
ax(1) = axes('Units','normalized','Position', [ .1 .1 .4 .8]);
ax(2) = axes('Units','normalized','Position', [ .5 .1 .4 .8]);
imshow(img, 'Parent', ax(1))
imshow(img, 'Parent', ax(2))
linkaxes(ax)