reading multiple images in a folder and storing the data

2 views (last 30 days)
Hello,
I have the following code which was provided by one of the members. It reads an image and calculate the surface and sectional areas.
I tried to modify the code so that it reads several images, say from 1-100 and store the sectional and surface areas in a text file, but it didn't work.
Any suggestions?
inpict = rgb2gray(imread('44.png'));
% generate binary image of object alone
m = ~imbinarize(inpict,'adaptive','foregroundpolarity','dark','sensitivity',0.5);
m = bwareafilt(imclearborder(m),1);
st = strel('disk',20);
m = imerode(~bwareafilt(imerode(~m,st),1),st);
%imshow(m)
% calculate areas
d = sum(m,1);
d = d(d~=0);
Asurf = sum(pi*d) % assuming rotational symmetry
Asect = sum(m,'all')

Answers (1)

Image Analyst
Image Analyst on 19 Oct 2021
There is nothing in that code that stores anything in a text file. Try fopen(), then fprintf() and then fclose(), or the writematrix() function.
To process a sequence of image files, see code samples in the FAQ.
Write back if you can't figure it out.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!