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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay