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

2 Ansichten (letzte 30 Tage)
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');
imshow(rgb)
[centers,radii] = imfindcircles(rgb,[10 300],'Sensitivity',0.85);
imshow(rgb)
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!

Akzeptierte Antwort

yanqi liu
yanqi liu am 26 Sep. 2021
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);
%imshow(rgb)
[centers,radii] = imfindcircles(rgb,[10 300],'Sensitivity',0.85);
%imshow(rgb)
%h = viscircles(centers,radii,'color','b');
res{end+1} = [centers radii(:)];
end
xlswrite('res.csv',res)

Weitere Antworten (1)

Image Analyst
Image Analyst am 26 Sep. 2021
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 Kommentar
Nick
Nick am 27 Sep. 2021
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!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by