Imshowpair showing only green channel

11 views (last 30 days)
% Imshowpair output shows only the green channel of the RGB image in both the cases, for the
% code below, the input image is RGB. What should I do?
% PS: Its a code for a simple translation of the image 1
clear, clc,close all;
img = imread('image1.jpg');
I = imresize(img,[512 512]);
ref = imref2d(size(I));
background = zeros(700);
axis on;
function my_translation(I,x,y,background)
tform = affine2d([1 0 0; 0 1 0; x y 1]);
r = imref2d(size(I));
[out,out_ref] = imwarp(I,r,tform);
axis on;

Accepted Answer

Walter Roberson
Walter Roberson on 21 Mar 2021
This is exactly what is expected for that set of commands.
imshowpair(...,METHOD) displays the differences between images A and B
using the visualization style specified by METHOD. Values of METHOD
can be:
'falsecolor' : Create a composite RGB image showing A and B overlayed
in different color bands. This is the default.
Parameters include:
'ColorChannels' Assign each image to specific color channels in the
output image. This method can only be used with the
'falsecolor' method.
Valid 'ColorChannels' values are:
[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.
Default value: 'green-magenta'
You did not specify an explicit method, so you get 'falsecolor'. You did not specify 'ColorChannels' so you get the default green-magenta.
The default [2 1 2] vector for green-mageneta means that the first channel (red) is to be taken from image #2, that the second channel (green) is to be taken from image #1, and that the third channel (blue) is to be taken from image #2. Your image #2 is all zeros, so you red and blue channels are to be set to all 0. Your green channel is extracted from the green channel of image #1. Overall result: you see the green channel of the original image. Exactly what the code asks for.
When you use an all-zero second image like you did, it does not make much sense to use anything other than facecolor with selected color channels like you are doing. The only other setting that might make sense is checkerboard, if you wanted to show like a mosaic.
img = imread('flamingos.jpg');
imshowpair(img, 0, 'checkerboard');
Subhransu Sekhar Bhattacharjee
Oh yes I was just reading about how to deal with handle of an image, thank you so much for this.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!