Skip to content

Instantly share code, notes, and snippets.

@strdr4605
Created May 10, 2022 16:01
Show Gist options
  • Save strdr4605/0034b60f70a43d7c14693513ed0213f3 to your computer and use it in GitHub Desktop.
Save strdr4605/0034b60f70a43d7c14693513ed0213f3 to your computer and use it in GitHub Desktop.
import numpy as np
from PIL import Image
section_size = 20
im = Image.open("ndvi_test.jpg")
px = np.asarray(im)
x = 0
y = 0
imgheight, imgwidth, _ = px.shape
for i in range(0, imgheight - 1, section_size):
for j in range(0, imgwidth - 1, section_size):
section = px[i:i+section_size, j:j+section_size]
avg_color = np.average(section, axis=(0, 1))
for section_i in range(i, i+section_size):
for section_j in range(j, j+section_size):
px[min(section_i, imgheight - 1), min(
section_j, imgwidth - 1)] = avg_color
out = Image.fromarray(np.uint8(px))
out.show()
# im.show()
# im.save("ndvi_test_out.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment