what is the difference between these two types of rgb matlab code ?

조회 수: 1 (최근 30일)
i have a 3D color image , when i use a matlab code as below
x=imread('....');
R=x(:,:,1); % red
G=I(:,:,2); % green
B=I(:,:,3); %blue
figure, imshow (R);
it display grayscale image. and if i use the code given below
% Red channel only
im=imread('....');
im_red = im;
im_green = im;
im_blue = im;
im_red(:,:,2) = 0;
im_red(:,:,3) = 0;
figure, imshow(im_red);
it display red color image.
i need help in undestanding difference between these codes ?

채택된 답변

Ken Atwell
Ken Atwell 2014년 11월 18일
In the first case, R is not a 3-D image, but a 2-D image, which MATLAB will display as grayscale. You created R as 2-D when you indexed in the red-only portion of the images in your statement:
>> R=x(:,:,1); % red
In the second case, im_red is a 3-D image, It begins as identical to 'im', but then you set both the green and blue planes to zeros with:
>> im_red(:,:,2) = 0;
>> im_red(:,:,3) = 0;
Look at the dimensions of your matrices in the Variable window as you execute these command one-by-one, and I believe you will be able to follow along with what is happening.
  댓글 수: 1
namita chandrakar
namita chandrakar 2014년 11월 22일
Quite nice explanation, now it's clear for me. Thanks for your time and answer.

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

추가 답변 (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