MATLAB quesiton Write a function rgb colorm to display color

MATLAB quesiton:

Write a function rgb color.m to display color (red, green, blue, yellow, magenta, cyan, white) as a result of mixing primary colors (red, green, blue) . The function should have the following declaration: function color = rgb color(rgb) where the input rgb is a 3-element vector having value of either 0 or 1 to denote the three primary colors (red, green, blue) respectively. The output color is a string denoting the color of the mixture. See http://en.wikipedia.org/wiki/Additive_color for information on how colors are mixed. For example, when rgb = [1 0 0], the resulting color is red. When rgb = [1 1 1], the resulting color is white. If the input rgb is not a valid input, the output color should be the string \'Invalid input\'. Remember to give the function a description. Use nested if statements

Solution

img = imread(\'filename.png\'); % Read image
red = img(:,:,1); % Red channel
green = img(:,:,2); % Green channel
blue = img(:,:,3); % Blue channel
a = zeros(size(img, 1), size(img, 2));
just_red = cat(3, red, a, a);
just_green = cat(3, a, green, a);
just_blue = cat(3, a, a, blue);
back_to_original_img = cat(3, red, green, blue);
figure, imshow(img), title(\'Original image\')
figure, imshow(just_red), title(\'Red channel\')
figure, imshow(just_green), title(\'Green channel\')
figure, imshow(just_blue), title(\'Blue channel\')
figure, imshow(back_to_original_img), title(\'Back to original image\')

MATLAB quesiton: Write a function rgb color.m to display color (red, green, blue, yellow, magenta, cyan, white) as a result of mixing primary colors (red, green

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site