Draw a gradient circle within a circle
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I want to code a gradient circle within a circle like shown in the diagram. Any help will be appreciated. 

채택된 답변
One way might be to use a patch with vertex interpolation, as in this example.
EDIT:
Here's how you might apply that to a circle:
t=linspace(0,360,500); t(end)=[];
x=cosd(t);
y=sind(t);
c=cosd(t);
patch(x,y,c); colormap(gray); axis equal; caxis([-0.7970 ,0.6373])

댓글 수: 15
I haven't found answer from the shared link
Matt J
2021년 6월 19일
You should see an example there with a gradient transition across triangles, similar to what you are trying to do with circles.

Scott MacKenzie
2021년 6월 19일
편집: Scott MacKenzie
2021년 6월 19일
@Matt J I tried -- without success -- to extend this example to circles. I think it's tricky because a circle doesn't have faces and vertices. When I tried to concoct a circle as a many-sided polygon, the color interpolation seemed to go a bit wonky:

@Scott MacKenzie See my edited answer
@Matt JWow, excellent. Thanks for this
Hi Matt, I want to add the gradient circle that you plotted inside the white circle in the following code. How can I do that?
% First create the image.
imageSizeX = 256;
imageSizeY = 256;
image=zeros(imageSizeX,imageSizeY);
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 128;
centerY = 128;
radius = 100;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
% Now, display it.
image(circlePixels)=256;
imshow(image, [])

Doing this with images is much easier than with plots...
gradientCircle=columnsInImage.*circlePixels;
gradientCircle(circlePixels)=rescale(gradientCircle(circlePixels),0,255);
imshow(gradientCircle, [])

I actually want an image of zeros of some height and width in which I have two circles, the outer circle should be white and inner most circle should have a gradient (0 to 255). See the first image that I had posted in a question. Thanks
Well, it's very easy to add a circle around the first.
halo=imdilate(circlePixels,strel('disk',10)) & ~circlePixels;
gradientCircle(halo)=255;
imshow(gradientCircle, []);shg

@Matt J Thanks for your reply. This function is really helpful but I want to code such that I could change the dimensions of image and inner circles. I want some like this shown image. How can I modify my above mentioned code to get something like this image? Thanks

Matt J
2021년 6월 19일
Well, the radius is a parameter you do control, isn't it? You set it to 100 in your original code, but you could easily change it to something else.
@Matt J yes I can control the radius of outer circle but how to control the radius of inner circle that you coded? Thank you!
Matt J
2021년 6월 20일
The inner circle is the one that you coded. The outer circle is coded by choosing the strel radius in strel('disk',10)
@Matt J Thank you so much. I appreciate your help!
Matt J
2021년 6월 20일
You're quite welcome, but please Accept-click the answer if you consider the question resolved.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
