Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save harrisonford/7a86ea5790e7dc24543c0aece92ede31 to your computer and use it in GitHub Desktop.
Save harrisonford/7a86ea5790e7dc24543c0aece92ede31 to your computer and use it in GitHub Desktop.
Implements NSS (Natural Scanpath Saliency) scoring function from MIT Benchmark page for python
import numpy.ma as ma
# NOTE: THIS FUNCTION ASUMES BOTH MAPS ARE SAME SIZE! (modify to generalize)
# And also salmap, fixmap are np.arrays or equivalent
def nss(salmap, fixmap, threshold=0):
# Z-score salmap and binarize fixmap
salmap_scored = (salmap - salmap.mean())/salmap.std()
fixmap_mask = fixmap <= threshold # all these '1' values are going to be eliminated using mask
# Take mean value of fixation locations in fixmap as your score
# This means wherever fix-duration is at least threshold we'll use to calculate score
# If threshold=0 we think of fixation as a binary "there is or isn't"
intermap = ma.masked_array(salmap_scored, mask=fixmap_mask)
return intermap.mean()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment