Masih chatraei

I'm passionate about building intelligent systems that bring comfort, efficiency, and smart control to daily life. With hands-on experience in IoT devices, AI integration, and educational content creation, I specialize in developing smart home solutions that bridge the physical and digital worlds.

image processing with numpy

In this post, I want to use Python and the powerful NumPy library to convert an image into a three-dimensional matrix, extract interesting data from the image, and also perform interesting filters and slicing on the image. In this post, we will examine the outputs of the project. The codes for this project are completely in my GitHub : Click Here.👈

Photo source

For this project, I used this photo of a hummingbird, but you can import your own photo at the beginning of the project file so that all processing can be done for your image

It is interesting to know that digital color photographs are three-dimensional, with dimensions of length, width, and depth. The depth of the photograph is the combination of the red, blue, and green values

RGB values ​​are between 0-255

Slicing

I divide the image into 3×3 dimensions

The marked parts are separated

The middle part is selected

The four corners of the photo are selected and glued together

Filtering

In this image, the red values ​​of the pixels have been removed, leaving only the green and blue color combination visible👇

In this image, the green values ​​of the pixels have been removed, leaving only the red and blue color combination visible👇

In this image, the blue values ​​of the pixels have been removed, leaving only the red and green color combination visible👇

In this image, the red and green values ​​of the pixels have been removed, leaving only the blue color combination visible👇

In this image, the red and blue values ​​of the pixels have been removed, leaving only the green color combination visible👇

In this image, the green and blue values ​​of the pixels have been removed, leaving only the red color combination visible👇

Selecting specific pixels

In this image, we select pixels with a red value greater than 200 and make the pixels completely white👇

In this image, we select pixels with a red value less than or equal to 200 and make the pixels completely white👇

In this image, you can see the pixels with a red value greater than 150 or less than 150 and the number of pixels each selected in the image

In this image, you can see the pixels with a green value greater than 150 or less than 150 and the number of pixels each selected in the image👇

In this image, you can see the pixels with a blue value greater than 150 or less than 150 and the number of pixels each selected in the image👇

analysis

In this section, we want to analyze the image

In this section, we want to detect pixels that are completely black👇

In this section, we want to detect pixels that are completely white👇

In this section, we want to see which red, blue, and green values ​​are greater than the others in each pixel👇

In this section, based on the image, we calculate the average of the red, green, and blue values ​​in each row and move from top to bottom. The resulting graph is the average of all rows of the image for the colors red, green, and blue👇

In this section, based on the image, we calculate the average of the red, green, and blue values ​​in each column, moving from left to right. The resulting graph is the average of all the image columns for the colors red, green, and blue👇

In this section, for each pixel, we keep the red, green, and blue values ​​that are greater than the others and set the other values ​​to zero(dominant color per pixel)👇

In this section, the red, green, and blue values ​​of each pixel are inverted by subtracting them from the maximum intensity of 255 for each channel. This operation converts the original image into its negative equivalent, where the bright areas are darkened and the colors are inverted👇

Analysis of the original image and its negative, based on averaging the red, blue, and green values ​​along the row, in the form of a graph👇

Increase and decrease size

In this section, we reduce the image dimensions by deleting rows and columns in a specific pattern.
We also increase the image dimensions by repeating some rows and columns in a specific pattern.

🚀The full project file is on my GitHub🚀