Created
December 6, 2019 20:58
-
-
Save ritvikmath/57e1a11669aa03b7ff25b748165bef5e to your computer and use it in GitHub Desktop.
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
| #create a copy of my image | |
| copyImg = img.copy() | |
| #get the average of each pixel | |
| #we need axis=2 so that we take averages accross the 3rd axis (the color axis) rather than accross the rows or columns | |
| average_pixel_values = np.mean(copyImg, axis=2, keepdims=True) | |
| #create the grey image by "stacking" three copies of these grey values together | |
| greyImage = np.concatenate([average_pixel_values]*3, axis=2) | |
| #make sure to cast the final image back to integers | |
| greyImage = greyImage.astype(int) | |
| #show the final image | |
| plt.imshow(greyImage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment