How it works...

To convert the data type of the matrix, it's necessary to use the astype function of NumPy Array. The function takes desired type as input and returns converted array.

To scale the values of the matrix, you can use an algebraic operation with the matrix itself: for example, just divide the matrix by some value (255, in the preceding code) to divide each element of the matrix by the specified value. The result of scaling the values of the input images should appear as follows (the left image is the original, the right image is the scaled version):

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.