How can I make gray or black color in circle?

조회 수: 7 (최근 30일)
Haksun Lee
Haksun Lee 2014년 7월 4일
댓글: Image Analyst 2014년 7월 4일
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');

답변 (1개)

Image Analyst
Image Analyst 2014년 7월 4일
Add this code to the end of yours:
numberOfGrayLevels = 256; % from 1 to 256.
colormap(gray(numberOfGrayLevels));
colorbar;
  댓글 수: 2
Image Analyst
Image Analyst 2014년 7월 4일
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 2014년 7월 4일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by