Getting the Wrong Output While Using Image Batch Processor (Edited Version)
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2023-8-6
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 个评论
Walter Roberson
2023-8-28
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Import, Export, and Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!