Created
October 20, 2022 17:57
-
-
Save victormurcia/c27d02c089dfcd3c5ee08f6d1686de7a to your computer and use it in GitHub Desktop.
get pixel color
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
| #Get color from single pixel in image | |
| #Make list of pixel coordinates based on image shape | |
| y = range(0, height, 25) | |
| x = range(0, width, 25) | |
| #Combine lists above into a list of tuples | |
| merged_list = tuple(zip(x, y)) | |
| #Initialize the plot | |
| fig,axs = plt.subplots(1, len(y), figsize=(30,30)) | |
| i = 0 | |
| #Iterate over elements in tuple list of pixel coordinates | |
| for (x, y) in merged_list: | |
| #Return rgb tuple at x,y coordinate | |
| r, g, b = (rgb_img[x, y]) | |
| # Creating rgb array from rgb tuple | |
| color_of_pix = np.zeros((5, 5, 3), np.uint8) | |
| color_of_pix[:] = [r, g, b] | |
| #Display rgb array | |
| axs[i].imshow(color_of_pix) | |
| i += 1 | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment