DEV Community

Cover image for NUMPY AND IMAGE MANIPULATION
betpido
betpido

Posted on

NUMPY AND IMAGE MANIPULATION

An image is a pixel or a combination of pixels.

A pixel is the smallest piece of an image ( just as an atom is the smallest piece of an object)

NumPy refers to Numerical Python and its a library in Python for numerical and mathematical operations.

NumPy is used extensively in image manipulation and computer vision, because of its ability to deal with arrays and matrices.

You can read more on NumPy online, but in this short post, I wanted to talk about a few things in NumPy that I want learners to take note of.

  1. NumPy treats images as matrices. Numpy is used for matrix manipulation in Python.

  2. An image is a 3-dimensional array(3D array) which means H(height), W(width) and RGB-value(color)

  3. A 3D array, involves number of arrays, number of rows of each array, and number of columns for each row. That is
    [Number of arrays, Number of rows of each array, Number of columns of each row]
    [4,5,3] is an example of a 3D array.
    4 = 4 arrays,
    5 = each array has 4 rows
    3 = each row has 3 columns

4.For any image, the number of arrays refers to the height of the image
Number of of rows of each array refers to the width of the image
Number of columns of each row refers to the number of colors of each pixel.
[4,5,3] being a 3D array as stated in 3 above,
For this image,
4 = height of image
5 = width of image
3 = number of colors of each pixel of this image.

In my next post, I am going to draw a diagram of a NumPy array and relate it to a practical image.
I will also show how 'row' and 'columns' in NumPy are arranged differently from 'row' and 'columns' in spreadsheet software

Top comments (2)

Collapse
 
akechi523 profile image
Seiya Souda

This is great article.
I am looking forward to next one.
Thank you.

Collapse
 
betpido profile image
betpido

Thanks bro, I just posted it. Let me know if you need additional information.