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

Gaze Extraction #5

Open
youssefmohana opened this issue May 9, 2024 · 0 comments
Open

Gaze Extraction #5

youssefmohana opened this issue May 9, 2024 · 0 comments

Comments

@youssefmohana
Copy link

youssefmohana commented May 9, 2024

Debugging

RuntimeWarning: invalid value encountered in divide
  gaze = (((gaze-gaze.min())/(gaze.max()-gaze.min())) * 255).astype(np.uint8)
RuntimeWarning: invalid value encountered in cast
  gaze = (((gaze-gaze.min())/(gaze.max()-gaze.min())) * 255).astype(np.uint8)

can we update code with this ?

def getPatchGaze(self, gaze: NDArray[Any]) -> NDArray[Any]:
    g = np.zeros((56,56), dtype=np.float32)
    for i in range(56):
        for j in range(56):
            x1 = 4*i-7
            x2 = 4*i+7
            y1 = 4*j-7
            y2 = 4*j+7
            if x1 < 0:
                x1 = 0
            if y1 < 0:
                y1 = 0
            if x2 > 223:
                x2 = 223
            if y2 > 223:
                y2 = 223
            g[i,j] = gaze[x1:x2, y1:y2].sum()
    
    # Check if the range of g is suitable for normalization
    if g.max() - g.min()!= 0:
        g = (g - g.min()) / (g.max() - g.min())
    else:
        # Handle the case where all values are the same
        g = np.full_like(g, 127.5)  # Set to middle value of uint8 range
    
    # Cast to uint8, handling NaN values by setting them to 0
    g = np.nan_to_num(g).astype(np.uint8)
    
    return g

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