Weird imshow image. same pixel value different color

조회 수: 2 (최근 30일)
Kyle
Kyle 2011년 6월 25일
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
Jan
Jan 2011년 6월 26일
The question is not clear to me. Why do you think that something went wrong?

댓글을 달려면 로그인하십시오.

채택된 답변

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