OpenC V— Jupyter-lab — Python

Image Processing Exercises — #PyVisionSeries — Episode #01

J3
Jungletronics
4 min readOct 4, 2022

--

Let´s create a conda environment for running python OpenCV code.

We are working with Jupyter Notebook :)

Please, first, download Anaconda package for Data Science.

Download all the files for this project.

Now folow theses steps:

00step — Create Directory to work with

Create anywhere on your windows computer a directory (python_opencv)

Now type on prompt:

and paste these file inside:

python_opencv.yml

DATA [Directory containing the images]

Yml file will import all the libs that you will need for OpenCV via Conda.

01step — Create a Virtual Environment

In your prompt (inside python_opencv dir):

02 step— Run Jupyter Notebook:

If all goes well, you will find this screen open in your browse:

keep prompt screen open. Now you are ready to go!

Before we dive into OpenCV, Let´s see how to manipulate Image w/ Pure Python!

GOTO

Rename it as 01_cv_00.ipynb,

and Type:

PILLOW LIB

Importing Numpy as well Matplotlib:

Importing Pillow lib:

Save this image DATA to your directory: 00_puppy.jpg (or whatever you like:)

Type:

To work with Numpy we must convert JPEG image into Numpy Array. Here is how to:

This now is a Numpy Array:

It’s Shaped as:

Use MatPlotLib to show the image:

It’s Shaped as:

Note that there’s three channels here, the red, the green and the blue.

Each one has its array, (551, 789) for Red , (551, 789) for Green and, (551, 789) for Blue. 3-D arrays.

Let’s actually access one of these channels by itself:

For RED:

Showing the img:

Notice that the dog’s coat is reddish, so it appears white in the image

So that means when we’re actually viewing this in grayscale, the closer to white that means more red for this particular image.

For GREEN:

Notice that the grass is green, so it appears white in the image, at the ends

For BLUE:

Note that the container behind is blue, so it appears very clear in the image

So, here we’re displaying the three different channels as grayscale.

Now let´s zeroed GB and stick with R channel

Zeroed out the Green Channel:

Zeroed out the Blue Channel:

Shows up the RED channel:

Here the other channels were zeroed, and red prevails

We went ahead and zeroed out the Green Channel as well as the Blue Channel, which is why this picture only shows up with the red.

There are 3 channel, yet! because we’re seeing all three channels at once instead of just one channel.

What we did was zeroed two channels, but the arrays remain intact even if their values have been set to zero

👉Jupiter notebook link :)

👉Github (EX_01)

Credits & References:

Jose Portilla — Python for Computer Vision with OpenCV and Deep Learning — Learn the latest techniques in computer vision with Python, OpenCV, and Deep Learning!

Posts Related:

00 Episode#Hi Python Computer Vision — PIL! — An Intro To Python Imaging Library #PyVisionSeries

01 Episode# Jupyter-lab — Python — OpenCV — Image Processing Exercises #PyVisionSeries

02 Episode# OpenCV — Image Basics — Create Image From Scratch #PyVisionSeries

03 Episode# OpenCV — Morphological Operations — How To Erode, Dilate, Edge Detect w/ Gradient #PyVisionSeries

04 Episode# OpenCV — Histogram Equalization — HOW TO Equalize Histograms Of Images — #PyVisionSeries

05 Episode# OpenCV — OpenCV — Resize an Image — How To Resize Without Distortion

07 Episode# YOLO — Object Detection — The state of the art in object detection Framework!

08 Episode# OpenCV — HaashCascate — Object Detection — Viola–Jones object detection framework — #PyVisionSeries

--

--

J3
Jungletronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!