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

3 次查看(过去 30 天)
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!

采纳的回答

yanqi liu
yanqi liu 2021-9-26
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)

更多回答(1 个)

Image Analyst
Image Analyst 2021-9-26
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 个评论
Nick
Nick 2021-9-27
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!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by