Show the amount of circles being found in each frame of a sequence using imfindcircles

7 次查看(过去 30 天)
I have a video of water moving along a track with circles on the track. The video has been edited so the circles are not visible at the start, but become visible as the water moves over them. The code below extracts the series of frames from one image, and then locates the number of circles in each of the subtracted frames as water moves along the track, detecting none at the beginning and all of the circles by the end. This works, however the results in the command window are pretty tough to comprehend with no obvious number of circles detected in each image, and there are many to scroll through since there are 99 frames. I need to be able to see the rate at which the circles are appearing. Is there a way to see simply how many circles are in each frame/the rate at which they are appearing, whether that's displayed in a graph or just in the command window in a more understandable format? Thanks.
folder = fullfile('C:\Folder1\Folder2');
filePattern = fullfile(folder, '*.jpg');
fileList = dir(filePattern);
numberOfFiles = numel(fileList);
%choose name of file of image to be subtracted from below
subtractionFileName = 'subtract.jpg';
if ~isfile(subtractionFileName)
errorMessage = sprintf('Subtraction image not found:\n%s', subtractionFileName);
uiwait(errordlg(errorMessage));
return;
end
backgroundImage = imread(subtractionFileName);
for k = 1:numberOfFiles
baseFileName = fileList(k).name;
if contains(baseFileName, 'subtract', 'IgnoreCase', true)
continue;
end
fullFileName = fullfile(fileList(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
thisImage = imread(fullFileName);
%Doing the subtraction
subtractionImage{k} = backgroundImage - thisImage;
%Displaying images
imshow(subtractionImage{k}, [])
caption = sprintf('Image #%d of %d : %s', k, numberOfFiles, baseFileName);
title(caption, 'Interpreter', 'none');
drawnow; %forcing updating of screen immediately
end
Rmin = 3;
Rmax = 10;
for k = 1:numberOfFiles
newImage1 = subtractionImage{k};
[centresbright, radiibright] = imfindcircles(newImage1, [Rmin Rmax], 'ObjectPolarity', 'bright',...
'Sensitivity', 0.85,'EdgeThreshold',0.10);
viscircles(centresbright, radiibright, 'color', 'b')
end

回答(1 个)

T.Nikhil kumar
T.Nikhil kumar 2023-10-26
Hello Andrew,
I understand that you want to count the number of circles detected in each frame and display it in the command window or visualise it in a graph.
I would suggest you create an array that will keep track of the number of circles in each frame and name it ‘circleCount. Each element in this array will contain the number of circles found in the corresponding index’s frame.
You can obtain the number of circles by calculating the row size of the ‘centresbright’ variable which is an output of the ‘imfindcircles’ function. Refer to the code snippet to understand the procedure:
circleCount = zeros(numberOfFiles, 1); % Initialize circle count array before the loop
%%
for k = 1:numberOfFiles
newImage1 = subtractionImage{k};
[centresbright, radiibright] = imfindcircles(newImage1, [Rmin Rmax], 'ObjectPolarity', 'bright',
'Sensitivity', 0.85,'EdgeThreshold',0.10);
% Store the circle count for this frame
circleCount(k) = size(centresbright, 1);
viscircles(centresbright, radiibright, 'color', 'b')
end
You can now plot this data using the ‘plot’ function and visualise the number of circles in each corresponding frame. Refer to the following code snippet on the procedure:
% Display circle count in each frame
frameNumbers = 1:numberOfFiles;
figure;
plot(frameNumbers, circleCount);
title('Number of Circles in Each Frame');
xlabel('Frame Number');
ylabel('Circle Count');
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by