Getting the Wrong Output While Using Image Batch Processor (Edited Version)
3 views (last 30 days)
Show older comments
Shafa Salsabila
on 6 Aug 2023
Commented: Walter Roberson
on 28 Aug 2023
Greetings, everyone.
I am a beginner in MATLAB and I just started to learn it for my bachelor thesis. So, I created a function that counts porosity from an image and feed that function into batch processor to process hundreds of image. I used the simpe formula (black pixel/total pixel) * 100 to generate porosity value and for 1 image, I expected to only get 1 porosity value. Therefore, I wanted the output table to be (the number of images)x1. But after running a trial with 12 images processed by a porosity calculator function in image batch processor, I got 12x2 table where each desired output is a vector(12,1).

Here's my code:
function porosity = porosity_function(image)
% Calculates the porosity of an image.
% Args:
% image: A MATLAB array representing the image.
% Returns:
% The porosity of the image
black_pixels = sum(image == 0);
total_pixels = size(image, 1) * size(image, 2);
porosity = (black_pixels * 100) / total_pixels;
end
And here's a few sample images (all are binary image, originally a SEM -scanning electron microscope- image of a limestone with 2000-8000x magnification). In my field of study (chemistry), pore is one of the key characteristics that represents a material/substance and there are many methods to measure it. For my thesis, I compare porosity calculated digitally (from an image and using MATLAB) and experimentally (using gas sorption analyzer instrument with nitrogen adsorption method). I have 100+ SEM images to process, so I need to put it in batch processor to save time.

Perhaps anyone could tell me what's wrong with my function? Any help would be appreciated.
0 Comments
Accepted Answer
Walter Roberson
on 6 Aug 2023
The problem is not the porosity function: the problem is the way you are storing the results into the output table.
You are probably doing something like
for i = 1 : number_of_files
T(i).output = Porosity_results;
T(i).fileName = filenames{i};
end
when you should instead be doing
for i = 1 : number_of_files
T(i).output = Porosity_results(i);
T(i).fileName = filenames{i};
end
or better yet make the table in one call, such as
T = table(Porosity_results, filenames(:), 'VariableNames', {'output', 'fileName'});
2 Comments
Walter Roberson
on 28 Aug 2023
We recommend that you do not use image as the name of a variable, as doing so interfers with calling the MATLAB function named image
More Answers (0)
See Also
Categories
Find more on Import, Export, and Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!