How to output centroid coordinate from switch case wihtin loop case
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Image Analyst
am 14 Nov. 2022
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
Siehe auch
Kategorien
Mehr zu Image Processing and Computer Vision finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!