How can I make gray or black color in circle?

7 Ansichten (letzte 30 Tage)
Haksun Lee
Haksun Lee am 4 Jul. 2014
Kommentiert: Image Analyst am 4 Jul. 2014
As the following source, I made ring including some colors..
But I can't get black or gray color.
How can I make gray or black color in circle?
By which data can color affected?
%# define the ring
phi = linspace(0,2*pi,360);
innerRim = [cos(phi)',sin(phi)'];
outerRim = [cos(phi)',sin(phi)']*1.1;
xRing = [outerRim(:,1),innerRim(:,1),innerRim([2:end,1],1),outerRim([2:end,1],1)]';
yRing = [outerRim(:,2),innerRim(:,2),innerRim([2:end,1],2),outerRim([2:end,2],2)]';
%# create some data. 0 for black 0.5 for gray.
%# RingData has a value for each degree
ringData = ones(1,360);
ringData(1:40) =0.9;
ringData(40:80) = 0.8;
ringData(80:120) =0.7;
ringData(120:160) = 0.6;
ringData(160:200) = 0.4;
ringData(200:240) = 0.3;
ringData(240:280) = 0.2;
ringData(280:320) = 0.1;
ringData(320:360) = 0;
%# plot the ring
%# for an outer ring, add 1 to xRing, yRing
figure
patch(xRing,yRing,ringData, 'Edgecolor','none');
set(gca,'cLim',[0 1]);
axis square
axis off
set(gcf,'color','w');

Antworten (1)

Image Analyst
Image Analyst am 4 Jul. 2014
Add this code to the end of yours:
numberOfGrayLevels = 256; % from 1 to 256.
colormap(gray(numberOfGrayLevels));
colorbar;
  2 Kommentare
Image Analyst
Image Analyst am 4 Jul. 2014
Haksun's "Answer" moved here since it's a reply to me rather than an answer to the original question.
Thank you for your reply.
And, could I get another color including RGB?
For example I'd like to get [3 17 34] colored dark blue in circle.
Again I really appreciate your concern.
Image Analyst
Image Analyst am 4 Jul. 2014
Yes, you can make up a custom colormap. For example you can say
colorMap = gray(256);
and if you want values of 30 to be [3 17 34] , just do
colorMap(31,:) = [3 17 34];
See caxis() to see how you can assign specific values of your data to row 1 and row 256 of your colormap.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by