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

 採用された回答

KSSV
KSSV 2022 年 7 月 27 日
編集済み: KSSV 2022 年 7 月 27 日

0 投票

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 件のコメント

Latifa Bouguessaa
Latifa Bouguessaa 2022 年 7 月 27 日
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
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.

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',[]);
Walter Roberson
Walter Roberson 2022 年 7 月 30 日
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
Latifa Bouguessaa
Latifa Bouguessaa 2022 年 7 月 31 日
Hello Walter Roberson, thanks for your help. this is exactly what i need
Latifa Bouguessaa
Latifa Bouguessaa 2022 年 8 月 12 日
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
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.
Latifa Bouguessaa
Latifa Bouguessaa 2022 年 8 月 12 日
Thank you for your help Image Analyst
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
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
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by