Reputation: 649
Lets say I have a matrix A
A = [1 1 1 1 1 1 1;
1 0 0 1 0 0 1;
1 0 0 0 0 1 1;
1 0 1 0 1 0 0;
1 0 0 0 0 0 1;
1 1 1 1 1 1 1];
And I want to give the 1's at the edges a specific color, and the 1's that are not at the boundaries a specific color and the 0's a specific color, How do I go about this?
Currently I just have imagesc(A)
, I have been reading up on colormap
and I do not understand it. To me it seems they just have set color scheme. On the website I see winter
, summer
, hot
, jet
etc. I would like to know how to modify, and how and where colors are displayed, and what colors are to be displayed.
Upvotes: 0
Views: 134
Reputation: 927
Colormap in matlab allows you to set a color for an indexed image (in your case you only have 2 indexes - 0,1 which is usually interperted as black and white).
MATLAB has some predefine settings as you mentioned winter
,summer
, hot
, jet
etc.
You can define your own colormaps.In order to do that you need to first build a matrix of nX3 where n is the number of colors you need and the 3 is attributed to the RGB color space.
In your example above
imagesc(A)
Gives a blue and yellow image (since the default is parula
).
If you define the new colormap matrix as follows
Cmap = [1 1 1; 0 0 0];
colormap(Cmap);
You will get the image in black and white (because of the values in Cmap). You can change the Cmap
matrix values for different colors.
Upvotes: 3