Draw multiple circles in one image
显示 更早的评论
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?
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
"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
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.
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)
