10. OpenCV Values & Pixels

Опубликовано: 13 Март 2026
на канале: Study With Siva
No
0

Welcome back.
In the previous lesson, we talk about the terminology of image and image processing.
Now let's see some hands on stuff on image processing with open CV.
So let me open my command prompt and make sure you activate your virtual environment.
Since I'm in the installations folder, let me go back, which is ID, dot, dot, and you can go back
to my one open CV by again any one open CV.
Now let's open the Jupiter Notebook and we will work on all that stuff in the Jupiter Notebook.
Okay, let's type.
Jupiter Space Notebook.
And this will open the Jupiter Notebook.
We have successfully opened the Jupiter notebook and you can notice that we have a folder named Data,
and inside the data we have a couple of files that is flying underscore EPG and mail underscore 000281
and one video file is there.
We will work on this data.
Let's go back and open the Djibouti Notebook by click on New and Python three.Okay.
Now let me name the notebook as zero one and which is my values and pixels or pixels.
So here in this lesson, let's try to understand what is values or pixels.
In the previous lesson, we already look into the values of pixels, which are actually the values inside the image.
Usually for an eight bit image, the values of the pixels in the range from 0 to 2 to the power of n minus one.
And that's what we understand right now.
Here what I'll do, let me generate some values and try to render that in an image and see how exactly
we can able to get OC for that. Let's import numpy as nP.
And also a mad plot lib.
It is import mad plot lib dot pie plot as plot.
NumPy is a numerical python and math plot.
Lib is a visualization library.
Now let's execute this.
As we know in the previous lesson we discuss about the image and the range of values is between 0 to
2 to the power of n minus one.So for an eight bit image, the values could be in the range from 0 to 255.
So what I will do here is let me create an array.
In the range.
0 to 255 and the size of the array is 16 by 16.
Let me create this for that.
Let me take a R is equal to I'll use simple numpy which is r dot arrange that the one way we can create
the values in the range of 0 to 2 to the power of n minus one.
So what I will do 0 to 256 so that I can able to get the values from 0 to 286.
Now the step is equal to one.
And now let's print the array.
Now we can see that we have the list of values in the range of 0 to 255.
Now the next step is let me convert that into the 16 by 16 array.
So which is R is equal to R dot.
I can simply do the reshape and the shape I want here is 16 by 16.
Now let's print.
Aorta.And year ago, this is my 16 by 16 area, which is a two dimension area.
And in the previous lesson we talk about the any two dimension array is a grayscale image, right?
So, so this is a greyscale image and the values in the range from 0 to 255 and the lower the value
is black in color and the higher the value is white in color, maybe the middle values is pretty much
gray in color.
Let us visualize this and let's see how exactly we can able to get.
In order to visualize this array, we need to convert the array to and sign a bit because a bit image
is a data type of and sign advertiser.
So let me convert that into eight bit array.
Which is equal to a dot you can use as a type.
And now the data type could be a bit or unsigned 88 bit in diesel, which is on you and eight.
This will be my arm.
Now we can simply visualize this using the map plot lib here.
I can use this map plot lib and that I can simply visualize this.Let's visualize this using plt dot aim show and saying that I'm converting that into the image and x is an array I need to provide here which is a r underscore a bit.
And the next thing is a color map.
Usually that plot leap assumes that email is an odd GB array.
Since we are having the two dimensional array, so the color map will be the create.
And now let's execute this.
And here we go.
This is what an image what you're having with us.
What you can notice is that as the definition that lower, the values are darker and higher, the values
are white and color. That's what exactly which we have.
And you can notice that there is some small, small boxes or basically called pixels, and the values defines the color intensity.
Cool.
That is how we can generate an image.
All right.
What I'll do.Let me also remove the axes so that it will be much more clear which is built dot axes and I will put off.
And finally I'll put plt dot show.
So this is what my image.