Imshowpair showing only green channel

6 Ansichten (letzte 30 Tage)
Subhransu Sekhar Bhattacharjee
% 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);
imshowpair(I,ref,background,imref2d(size(background)))
axis on;
my_translation(I,100,-100,background)
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);
figure,imshowpair(out,out_ref,background,imref2d(size(background)))
axis on;
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 21 Mär. 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');
  7 Kommentare
Walter Roberson
Walter Roberson am 22 Mär. 2021
Your my_translation is returning the handle to the image() object created by the imshow() call in my_translation. You cannot then imshow() the handle to the image()
img = imread('foosball.jpg');
I = imresize(img,[512 512]);
fig1 = figure;
ax1 = axes(fig1);
J = imshow(I, 'Parent', ax1);
axis(ax1, 'on');
fig2 = figure;
ax2 = axes(fig2);
my_translation(ax2, J,100,-100);
axis(ax2, 'on')
function output = my_translation(ax,h,x,y)
xrange = h.XData;
yrange = h.YData;
xrangeNew = xrange + x;
yrangeNew = yrange + y;
cmap = colormap(ancestor(h,'axes'));
output = image('Parent', ax, 'CData', h.CData, 'XData', xrangeNew, 'YData', yrangeNew);
colormap(ax, cmap);
axis(ax, 'on')
ax.YDir = 'reverse';
end
Subhransu Sekhar Bhattacharjee
Oh yes I was just reading about how to deal with handle of an image, thank you so much for this.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing and Computer Vision finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by