Created
October 12, 2021 02:39
-
-
Save InputBlackBoxOutput/712e11e13b8c748bbbab53214ae79076 to your computer and use it in GitHub Desktop.
Perform operations on pixels in an image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
from PIL import Image | |
def process_pixels(img): | |
pixel_data = list(img.getdata()) | |
pixels = np.array(pixel_data).flatten() | |
width = img.size[0] | |
height = img.size[1] | |
# Perform operations on pixels | |
print(pixels) | |
pixel_data = [] | |
for index in range(0, len(pixels), 3): | |
pixel = [] | |
for offset in range(3): | |
pixel.append(pixels[index + offset]) | |
pixel_data.append(tuple(pixel)) | |
img.putdata(pixel_data) | |
return img | |
img = Image.open('image.png') | |
img = process_pixels(img) | |
img.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment