Draw multiple circles in one image
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello, everyone,
I need your help. I wanted to draw several circles in one picture and edit them later. Attached is a screen shot. thank you for your help
Latifa
채택된 답변
R = 2:2:10 ;
th = linspace(0,2*pi) ;
figure
hold on
for i = 1:length(R)
x = R(i)*cos(th) ;
y = R(i)*sin(th) ;
plot(x,y)
end
axis equal

댓글 수: 9
thanks sir for your help
how can I cut off the individual circles from the image for further processing? is there a function for this?
Latifa Bouguessaa
2022년 7월 27일
편집: Walter Roberson
2022년 7월 30일
i tried again but without success
here is my code:
image = imread('cameraman.tif');
figure(1)
imshow(image,'DisplayRange',[]);
xc=128;
yc=128;
theta=linspace(0,2*pi);
c0=1;
r=[10,20,30,40,50];
for i = 1:length(r)
x = r(i)*cosd(theta) + xc;
y = r(i)* sind(theta) + yc;
pos = [x, y];
viscircles([x(i),y(i)],1,'LineStyle','-','LineWidth',1);
%viscircles('Position', pos, 'EdgeColor', 'g', 'LineWidth', 1)
axis square;
grid on;
subimage(:,:,co) = imcrop(image, pos);
co=co+1;
end

Error using images.internal.crop.parseInputsOverTwo>validateRectangle
Input number 2, RECT, is expected to contain 4 elements.
Input number 2, RECT, is expected to contain 4 elements.
Error in images.internal.crop.parseInputsOverTwo (line 54)
validateRectangle(spatial_rect,2);
Error in imcrop (line 104)
images.internal.crop.parseInputsOverTwo(varargin{:});
figure(2)
imshow(subimage,'DisplayRange',[]);
img = imread('cameraman.tif');
figure(1)
imshow(img, 'DisplayRange', []);

[r, c, p] = size(img);
xc = 128;
yc = 128;
r=[10,20,30,40,50];
for i = 1:length(r)
ROI = images.roi.Circle('Center', [xc, yc], 'Radius', r(i));
mask = cast(repmat(createMask(ROI, img), [1, 1, p]), class(img));
masked_img = img .* mask;
subimage{i} = imcrop(masked_img, [xc-r(i), yc-r(i), 2*r(i)+1, 2*r(i)+1]);
end
for i = 1 : length(r)
figure
imshow(subimage{i}); title(string(r(i)));
end





Hello everyone.
thank you all for your help.
I still have a few questions though.
how can I call up and edit the individual ROIs from subimage{i}?
next task is to calculate the FFT of each ROI. How can I only edit the values inside the circle.
I thank you in advance
Image Analyst
2022년 8월 12일
"how can I call up and edit the individual ROIs from subimage{i}?" <= you already have subimage{i}, so it's already "called up". To edit it, you assign values to certain rows and columns of it.
"next task is to calculate the FFT of each ROI." <= call ftImage = fft2(subimage{i}); The fft will apply to the entire rectangular image including the black masked off portions.
"How can I only edit the values inside the circle." <= I already told you how to edit the image. Just give row and column values inside the circle and reassign those intensity values.
I tried to solve the task like this, but it doesn't work, I don't know what the problem is. Here is my code:
for i=1:length(r)
mm = mean(mean(subimage{i}(subimage{i}~=0)));
subimage{i}=(subimage{i}(subimage{i}~=0))-mm;
spe{i}= (abs(fftn(subimage{i}))).^2;
%pixel spacing
Deltax=Spasi(1);
Deltay=Spasi(2);
f=(Deltax*Deltay)/size(subimage{i},1).^2;
w4{i}=mean(spe{1,i});
nps{i}=f*w4{i};
nps{i}=nps{1,i}/sum(nps{i});
spaki=Spasi(1,1);
[q g]=size(nps{i});
%Frequency
frequency=(1/((r(i)+1)*2*spaki));
sumbu=0:frequency:(((g-1)*frequency));
hold on
figure(5)
subplot(3,2,i)
hold on;
plot(sumbu, nps{i}, 'o--')
xlabel('Spatial Frquency ?mm?^-1')
ylabel('NPS)
set(gcf, 'color', 'w')
end
Image Analyst
2022년 8월 12일
I have no idea what you want to do. All professional programmers put comments into their code. Where are yours? Explain every section or line of your code up until the plotting part.
Walter Roberson
2022년 8월 12일
You cannot reliably recreate the roi given just the subimage and comparing it to 0, as interior pixels could be 0.
You could, it is true, take the subimage and fit a circle to it to recreate the roi.
But if you are going to need the roi later, just record the mask variables as well, it saves a lot of trouble.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
참고 항목
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)
