필터 지우기
필터 지우기

How to output centroid coordinate from switch case wihtin loop case

조회 수: 2 (최근 30일)
Chanoknunt Sangsobhon
Chanoknunt Sangsobhon 2022년 11월 14일
댓글: Chanoknunt Sangsobhon 2022년 11월 15일
Hello again. Sorry for my question again.
I have a code to detected the shape using for loop and switch case.
I can plot the centroid on image but I cannot extract the centroid coordinate from it.
I want the centroid coordinate in the form of matrix of excel file or anything that I can use the information in the next step.
This is the code I have. For this code I cannot obtained the all centroid detected within this loop.
Furthermore, this is the code use for 1 image. In short future, I have to read the all images in folders and do this to every image. So, I need to store the centroid coordinate of every image and use it for calculation. I will be so thankful if you can guide me for this.
Thank you in advance.
for i = 1 : length(STATS)
W(i) = uint8(abs(STATS(i).BoundingBox(3)-STATS(i).BoundingBox(4)) < 0.1);
W(i) = W(i) + 2 * uint8((STATS(i).Extent - 1) == 0 );
W(i) = W(i) + 4 * uint8((STATS(i).Extent - 1) <= 0.7854); %Extent = pi/4 case ellipse/circle
centroid = STATS(i).Centroid;
switch W(i)
case 5
plot(centroid(1),centroid(2),'wO');
x_centroid = centroid(1:2:end);
y_centroid = centroid(2:2:end);
case 2
plot(centroid(1),centroid(2),'wX');
case 3
plot(centroid(1),centroid(2),'wS');
%case 4
%plot(centroid(1),centroid(2),'w+');
end
end

답변 (1개)

Image Analyst
Image Analyst 2022년 11월 14일
Put all that in a loop over all files. For code snippets, see the FAQ:
If you still can't figure it out, write back.
If you want to save the centroid(s) for the blob(s) in this image, save STATS into a cell array
filePattern = '*.png';
fileList = dir(filePattern);
numImages = numel(fileList);
for frameIndex = 1 : numImages
thisFileName = fullfile(fileList(frameIndex).folder, fileList(frameIndex).name);
fprintf('Processing %s\n', thisFileName)
STATS = regionprops(binaryImage, 'Centroid', 'Extent', 'BoundingBox');
for i = 1 : numel(STATS)
% Code
end
ca{frameIndex} = STATS; % Save centroids for all the blobs into a cell for this particular image.
end
  댓글 수: 1
Chanoknunt Sangsobhon
Chanoknunt Sangsobhon 2022년 11월 15일
I have tried the code but the ca obtained only 1 centroid value which I don't know what value it is whether it is which centroid or it is x or y coordinate. I mean, I tried used it with one image first but in that image suppose to have 2 centroids but it obtained only 1 centroid value.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by