How do I correct my colors in my indexed image displayed with image() function?
Show older comments
For this problem I needed to code an image that contains five different colors placed in different places in a 40 x 40. My code gets the image to print, but the colors are wrong. There are different colors, but they are all variations of purple. I am not sure what I am doing wrong and what I need to do to fix it. I tried retyping the code and redoing the figure, but it didn't help. I also tried to look up several solutions and nothing I came across helped. I tried with variable names, numbers, colormap, no colormap, and I am not sure how to fix it. Help would be greatly appreciated. Thank you in advance!
Guidelines:

My Figure:

My Code:
teal = [0.08,0.25,0.3];
black = [0,0,0];
red = [1,0,0];
darkred = [0.24,0.008,0.008];
% 1 == teal;
% 2 == black;
% 3 == red;
% 4 == darkred;
% myColors = [teal; black; red; darkred];
%
% colormap(myColors)
pixelPicture = ones(40,40);
pixelPicture(1:10,1:5) = 1;
pixelPicture(11:20,1:5) = 4;
pixelPicture(21:40,1:5) = 1;
pixelPicture(1:5,6:10) = 4;
pixelPicture(6:40,6:10) = 1;
pixelPicture(1:5,11:15) = 1;
pixelPicture(6:10,11:15) = 4;
pixelPicture(11:15,11:15) = 1;
pixelPicture(16:20,11:15) = 3;
pixelPicture(21:25,11:15) = 4;
pixelPicture(26:30,11:15) = 1;
pixelPicture(31:40,11:15) = 2;
pixelPicture(1:15,16:20) = 1;
pixelPicture(16:25,16:20) = 3;
pixelPicture(26:40,16:20) = 1;
pixelPicture(1:15,21:25) = 1;
pixelPicture(16:20,21:25) = 3;
pixelPicture(21:25,21:25) = 4;
pixelPicture(26:40,21:25) = 1;
pixelPicture(1:5,26:30) = 1;
pixelPicture(6:10,26:30) = 4;
pixelPicture(11:15,26:30) = 1;
pixelPicture(16:25,26:30) = 4;
pixelPicture(26:30,26:30) = 1;
pixelPicture(31:40,26:30) = 2;
pixelPicture(1:5,31:35) = 4;
pixelPicture(6:40,31:35) = 1;
pixelPicture(1:10,36:40) = 1;
pixelPicture(11:15,36:40) = 3;
pixelPicture(16:20,36:40) = 4;
pixelPicture(21:40,36:40) = 1;
figure(2);
image(pixelPicture)
Accepted Answer
More Answers (0)
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!