Converting RGB Numpy Matrix To Greyscale Martix
I want to convert rgb matrix to greyscale martix without directly opening the image file as the process is very slow in python?
In general, you always have to load image into python program if you want to process it. If you dont wan to use image procesing library, you can do all with numpy (for example OpenCV works with numpy arrays anyway, so I would be using OpenCV)
If you want to use purely matrixes(numpy) you can use for saving and loading
matrix = np.load('image.npy') np.save('grayscale.npy',grayscale)
Suppose you have have numpy matrix with this RGB shape:
>>> matrix.shape (1000, 1000, 3)
In order to transform it into grayscale without doing any 'image processing', you can simply do MEAN over 3rd. dimension (color dimension)
grayscale = matrix.mean(axis=-1) # you can use axis=2 or as Nils Werner pointed out: axis=-1 which is more general >>> grayscale.shape (1000,1000)
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module