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

Optimize get_avg_pixels #5

Open
kolayne opened this issue Dec 3, 2020 · 0 comments
Open

Optimize get_avg_pixels #5

kolayne opened this issue Dec 3, 2020 · 0 comments

Comments

@kolayne
Copy link
Owner

kolayne commented Dec 3, 2020

Can we delegate the following piece of code to numpy and thus speed it up?

def get_avg_pixels(img, split_depth=2):
ans = np.zeros((split_depth, split_depth, 3))
img = np.asarray(img)
x_size, y_size, _ = img.shape
for x_multiplier in range(split_depth):
x_range_from = int(x_size / split_depth * x_multiplier)
x_range_to = int(x_size / split_depth * (x_multiplier + 1))
for y_multiplier in range(split_depth):
y_range_from = int(y_size / split_depth * y_multiplier)
y_range_to = int(y_size / split_depth * (y_multiplier + 1))
ans[x_multiplier, y_multiplier] = avg(img[x_range_from:x_range_to, y_range_from:y_range_to].ravel())
return ans

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