필터 지우기
필터 지우기

Showing multiple images in one window in Matlab

조회 수: 3 (최근 30일)
Ba Ba Black Sheep!
Ba Ba Black Sheep! 2017년 7월 19일
댓글: Walter Roberson 2017년 7월 28일
Why doesn't the following code show the images?
clear all;
image_name = 'woman.png';
I = gray_imread(image_name);
N = 12;
J = zeros(size(I,1), size(I,2), N);
for i=1:N
J(:,:,i) = I;
end
sqrtt = ceil(sqrt(N));
m = sqrtt;
n = sqrtt;
for k=1:N
K = J(:,:,k);
subplot(m,n,k);
imshow(K);
set(gca,'xtick',[],'ytick',[])
end
How can I solve the issue?
  댓글 수: 2
KSSV
KSSV 2017년 7월 19일
편집: KSSV 2017년 7월 19일
What is size of I? What is this function gray_imread?? We cannot help you unless the function is known.
Ba Ba Black Sheep!
Ba Ba Black Sheep! 2017년 7월 28일
function img = gray_imread( image_name )
I = imread(image_name);
if(is_rgb(I))
img = rgb2gray(I);
elseif (is_gray(I))
img = I;
end
function ret = is_gray( yourImage )
[~, ~, numberOfColorChannels] = size(yourImage);
if(numberOfColorChannels == 1)
ret = 1;
else
ret = 0;
end
function ret = is_rgb( a )
if size(a,3)==3
ret = 1;
else
ret = 0;
end

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 28일
Change
J = zeros(size(I,1), size(I,2), N);
to
J = zeros(size(I,1), size(I,2), N, class(I));
  댓글 수: 2
Ba Ba Black Sheep!
Ba Ba Black Sheep! 2017년 7월 28일
what is the explanation?
Walter Roberson
Walter Roberson 2017년 7월 28일
You are accidentally converting uint8 values to double with the same integer values. However MATLAB looks at the data type to determine the expected range of values. For the integer data types like uint8 the smallest integer of the type is mapped to the first color in the color map and the highest valid integer for the type is mapped to the last color in the map. For the floating point types the rule is different: 0 is mapped to the first colour and 1 is mapped to the last colour. So where uint8(128) would map halfway between into the colour map, double(128) is way outside the expected 0 to 1 range and so would get mapped to the last colour. You end up with an image that is black where the original was exactly 0 and bright white everywhere else.
The change to the code that I showed does not initialize J as double (the default when you use zeros), and instead copies the data type such as uint8 from the original matrix to J so that the original and J will be treated the same way by the graphics engine.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by