So, in this matlab tutorial we're going
to do some basic exercises just to get you
working with image matrices and they're
going to be very similar to the
exercises we did for sound. So the first
exercise I want to do is how do we flip
and image upside down? I'm going to give
you a minute to think about that,
so please pause this video and then come
back when you have figured it out.
Ok, so, we want to flip an image. It's
going to be exactly the same as we did
for sound. So, if you recall sound was
stored in using different samples in
different rows, and essentially that's
what's happening with an image also.
Alright, so, the top of the image is the top
of the matrix and the bottom of the image
is the bottom of the matrix. So if we do
flipud, which stands for flip-up down, of
the image that we loaded and then we
imshow this image, we see the original
image flipped upside down.
So now here's something we couldn't do
with sound because sound is
one-dimensional, so you can only flip it
one way. Now let's suppose I want to flip
the image in the horizontal direction.
How would I do that? So I'm going to give
you a minute to think about that. Please
pause this video and then come back when
you figure it out.
Ok, so, if you remember when we were
talking about sound we looked at two
different kinds of flip. There was flipud
which flipped vertically, and fliplr
which flipped horizontally. So all we
have to do is call the other flip
function. I'm going to imshow this flipped
image, and then so this is the image
flipped horizontally.
And of course you could flip the image
both vertically and horizontally
to get this.
Ok,
so, now the next exercise we're going to
do involves working with color. So, I said
before that the third dimension in the
matrix are the red, green, and blue
channels of the color. So how can we
show this? So let's say I only
want to view the blue channel.
How can I visualize that? So,
I'm going to give you a minute to think
about this, please pause the video and
then come back once you've figured it out.
Ok, so, usually we say RGB because red is
the first component, green as a second
component, and blue is the third
component. So I'm going to assign the
original matrix a to a temporary
variable B. I want to view blue so what I
want to do is I'm going to set red and
green to 0. So how would I do that? I say
colon to select all of the rows, another
colon to select all of the columns, and
then I put a 1 because I want to set the
first channel which is red
to 0. I'm going to do the same for the
green channel, and so now only the blue
channel has values that are not zero. So
if I imshow B, now we see only the
blue components of the image. Alright, and so if I
imshowed
one of the other channels that was set
to zero, it's just pure black. So 0 is black,
it means no intensity at all.
So, next we're going to look at the green
channel. So I'm gonna set G = A;
G colon, colon, so I'm setting again
red to 0, but now I don't want to set
green to 0 I want to set blue to 0, so it's G
(:, :, 3) = 0; and imshow(G), so
here's the green channel. So it's a
little bit more intense, or it has a
higher intensity than the blue channel, we
can see visually. So now let's say we
want to view the red channel. So we're
going to do something very similar to be
above. So I don't want to set red to 0 iIwant
to set green to 0 which is the second channel, and
I want to set blue to 0 which is the third
channel. So imshow(R) and this is the
red channel. So one thing to notice is
that no matter which channel we look at,
we can still pretty much just view the
image. Now why is that? It's because every
color contains a red component, a green
component, and a blue component. So, when
you see colors think of them as sort of
a mixture of those three.