[No audio]
Consider this gray scale image. Now this
image is made of pixels, and this particular
one has 3 by 5, so it has 15
pixels. So it's quite a small image. Now
each pixel has a value, and that's what
defines the intensity of the gray color
for each pixel. So in reality, these are
numbers, but our computer display
shows them in a color format, which is
easy, readable by us humans. What I'm
trying to get is that programs use
numbers to store images, that the computer
display, or so all the screen converts these
numbers to colors. Python can also do
image processing, just like photoshop
does. Probably it cannot do all the cool
stuff that you can do with Photoshop.
But you can make use of Python to
automate things. For instance, we will be
using the image processing capabilities
of Python to detect faces from photos,
from images, and also detect moving
objects in videos as well. So videos are
made of images. So it's the same thing
basically, and Python stores and erase images
using arrays of numbers. For instance,
this image could be represented as you
know, a list of three other lists.
[No audio]
So three lists because we have three rows
there with pixels, and then in each of
the lists, you'd have like five numbers,
and so on, and so on, and the fifth, and
the same for the other two lists, we've
got five numbers, because we have five
columns, so five pixels for each row.
And that's an image for Python, and here
is where NumPy comes in handy. So while
you can represent images with the lists, as
we did here, this is not very efficient,
because for big images, all these occupy
lots of memory, and therefore, they slow
down operations on them. So this is sold
by NumPy, which is a library of Python
library that provides a multi
dimensional array object. So let me go
ahead and create this array object.
[No audio]
First of all, what you need to do is
you need to import numpy, and if you
haven installed Pandas, NumPy should have
been installed with Pandas, because
Pandas is based on NumPy. If you haven't
installed NumPy, just yet, just go ahead
and pip install numpy. And if for some
reason you have some problems on
Windows, then just go ahead, and as I've
showed you and find the pre-compiled Python
libraries, go to this side and then
search for NumPy, and figure out if
you're on a 3.5 version of Python that
just get that version, and then you
point to this file with pip install and
the name of the file. Great. Now I have
NumPy installed, so let's create this multi
dimensional object and store it in n
variable. That would be numpy.arange,
and let's say 27, execute that, and
print out, and so this is a numpy array.
That's how it is called, and this
particular one is not exactly a multi
dimensional array, because it only has
one dimension. So it's a plain, it's
like a plain list, a python list. But
still it's not exactly a list,
type, sorry. So it's a numpy n
dimensional array. It can have 1
dimensional, 2, or 3. So we have 1, 2, 3
and I'll show whole these scenarios. So that was
the 1 dimensional array, and if you
want to print it in a nice form, and that'd
be the array. Now
[No audio]
I'm just creating a
NumPy array using numbers on the fly
here. But normally you'd have to create
arrays from images, and we'll do that in
just a bit. So for now, let's create
some arrays manually. Now let's see what
2 dimensional arrays, reshape 3
by 9. So we already have this 1
dimensional array and we want to convert
it to a 2 dimensional array. If you
execute that, you get a 2 dimensional
array. So that's a 2 dimensional array
because it has 2 dimensions. So think
of it as this image file, we have 2
dimensions, vertical and horizontal.
Now, what's a 3 dimensional array?
Even though 3 dimensional arrays are
less frequently used, it's still good to
know about them. Anyhow, let me create a
3 dimensional array. I could say a
3 by 3 by 3, because you
know, you have 27 elements, so 3 by
3 by 3 gives you 27, and yep, that's a
3 dimensional array. Think of that
as a cube that has 3 dimensions. So
3 by 3 by 3, and
practically, you'll see that in just a
bit in this lecture, where do we deal
with 3 dimensional array. So bear
with me, and yeah, you are able to see
the similarities between a NumPy array
and plain python list of lists. So this
array here would be like a 2 dimensional
array, or if you like to call it like
that. Either the structure in the middle level
is different between Python lists and
NumPy arrays, and also NumPy arrays
allow you to make some more efficient
operations such as iteration between the
array items, and so on, and you can also
create NumPy array out of Python lists.
For instance, I'll get this list here,
and I'll create a new object and then points to
NumPy, and to convert all atleast to a
NumPy array, you'd want to use asarray
methods and then between the brackets goes
the object that you want to convert.
[No audio]
n and that's an array, which is almost exactly
like this one in here, and if you print
that you would be able to see the difference.
You know, they look exactly
the same. But they are not because this
is a list and this is a NumPy.
Alright, great. Let's move on. So that's
NumPy, and as I mentioned earlier, a NumPy
is a base library for all the libraries,
such as Pandas, and also OpenCV, which
is an image processing library. So
Pandas DataFrames are based on NumPy
arrays, and OpenCV objects are based on
NumPy arrays. So Pandas, what Pandas
does is, it just add some cool features in
there, and such as it adds, it gives
capabilities for having table headers,
and indexes, which you can have in
NumPy, because NumPy is meant to be a
more simple and in a more low level of
storing objects and doing operations. So
NumPy is a requirement for many
libraries, and yeah, let's stop this
lecture in here, and in the next
lecture, we will go straight ahead and
create a NumPy array out of our image in
here. So this image, we're going to see you there.