Images appear black and white instead of coloured

조회 수: 6 (최근 30일)
Jason
Jason 2015년 2월 20일
편집: Jason 2015년 2월 23일
I plot a montage of images onto a UIPanel and it worked fine when the images were tiffs. My images are now jpgs and I notice that the coloured images now appear black and white. I can't see why this would be the case. Here is my code
This is in a loop for all images.
hp = handles.uipanelM;
h=subplot('Position',positionVector,'Parent',hp); %to enable deleting use handles
colormap (jet);
% update handle array
hSubplots = [hSubplots ; h]; %Concatenate
axis off;
hold off;
%Create thumbnail sized image
IM1=imresize(IM, 0.05);
allImgs{y1,x1} = IM1 ;
imagesc(Image,[mlo mhi])
colormap (jet);
axis off;
set(gca,'ytick',[]);
set(gca,'xtick',[]);
drawnow;
  댓글 수: 4
Adam
Adam 2015년 2월 20일
hp is a panel handle, it needs to be either a figure handle or an axes handle.
Jason
Jason 2015년 2월 20일
OK, but I am plotting onto the panel handle. The only other handle I use is:
h=subplot('Position',positionVector,'Parent',hp)
Im not convinced this is the issue, as it works with 12 bit tiffs, but not with 8 bit jpgs.

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

채택된 답변

Image Analyst
Image Analyst 2015년 2월 20일
편집: Image Analyst 2015년 2월 21일
JPG images are usually color, even if they appear as gray scale - it's just that all the color channels are the same. Try:
imshow(IM1, []); % Display color image
Or extract one of the color channels:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
imshow(redChannel, []); % Display one monochrome color channel
colormap(jet(256));
Or convert to grayscale if the color channels are NOT all identical:
grayImage = rgb2gray(IM1);
imshow(grayImage); % Display converted image.
colormap(jet(256));
colorbar;
  댓글 수: 7
Image Analyst
Image Analyst 2015년 2월 21일
Jason: That won't do it. First of all, Image was not even defined in your code. You should use the red channel of IM or IM1. Second, Image is a bad name since image() is the name of a built in function. I know MATLAB is case sensitive, but nonetheless it's not a wise idea to use variables with the same names as the built in functions, even if the case of some of the letters is different.
Jason
Jason 2015년 2월 23일
편집: Jason 2015년 2월 23일
Hi IA. I actually put Image(:,:,1) in a function that I pass IM1 to.
function Im_Scale(handles,Image,mlo, mhi,ext)
size(Image, 3) %If 3 then RGB, if not then grayscale
if ext=='.jpg'
imagesc(Image(:,:,1),[mlo mhi])
else
imagesc(Image,[mlo mhi])
end
colormap (jet);
axis off;
set(gca,'ytick',[]);
set(gca,'xtick',[]);
drawnow;
end
I will take your advice regarding the name Image. As I correct though to use the index 1 as representing the red channel?
Thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by