Skip to content

FOS Mean calculation #11

@horsto

Description

@horsto

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions