# Getting the Wrong Output While Using Image Batch Processor

1 回表示 (過去 30 日間)
Shafa Salsabila 2023 年 8 月 1 日

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 executing 12 images with the function in image batch processor, I got 12x12 table.  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
Perhaps anyone could tell me what's wrong with my function? Any help would be appreciated.

サインインしてコメントする。

### 回答 (2 件)

VBBV 2023 年 8 月 1 日

possibly you are calliing the function porosity_function inside a loop, which repeats 12 times and storing the output for all images each time. That makes 12 x 12. However, from the snapshots its not clear whether its 12 x12 table or a 12 x 2 table that you actually mean, perhaps its 12 x 2 table
function porosity = porosity_function(image)
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

サインインしてコメントする。

DGM 2023 年 8 月 1 日

If the array called image is a matrix, the output from this operation will be a vector.
black_pixels = sum(image == 0);
While addressing the dimensionality of the output is one thing, I think we need to back up and ask whether it's appropriate to do either of these operations on the particular images. If the input images are logical class, this entire operation can be reduced to a single call to mean().
porosity = mean(~image,'all')*100
... but most images aren't stored in logical class (it's possible, but uncommon). If it's assumed that black is 0, that's nominally correct, but often not in practice.
imshow(inpict) % looks like it has lots of black! nnz(inpict==0) % but it actually has none!
ans = 0
Photographic content or even nominally-binarized images that have been subject to compression can be deceiving. It's worth asking if equality with zero is an appropriate test. If picking another threshold, it would be useful to know what the image class is and what the histogram looks like.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeImages についてさらに検索

R2023a

### Community Treasure Hunt

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

Start Hunting!