Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOS Mean calculation #11

Open
horsto opened this issue Oct 10, 2023 · 0 comments
Open

FOS Mean calculation #11

horsto opened this issue Oct 10, 2023 · 0 comments

Comments

@horsto
Copy link

horsto commented Oct 10, 2023

When calculating the mean (in FOS) ...
https://github.com/giakou4/pyfeats/blob/dc0e2d1b3623aeb7f26c9777dafb491ecd961b9c/pyfeats/textural/fos.py#L47

I noticed divergence between a simple np.mean and your version.

f  = f.astype(np.uint8)
mask = mask.astype(np.uint8)
level_min = 0
level_max = 255
Ng = (level_max - level_min) + 1
bins = Ng

# 3) Calculate Histogram H inside ROI
f_ravel = f.ravel() 
mask_ravel = mask.ravel() 
roi = f_ravel[mask_ravel.astype(bool)] 
H = np.histogram(roi, bins=bins, range=[level_min, level_max], density=True)[0]

# 4) Calculate Features
features = np.zeros(16,np.double)  
i = np.arange(0,bins)
features[0] = np.dot(i,H)

features[0] here is the FOS_Mean.
If you calculate a simple np.mean(roi) you get a different result than saved in features[0].
If you edit Ng = (level_max - level_min) + 1 to Ng = (level_max - level_min) (drop the +1), then the results match.

I am not quite sure I understand the +1 here.
For example, in my data:

np.mean(roi) -> 73.9154898873683
features[0] with Ng = (level_max - level_min) + 1 -> 74.20535455359327 
features[0] with Ng = (level_max - level_min) ->  73.9154898873683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant