![](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 (한국어)