For the output of image processing (image evaluation) software using numpy in python3, Inf and NaN are included in the mean, standard deviation, maximum, and minimum.
sample_code.py
import numpy as np
img = #Somehow an array of images
print(np.max(img))
print(np.min(img))
print(np.mean(img))
print(np.std(img))
>inf
>-inf
>NaN
>NaN
Like this I was quite addicted to it
In the first place, what is inf or NaN **? (Gekiuma Gaku) When I looked it up, a lot of information came out. inf Abbreviation for infinity. Represents infinity. -inf is negative infinity, isn't it?
NaN
Floating-point numbers have a special number called NaN (Not a Number) that represents anomalous real numbers. This happens when you perform calculations that cannot be represented by real numbers, such as infinity-infinity, indeterminate forms such as 0.0 / 0.0, square roots of negative numbers, and logarithms of negative numbers.
From NaN Story
My understanding is that values (numbers) that you do not want to consider or exclude during calculation are recognized.
sample_code.py
import numpy as np
img = #Somehow an array of images
img[img == -np.inf] = np.nan
img[img == np.inf] = np.nan
Now the inf disappears from the array. Let's move on
sample_code.py
import numpy as np
img = #Somehow an array of images
img[img == -np.inf] = np.nan
img[img == np.inf] = np.nan
minimum,maximum= np.nanmax(img), np.nanmin(img)
average= np.nanmean(img)
standard deviation= np.nanstd(img)
#There are also totals and variances
Reference: https://note.nkmk.me/python-numpy-nansum/
I'm talking about what kind of processing this is done. When calculating the maximum and average, ** exclude the NaN element ** and calculate. For example, in the case of average calculation, it is not included in the total value of the whole and is not included in the number of elements.
An image that deletes NaN from the array. Then you may think that you should delete it, but that is not the case with image processing. If you delete it, it will be the same as the vertical and horizontal size of the image.
For the time being, if you divide by 0 or divide by 0, inf and NaN will be included, so Is it a feeling that software that does such processing should basically perform the above processing?
It was quite difficult to notice this. I often automate image processing work like I do with imageJ. I noticed that the output result of the software and the result processed by imageJ were different. I felt that inf would be excluded. Is it common sense in the world of image processing?