필터 지우기
필터 지우기

color image can be divided into individual color channels. if i give a gray input to the same program what will be the output??

조회 수: 1 (최근 30일)
a=imread(a.jpg)
R=a(:,:,1)
G=a(:,:,2)
B=a(:,:,3)
%if a= a gray image what will happen??

답변 (1개)

Walter Roberson
Walter Roberson 2016년 10월 18일
Grayscale .jpg images are quite uncommon -- I think I have only ever encountered one, myself.
The result of reading in a grayscale .jpg image would be an array in which the third dimension was only depth 1. Accessing a(:,:,2) would then generate an error because at most a(:,:,1) would exist.
There are also .jpg images which are color images but which visually look grey. If they are true grey images, then they would be RGB images in which all of the color channels would be equal, so isequal(R,G) would be true and isequal(R,B) would also be true.
  댓글 수: 2
anna ann
anna ann 2016년 10월 18일
편집: Walter Roberson 2016년 10월 18일
ok if a true gray image is used in this case what will be the output?is it error or r,g,b with equal values??
actually i want a single algorithm able to process both color image and gray scale image. so separating into rgb channels and analysing its values, can algorithm distinguish color and gray images??
Walter Roberson
Walter Roberson 2016년 10월 18일
tempimg = imread('cameraman.tif');
tfile = tempname;
filename_gs = [tfile, 'gs.jpg'];
imwrite(tempimg, filename_gs, 'mode', 'lossless');
filename_rgb = [tfile, 'rgb.jpg'];
tempimg_rgb = tempimg(:,:,[1 1 1]);
imwrite(tempimg_rgb, filename_rgb, 'mode', 'lossless');
subplot(1,2,1)
img_gs = imread(filename_gs);
imshow(img_gs);
title('grayscale 2D image');
disp('image size for 2D grayscale image is')
disp(size(img_gs))
disp('number of dimensions for 2D grayscale image is')
disp(ndims(img_gs))
try
r_gs = img_gs(:,:,1);
g_gs = img_gs(:,:,2);
b_gs = img_gs(:,:,3);
disp('We WERE able to extract three planes from 2D grayscale image')
catch
disp('We were NOT able to extract three planes from 2D grayscale image')
end
subplot(1,2,2)
img_rgb = imread(filename_rgb);
imshow(img_rgb);
title('rgb image that happens to be gray')
disp('image size for RGB image that happens to be gray is')
disp(size(img_rgb))
disp('number of dimensions for RGB image that happens to be gray is')
disp(ndims(img_rgb))
try
r_rgb = img_rgb(:,:,1);
g_rgb = img_rgb(:,:,2);
b_rgb = img_rgb(:,:,3);
disp('We WERE able to extract three planes from RGB image that happens to be gray')
catch
disp('We were NOT able to extract three planes from RGB image that happens to be gray')
end

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

카테고리

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