Skip to content

Instantly share code, notes, and snippets.

@prateekjoshi565
Created February 27, 2020 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prateekjoshi565/5a7b905cd898375773bbc6dd96cc8916 to your computer and use it in GitHub Desktop.
Save prateekjoshi565/5a7b905cd898375773bbc6dd96cc8916 to your computer and use it in GitHub Desktop.
# function to reduce image resolution while keeping the image size constant
def pixalate_image(image, scale_percent = 40):
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dim = (width, height)
small_image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
# scale back to original size
width = int(small_image.shape[1] * 100 / scale_percent)
height = int(small_image.shape[0] * 100 / scale_percent)
dim = (width, height)
low_res_image = cv2.resize(small_image, dim, interpolation = cv2.INTER_AREA)
return low_res_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment