Digital image processing basics using OpenCV and python :

Digital image :

# Pixel:

Types of digital image:

  1. Binary images
  2. Gray-scale images
  3. Color images
  4. Multispectral images

First thing first what is OpenCV ?

Why we use OpenCV?

  • OpenCV is available for free of cost.
  • Since the OpenCV library is written in C/C++, so it is quit fast. Now it can be used with Python.
  • It require less RAM to usage, it maybe of 60–70 MB.
  • Computer Vision is portable as OpenCV and can run on any device that can run on C.

Installation of the OpenCV :

Basic operations with OpenCV :

OpenCV to Read Image:

The syntax is:

Parameters:

  • CV_LOAD_IMAGE_ANYDEPTH — If we set it as flag, it will return 16-bits/32-bits image when the input has the corresponding depth, otherwise convert it to 8-BIT.
  • CV_LOAD_IMAGE_COLOR — If we set it as flag, it always return the converted image to the color one.
  • C V_LOAD_IMAGE_GRAYSCALE — If we set it as flag, it always convert image into the grayscale.

code :

output:

Code explanation :

OpenCV: Copy image

code:

output:

Code explanation :

OpenCV: Converting an color image to HSV

code:

output:

Code explanation :

OpenCV: Converting an color image to grayscale image

code :

output:

Code explanation :

OpenCV: Resize an image

Code :

Output :

Code explanation :

  • src — source/input image (required).
  • dsize — desired size for the output image(required)
  • fx — Scale factor along the horizontal axis.(optional)
  • fy — Scale factor along the vertical axis.
  • Interpolation(optional) — This flag uses following methods:
  • INTER_NEAREST — A nearest-interpolation INTER_AREA — resampling using pixel area relation. When we attempt to do image zoom, it is similar to the INTER_NEAREST method.
  • INTER_CUBIC — A bicubic interpolation over 4×4 pixel neighborhood.
  • INTER_LANCOZS4 — Lanczos interpolation over 8×8 pixel neighborhood.

Several ways of resizing the images

  1. Retain Aspect Ratio ( height to width ratio of the image is retained)
  • Downscale(Decrement in the size of the image)
  • Upscale(Increment in the size of image)
  • Resize only the width
  • Resize only the height

--

--

--

Eat. Sleep. Code. Repeat

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to use readme files(.md), here is the srategy list in, I want to do on Github!!

Cloud native migration of application — implementation steps and outcome

HDSC Winter ’22 Premiere Project Presentation: Key Insights from the 2020 Stack Overflow Survey

Perfect your user onboarding messages using Zapier, Airtable, and Notivize

How To Fix BLU Grand X LTE Not Charging [Troubleshooting Guide]

Recipe to build a basic Web 3 Ethereum Blockchain app

WEDEVELOPERS HIRING PROCESS, EVERYTHING YOU NEED TO KNOW.

All things are NOT equal as a new coder

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahin Das

Ahin Das

Eat. Sleep. Code. Repeat

More from Medium

Color Recognition with Python

Video Capturing Using Python And OpenCV

Image Classification using FASTAI — Tutorial Pt.1

Set up your Virtual Environment (Python)