DEV Community

es404020
es404020

Posted on

Python 📸 image manipulation

Image manipulation is a key technique in computer vision.This helps to better prepare our data for training .

In this short tutorial we would highlight various technique required for image manipulation

  • Load Image

`
import skimage.io as io #for input output manipulations on the image
import matplotlib.pyplot as plt
import numpy as np

you can download any color image from google.com to use for this lab

Read the image

img = io.imread('/content/Screenshot 2023-05-05 at 09.45.04.png')

plt.imshow(img)
plt.show()

`

  • Image shape


img.shape
(675, 1272,3)

The 3 means it contains three layer RGB(Red,Green and blue) all layered on each other.

  • Slipt layers in different section

`

Split

red = img[:, :, 0]
green = img[:, :, 1]
blue = img[:, :, 2]

`

  • Preview Split layers based on color

`
plt.imshow(red, cmap="Reds")
plt.show()

============================================
plt.imshow(green, cmap="Greens")
plt.show()

============================================

plt.imshow(blue, cmap="Blues")
plt.show()

`

Image Transformation
Using tensorflow you can run image argumentation to create muitiple variation of the same image
`

Rotation

import tensorflow as tf
transformation = tf.keras.preprocessing.image.apply_affine_transform(
img,
theta=270
)
plt.imshow(transformation)

Ship image

import tensorflow as tf
transformation = tf.keras.preprocessing.image.apply_affine_transform(
img,
tx=500,
ty=500,
)
plt.imshow(transformation)
`
Thanks for reading

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up