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

2 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

yanqi liu
yanqi liu il 26 Set 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)

Più risposte (1)

Image Analyst
Image Analyst il 26 Set 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 Commento
Nick
Nick il 27 Set 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!

Accedi per commentare.

Categorie

Scopri di più su Data Import and Export in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by