Weird imshow image. same pixel value different color

3 次查看(过去 30 天)
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)

采纳的回答

Doug Eastman
Doug Eastman 2011-6-27
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');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by