![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189988/image.png)
How to store a circle perimeter pixels in an array that is drawn over an binary image object?
2 次查看(过去 30 天)
显示 更早的评论
Zara Khan
2018-5-20
I have drawn two circles over an binary image object by taking radius=half of the mean major and minor axis and another one is 0.7*radius. Also have drawn its minor axis. Now I want to consider the upper portion of the minor axis and want to store perimeter pixels of those semi circles in individuals array. How to do that ?
1 个评论
采纳的回答
Image Analyst
2018-5-20
Take your arrays that you drew, x and y, and extract only those above the center y value
indexes = y < centerY; % Only those in the upper half.
xTop = x(indexes);
yTop = y(indexes);
18 个评论
Zara Khan
2018-5-21
编辑:Zara Khan
2018-5-21
Image Analyst : I have tried this code. But this is not the exact one I am asking for. I have attached an image and also have described how I have drawn circles. I only want to scan the circle perimeter that staring from intersection with the minor axis to the other intersection end.. For each of the circle I want to repeat the same process. Those perimeter pixels I want to store in individuals arrays .I am attaching two of my images here to clear the conception. img1 is my actual image. in img2 I have tried showing you from where I want to scan. I somehow have tried to highlight the portion by coloring them in yellow to make you understand.
Image Analyst
2018-5-21
You did not describe how you have drawn the circles. All you said was "I have drawn two circles over an binary image object", but you didn't say if you used plot() (which it looks like) or if you used viscircles(), which it doesn't look like.
Since it appears you used plot(), then you must already have x and y for the two circles. My code will work. Just attach the image you used (was it img1.png or one without the big white frame around it?) and a .mat file with your x and y coordinates and I'll show you that it will work.
Zara Khan
2018-5-21
编辑:Zara Khan
2018-5-21
a = imread('D:\data_set\P1_G5_4.png');
c=imcomplement(a);
L=logical(c);
s=regionprops(L,'Centroid','MajorAxisLength','MinorAxisLength','Orientation')
circleCenterX =s.Centroid(1);
circleCenterY =s.Centroid(2);
diameters = mean([s.MajorAxisLength s.MinorAxisLength],2);
r =diameters/2;
r1=0.7*diameters;
figure;
imshow(c);
hold on
t=0:0.1:2*pi;
%x_o and y_o = center of circle
x = circleCenterX + r*sin(t);
y = circleCenterY + r*cos(t);
plot(x,y,'r');
hold off
hold on
t=0:0.1:2*pi;
x1 = circleCenterX + r1*sin(t);
y1 = circleCenterY + r1*cos(t);
plot(x1,y1,'r');
hold off
hold off
t = linspace(0,2*pi,50);
hold on
a = s.MajorAxisLength/2;
b = s.MinorAxisLength/2;
Xc = s.Centroid(1);
Yc = s.Centroid(2);
phi = deg2rad(-s.Orientation);
x = Xc + a*cos(t)*cos(phi) - b*sin(t)*sin(phi);
y = Yc + a*cos(t)*sin(phi) + b*sin(t)*cos(phi);
xMinor=s.Centroid(1)+[-2,2]*(s.MinorAxisLength/2)*sind(s.Orientation);
yMinor=s.Centroid(2)+[-0,0]*(s.MinorAxisLength/2)*cosd(s.Orientation);
line(xMinor,yMinor);
hold off
Image Analyst
2018-5-21
You were not using the correct x for the circles. You were using the x of the elliptical fit of the hand. See this code:
a = imread('P1_G5_4.png');
c=imcomplement(a);
L=logical(c);
s=regionprops(L,'Centroid','MajorAxisLength','MinorAxisLength','Orientation')
circleCenterX =s.Centroid(1);
circleCenterY =s.Centroid(2);
diameters = mean([s.MajorAxisLength s.MinorAxisLength],2);
r =diameters/2;
r1=0.7*diameters;
subplot(1, 2, 1);
imshow(c);
hold on
t=0:0.1:2*pi;
%x_o and y_o = center of circle
x = circleCenterX + r * sin(t);
y = circleCenterY + r * cos(t);
plot(x,y,'r', 'LineWidth', 2);
t=0:0.1:2*pi;
x1 = circleCenterX + r1*sin(t);
y1 = circleCenterY + r1*cos(t);
plot(x1,y1,'m', 'LineWidth', 2);
axis('image', 'on');
t = linspace(0,2*pi,50);
a = s.MajorAxisLength/2;
b = s.MinorAxisLength/2;
% Xc = s.Centroid(1);
% Yc = s.Centroid(2);
% phi = deg2rad(-s.Orientation);
% x = Xc + a*cos(t)*cos(phi) - b*sin(t)*sin(phi);
% y = Yc + a*cos(t)*sin(phi) + b*sin(t)*cos(phi);
xMinor=s.Centroid(1)+[-2,2]*(s.MinorAxisLength/2)*sind(s.Orientation);
yMinor=s.Centroid(2)+[-0,0]*(s.MinorAxisLength/2)*cosd(s.Orientation);
line(xMinor, yMinor, 'LineWidth', 2);
plot(circleCenterX,circleCenterY,'r+', 'MarkerSize', 50, 'LineWidth', 2);
hold off
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
subplot(1, 2, 2);
imshow(c);
indexes = y < circleCenterY; % Only those in the upper half.
xTop = x(indexes);
yTop = y(indexes);
axis square;
hold on;
plot(xTop, yTop, 'r-', 'LineWidth', 2);
indexes = y1 < circleCenterY; % Only those in the upper half.
xTop1 = x1(indexes);
yTop1 = y1(indexes);
axis square;
hold on;
plot(xTop1, yTop1, 'm-', 'LineWidth', 2);
axis('image', 'on');
line(xMinor, yMinor, 'LineWidth', 2);
plot(circleCenterX,circleCenterY,'r+', 'MarkerSize', 50, 'LineWidth', 2);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/188829/image.png)
Zara Khan
2018-5-22
Image Analyst: Thank you.Problem has been resolved. you are the great.Now how can I store these two semi circles perimeter pixels to two individuals array?
Image Analyst
2018-5-22
You already have two arrays for x: xTop and xTop1, and two arrays for y: yTop and yTop1. Exactly what do you want?
Zara Khan
2018-6-30
编辑:Zara Khan
2018-6-30
whenever I am doing this I am getting a 32X3 matrix. why this is not coming as linear array? Intensity values should be stored in a linaer array ? where I am wrong. Please help me in identify this. My task is to store the half circle circumference intensity value to a matrix.
pix1=impixel(c,xTop,yTop);
pix2=impixel(c,xTop1,yTop1);
Image Analyst
2018-6-30
impixel() returns 3 values if the image is a color image, which is what you have. You're extracting 32 pixels from an RGB image.
Zara Khan
2018-7-1
编辑:Zara Khan
2018-7-1
ok. when I am plotting this pix1 using bar graph I am getting spitted graph and xticks also not properly created. So counting no of ticks not giving me the exact results. Here I am attaching the image. Basically I am trying to plot the half circles circumference intensity values from your right hand image where two half circles have been drawn.
Image Analyst
2018-7-1
I have no idea why you're plotting a colormap as a bar chart. That's gotta be a first. No idea why you're doing that or even using a colormap in the first place.
To get the values of the image under the circles, simply use a for loop
for k = 1 : length(xTop)
profile(k) = binaryImage(yTop(k), xTop(k));
end
plot(profile, 'b-', 'LineWidth', 2);
grid on;
Zara Khan
2018-7-2
yes now I am able to count no of peaks for each plot. But one problem I am facing that is I have taken 4 different radius:
diameters = mean([s.MajorAxisLength s.MinorAxisLength],2);
r1=diameters/2;
r2=0.7*diameters;
r3=0.8*diameters;
r4=0.9*diameters;
Now it is becoming very hard for me to handle many variables to draw these 4 circles then 4 half circles again storing these half circles circumferences intensity values to different variables. will it possible to do using loops where I am using different radius values?
Image Analyst
2018-7-2
Yes of course. Just have 4 variables. Or one variable that is a structure array.
Zara Khan
2018-7-2
Yes I have done that using 4 different variables then again have used some variables to draw 4 half circles then again taking 4 different loops for 4 different profiles ...this making the program lengthy and hard to handle ...how to do using loops ..can you please give me a some idea ?
Zara Khan
2018-7-3
Here indexes are always 1X63 for all the images. Hence the profiles are of 1X32 why? As there are two different half circle and there circumference lengths are also different still it is always coming 1X32 even for all the images in my folder this coming the same. Where is the problem in the above code?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)