MATLAB Answers

Measure circle radius in multiple images and output data in csv file

27 views (last 30 days)
Nick on 26 Sep 2021 at 1:05
Commented: Nick on 27 Sep 2021 at 3:04
Hi everyone,
I have thousands of images (most image has a single circle, a few have 2-5 circles with different radius). I would like to measure the radius in each image and output their radius value in a csv or txt tile. I am using the imfindcircles function currently, but I am manually measuring each picture and copying the radius to an Excel file. Here is my current code:
rgb = imread('XXX.jpg');
[centers,radii] = imfindcircles(rgb,[10 300],'Sensitivity',0.85);
h = viscircles(centers,radii,'color','b');
Could someone show me how to revise the code to let it automatically read all the images in my folder and output the values in a csv file? Thanks a lot!

Accepted Answer

yanqi liu
yanqi liu on 26 Sep 2021 at 2:58
sir, may be you want to loop the folder and get result to csv file
the follow is the ref code, please modify it
your_folder = 'please update this to your folder';
files = ls(fullfile(your_folder, '*.jpg'));
res = [];
for i = 1 : size(files,1)
filei = fullfile(your_folder, strtrim(files(i,:)));
rgb = imread(filei);
[centers,radii] = imfindcircles(rgb,[10 300],'Sensitivity',0.85);
%h = viscircles(centers,radii,'color','b');
res{end+1} = [centers radii(:)];

More Answers (1)

Image Analyst
Image Analyst on 26 Sep 2021 at 1:37
Nick, it really depends on how hard it is to find your circles. You forgot to attach your image so I can't see it. It could be you can simply threshold, like I do in my Image Segmentation Tutorial where I find circles:
To process a sequence of files, put your code to analyze a single image in a loop as shown in the FAQ:
  1 Comment
Nick on 27 Sep 2021 at 3:02
Thanks for the attached websites! I will attach a image next time asking a question. Really appreciate it ! I tried yanqi's code and it works for my images!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!