Display image using RGB values
Show older comments
I have a 45x45 matrix. It has values 0 to 1. I want to assign R,G,B values to each value. Like 0=(0,0,255) and 1=(255,0,0) and the middle values will be accordingly.
And then I want to display the image using those R,G,B values. I am new to matlab so I need some help.
1 Comment
Raymond MacNeil
on 3 Jan 2020
Edited: Raymond MacNeil
on 3 Jan 2020
Hi Sheetal:
Red, Green, and Blue channels are read from the first, second, and third 'pages' of a matrix, respectively. Thus, at the very least, you need an M * N * 3 matrix. You can include a fourth 'page' if you want your image to contain an alpha channel.
Here is an example of simple square-wave grating that alternates between red and blue bars. This should get the main idea across:
mata = 255*ones(100,10);
matb = zeros(100,10);
red = cat(3, mata, matb, matb);
blue = cat(3, matb, matb, mata);
rb_sqwv = repmat([red, blue], 5);
img = imshow(rb_sqwv)
Cheers,
Ray
Answers (0)
Categories
Find more on Image Category Classification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!