Weird imshow image. same pixel value different color

2 Ansichten (letzte 30 Tage)
Kyle
Kyle am 25 Jun. 2011
Hi,
I have some problem in displaying images with the following code. The output image should be image of Image A overlap image B. However the image become totally white after combine. When i use Imtool to check on the pixel value on A and C, i notice same pixel value shows different color.
Any1 knows what when wrong?
clc
% A = reshape(1:15,3,5)
% B = reshape(1:35,5,7)+12
A = imread('cameraman.tif');
B = imread('cameraman.tif');
% NA = 8; % The number to overlap in A.
% NB = 32; % The number to overlap in B.
[mA,nA] = size(A);
[mB,nB] = size(B);
% [IA,JA] = find(A==NA);
% [IB,JB] = find(B==NB);
IA=50;
JA=50;
IB=1;
JB=1;
mC = mA+mB+mod(mA+mB,2)+1;
nC = nA+nB+mod(nA+nB,2)+1;
C = zeros(mC,nC);
cC = round([mC/2,nC/2]);
C(cC(1)-IB+1:cC(1)-IB+mB,cC(2)-JB+1:cC(2)-JB+nB) = B;
C(cC(1)-IA+1:cC(1)-IA+mA,cC(2)-JA+1:cC(2)-JA+nA) = A;
C = C(:,any(logical(C)));
C = C(any(logical(C),2),:);
imshow(C)
  1 Kommentar
Jan
Jan am 26 Jun. 2011
The question is not clear to me. Why do you think that something went wrong?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Doug Eastman
Doug Eastman am 27 Jun. 2011
C is double so the default range for imshow is between 0 and 1, but your values are between 0 and 255. You can either specify the display range in imshow (see IMSHOW), cast C to uint8, or, even better, change the line that you use to create C to:
C = zeros(mC,nC,'uint8');

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox 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