You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to store a circle perimeter pixels in an array that is drawn over an binary image object?
1 view (last 30 days)
Show older comments
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 Comment
Accepted Answer
Image Analyst
on 20 May 2018
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 Comments
Zara Khan
on 21 May 2018
Edited: Zara Khan
on 21 May 2018
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
on 21 May 2018
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
on 21 May 2018
Edited: Zara Khan
on 21 May 2018
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
on 21 May 2018
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);
Zara Khan
on 22 May 2018
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
on 22 May 2018
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
on 30 Jun 2018
Edited: Zara Khan
on 30 Jun 2018
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
on 30 Jun 2018
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
on 1 Jul 2018
Edited: Zara Khan
on 1 Jul 2018
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
on 1 Jul 2018
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
on 2 Jul 2018
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
on 2 Jul 2018
Yes of course. Just have 4 variables. Or one variable that is a structure array.
Zara Khan
on 2 Jul 2018
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
on 3 Jul 2018
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?
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)