Measure circle radius in multiple images and output data in csv file
5 次查看(过去 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!
0 个评论
采纳的回答
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
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:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!