This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Compare differences between images


obj = imshowpair(A,B)
obj = imshowpair(A,RA,B,RB)
obj = imshowpair(___,method)
obj = imshowpair(___,Name,Value)



obj = imshowpair(A,B) creates a visualization of the differences between images A and B. If A and B are different sizes, imshowpair pads the smaller dimensions with zeros on the bottom and right edges so that the two images are the same size. imshowpair returns obj, an image object.


obj = imshowpair(A,RA,B,RB) displays the differences between images A and B, using the spatial referencing information provided in RA and RB. RA and RB are spatial referencing objects.


obj = imshowpair(___,method) uses the visualization method specified by method.


obj = imshowpair(___,Name,Value) specifies additional options with one or more Name,Value pair arguments, using any of the previous syntaxes.


collapse all

Display a pair of grayscale images with two different visualization methods, 'diff' and 'blend'.

Load an image into the workspace. Create a copy with a rotation offset applied.

A = imread('cameraman.tif');
B = imrotate(A,5,'bicubic','crop');

Display the difference of A and B.


Display a blended overlay of A and B.


Read an image. Create a copy and apply rotation and a brightness adjustment.

A = dicomread('CT-MONO2-16-ankle.dcm');
B = imrotate(A,10,'bicubic','crop');
B = B * 0.2;

In this example, we know that the resolution of images A and B is 0.2mm. Provide this information using two spatial referencing objects.

RA = imref2d(size(A),0.2,0.2);
RB = imref2d(size(B),0.2,0.2);

Display the images with the default method ('falsecolor') and apply brightness scaling independently to each image. Specify the axes that will be the parent of the image object created by imshowpair.

hAx = axes;

Input Arguments

collapse all

Image to be displayed, specified as a grayscale, truecolor, or binary image.

Image to be displayed, specified as a grayscale, truecolor, or binary image.

Spatial referencing information about an input image, specified as spatial referencing object, of class imref2d.

Spatial referencing information about an input image, specified as spatial referencing object, of class imref2d.

Visualization method to display combined images, specified as one of the following values.

'falsecolor'Creates a composite RGB image showing A and B overlaid in different color bands. Gray regions in the composite image show where the two images have the same intensities. Magenta and green regions show where the intensities are different. This is the default method.
'blend'Overlays A and B using alpha blending.
'checkerboard'Creates an image with alternating rectangular regions from A and B.
'diff'Creates a difference image from A and B.
'montage'Places A and B next to each other in the same image.

Example: imshowpair(A,B,'montage') displays A and B next to each other.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Scaling','joint' scales the intensity values of A and B together as a single data set.

collapse all

Output color channel for each input image, specified as one of the following values:

[R G B]A three element vector that specifies which image to assign to the red, green, and blue channels. The R, G, and B values must be 1 (for the first input image), 2 (for the second input image), and 0 (for neither image).
'red-cyan'A shortcut for the vector [1 2 2], which is suitable for red/cyan stereo anaglyphs.
'green-magenta'A shortcut for the vector [2 1 2], which is a high contrast option, ideal for people with many kinds of color blindness.

Parent of image object created by imshowpair, specified as an axes object.

Intensity scaling option, specified as one of the following values:

'independent'Scales the intensity values of A and B independently from each other.
'joint'Scales the intensity values in the images jointly as if they were together in the same image. This option is useful when you want to visualize registrations of monomodal images, where one image contains fill values that are outside the dynamic range of the other image.
'none'No additional scaling.

Output Arguments

collapse all

Visualization of two images, returned as an image object.


  • Use imfuse to create composite visualizations that you can save to a file. Use imshowpair to display composite visualizations to the screen.

Introduced in R2012a

Was this topic helpful?