MATLAB Answers

separating rgb values of an image

5 views (last 30 days)
Matpar
Matpar on 30 Aug 2019
Commented: Walter Roberson on 31 Aug 2019
Hi all
can someone tell me where i am going wrong?
I have my code, I want to separate the r g b values of the image! so for example if the image is 245x984x345
the r b g value will be separated such as it may have 100 red values 345 blue and the rest green.
when i try displaying the variables r g b separately the image are of various shades of gray!
i am not sure what is happening!
Please assist!
%Exercise 1
im = imread('scr.jpg');
whos im
r=im(:,:,1);
g=im(:,:,2);
b=im(:,:,3);
imshow(r);
figure;
imshow(r),title('Red values displayed');
figure;
imshow(g),title('Green values displayed');
figure;
imshow(b),title('Blue values displayed');
figure;
whos
%Exercise 2
g1=r+g+b/3;
imshow(g1),title('g1 Generic Average Formula');
figure;
%Exercise 3
g2=0.3*r+0.59*g+0.11*b/3;
imshow(g2),title('g2 Actual Average Formula');
figure;
subplot(2,2,1),imshow(im),title('original image');
subplot(2,2,2),imshow(r),title('red plane');
subplot(2,2,3),imshow(g),title('green plane');
subplot(2,2,4),imshow(b),title('blue plane');

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 30 Aug 2019
z = zeros(size(img));
r = z; r(:,:,1) = img(:,:,1);
g = z; g(:,:,2) = img(:,:,2);
b = z; b(:,:,3) = img(:,:,3);

  3 Comments

Matpar
Matpar on 30 Aug 2019
Oh hi walter,
thanks for responding!
Mind commenting so i can have the understanding of what is happening?
sorry for the inconvenience but i really want to get this!
thank loads really appreciate this budz !!
Matpar
Matpar on 30 Aug 2019
Sad faces WR,
it didn't work, i implemented it and disp() and imshow() after every line to see what was actually happening! i am not getting the image of red green blue, it displays a block of red green blue!
this should show the image of a scorpion in red green and blue, i should have three colours of a scorpion which is red green blue..
i am getting three rectangles of the colours rgb!
suggestions?
thanx in advance for responding!
Walter Roberson
Walter Roberson on 31 Aug 2019
Please attach the .jpg file.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by