< Return to Video

Introduction to Digital Images

  • 0:00 - 0:05
    In this section, I wanna talk about how
    digital images work in the computer. So,
  • 0:05 - 0:10
    here I've got an example - an image of some
    yellow flowers and what we're gonna see is
  • 0:10 - 0:15
    that this looks like sort of an organic
    rounded whole thing. In the computer, it's
  • 0:15 - 0:20
    gonna come down to really just a lot of
    little numbers. So, how's that work? So
  • 0:20 - 0:25
    what I wanna do is focus on this upper
    left flower here. You'll see there's a
  • 0:25 - 0:30
    little green area with a little thing in
    the middle. So if I zoom in by a factor of
  • 0:30 - 0:35
    ten on just that square, it looks like
    this. So what you see is that the image is
  • 0:35 - 0:40
    made of these little square things. So
    these are called pixels. So each pixel is
  • 0:40 - 0:45
    square. They're quite small, so, you know,
    there's not an exact number for it but
  • 0:45 - 0:51
    maybe 100 pixels per inch. And each pixel
    shows just a single color, so it's just
  • 0:51 - 0:56
    locked as the square of a single color.
    And what's funny is if you, you look at it
  • 0:56 - 1:01
    here it looks kind of. Very artificial and
    hard edged, but because the pixel is so
  • 1:01 - 1:05
    small when you look at it here in the
    original image, you know just, it just
  • 1:05 - 1:10
    looks right. The eye doesn't, the pixels
    are small enough that you don't see those little
  • 1:10 - 1:14
    hard edges. So this is what an image looks
    like when you sort of zoom in and see the
  • 1:14 - 1:19
    parts. If you want to think about how many
    pixels there are in an image, it's just a
  • 1:19 - 1:24
    question of multiplication. So if I had an
    image that was 800 pixels wide by 600
  • 1:24 - 1:28
    pixels high it's just a question of
    multiplying. So I multiply those two, and
  • 1:28 - 1:33
    that's 480,000 pixels. You may have heard
    the term megapixel. Is commonly used for
  • 1:33 - 1:37
    computers and cameras and things. So, a
    megapixel is a million pixels. So, my
  • 1:37 - 1:41
    800x600 image, 480,000. Well, that's about
    half a megapixel, roughly speaking.
  • 1:41 - 1:46
    So that's not a very big
    image, by modern standards. A digital
  • 1:46 - 1:50
    camera today, even on a phone usually
    would produce an image on the order of
  • 1:50 - 1:54
    five megapixels, ten megapixels, maybe
    twenty megapixels. That would be a pretty
  • 1:54 - 1:59
    big image. All right, so let's see
    how, how this thing works. So I've made a.
  • 1:59 - 2:04
    Just to make it a little more crisp I made
    this diagram. So if I have an image I can
  • 2:04 - 2:09
    think of it really as this grid of pixels.
    So each pixel is a square and it's just
  • 2:09 - 2:14
    showing a single color. Now we're gonna
    have an addressing scheme to sort of
  • 2:14 - 2:19
    identify each pixel as opposed to all the
    others. So the way that works is that we have a
  • 2:19 - 2:24
    set of x numbers along the top here. So
    zero is the far left and then it goes up,
  • 2:24 - 2:28
    goes to the right. And then the y-direction is done in sort of a unique way.
  • 2:28 - 2:33
    So zero is the very top, the top row, and
    then the y numbers read down. And that's
  • 2:33 - 2:38
    just historically how, how things are
    numbered in the computer. So I can just do
  • 2:38 - 2:44
    some simple examples. So for example, the,
    the, the upper left pixel is at (0,0). Or
  • 2:44 - 2:48
    x=0, y=0, I can say. The
    pixel one to its right, so this pixel here
  • 2:48 - 2:53
    is at x=1, y=0. And a
    lot of times if I say the coordinate, the
  • 2:53 - 2:57
    convention is to just say the x number and
    then the y number. So I would say, this is
  • 2:57 - 3:02
    (1,0). And let's say, this pixel over
    here. Well, you can kinda read up. It's at
  • 3:02 - 3:06
    x=4, y=2. Or I could just say (4,2).
    Now, in reality, we're not gonna get into
  • 3:06 - 3:11
    a lot of detail of messing around with
    these x-y numbers to identify specific
  • 3:11 - 3:16
    pixels. You just need to appreciate that
    there is this scheme. So even if we
  • 3:16 - 3:20
    had ten million pixels, any particular
    pixel has some x-y number that addresses
  • 3:20 - 3:25
    it, versus, all the other pixels. So, the
    question is. Well I've got these pixels,
  • 3:25 - 3:30
    how do I encode what the color is of
    any particular pixel? And so to talk about
  • 3:30 - 3:35
    that, I'm going to make a brief historical
    side-trip. So Newton had this famous
  • 3:35 - 3:40
    experiment in the 1600s, where he had a -
    which I reproduced here - a prism which is
  • 3:40 - 3:46
    just a triangular piece of glass. And here
    white sunlight is coming in the left hand
  • 3:46 - 3:49
    side and the prism splits it. Into the
    spectrum of colors here, which I just,
  • 3:49 - 3:54
    projected onto a white piece of paper. So
    what this shows is that white light is not
  • 3:54 - 3:59
    some indivisible pure thing. Instead, it
    can be separated into these pure
  • 3:59 - 4:03
    constituent colors. And so this is the
    same thing that you would see with a
  • 4:03 - 4:08
    rainbow. So the colors are actually in a
    continuous spectrum. But we Newton
  • 4:08 - 4:13
    identified certain ones. You know gave
    them, gave them words. So it goes, this is
  • 4:13 - 4:18
    the famous sequence where it goes red on
    the side here, and then orange, and
  • 4:18 - 4:22
    yellow, and green. And finally blue,
    indigo and violet on the far side here.
  • 4:24 - 4:31
    So. In the computer. I want to think of
    these pure colors as kind of a palette.
  • 4:31 - 4:38
    And the scheme we're gonna use is to pick
    actually red, green and blue out of here.
  • 4:38 - 4:44
    And use those as sort of to, as
    constituents to build up any other color
  • 4:44 - 4:48
    we might want. So the, or, ultimately, you
    could think of it, here we have white
  • 4:48 - 4:52
    light coming in the left, and we get the
    constituents out here. You could think of
  • 4:52 - 4:56
    it as running it backwards. That if I took
    the constituent colors and ran them back
  • 4:56 - 5:00
    this way, I could get white light out. And
    then, physics is not exactly the same, but
  • 5:00 - 5:04
    this is a little bit suggestive of, of how
    we're gonna take the constituents and put
  • 5:04 - 5:09
    them together in the computer. Also there
    is kind of a funny thing about indigo
  • 5:09 - 5:13
    here. When Newton named these, right in
    between blue and violet we've got indigo,
  • 5:13 - 5:18
    and it seems like. Really? And to go like
    that we needed a separate word for that
  • 5:18 - 5:22
    and couldn't we just call that blue. And
    it's funny because that shows sorta what
  • 5:22 - 5:27
    it's like to live in the 1600s. Newton was
    believed in a certain amount of mysticism
  • 5:27 - 5:31
    things that we think of as not scientific
    and, at the time, there were seven known
  • 5:31 - 5:35
    planets and Newton felt like, well, the
    number of colors should sorta match up the
  • 5:35 - 5:40
    number of planets. And so I think he kinda
    forced indigo in there just to make the
  • 5:40 - 5:45
    numbers add up. All right. So, what I'm
    gonna do. Is work on the scheme to encode
  • 5:45 - 5:51
    a particular color called the RGB color
    scheme. RGB stands for red, green, blue.
  • 5:51 - 5:56
    And the way this works, or the, the
    question is, I want a way of encoding.
  • 5:56 - 6:02
    What each color is, inside of my, my grid
    there. And so in the RGB scheme, we're
  • 6:02 - 6:07
    gonna use pure red, green, and blue
    lights, and mixing those in different
  • 6:07 - 6:12
    combinations, form, be able to form any
    kind of color. And rather than try and
  • 6:12 - 6:18
    talk through this, really, this just demos
    very well. So I'm gonna go to this, RGB
  • 6:18 - 6:22
    explorer page. And this will allow me to
    demonstrate how this works. So the way
  • 6:22 - 6:26
    this works is, I've got this three sliders
    on the left here. So there is this one
  • 6:26 - 6:31
    controls the red light. And we're gonna
    number these. So, when the red is all the
  • 6:31 - 6:35
    way dark. We're gonna call that zero. And
    if I turn it all the way up to maximum.
  • 6:35 - 6:39
    We're gonna call that 255. And if you see
    it at the bottom actually, the it always
  • 6:39 - 6:44
    reads out what the numbers are for the
    sliders. So I got a red slider, and a
  • 6:44 - 6:48
    green slider for making green light and a
    blue slider for making blue light. And so
  • 6:48 - 6:53
    the strategy in the RGB scheme is
    that. Essentially you have these, these
  • 6:53 - 6:58
    three knobs that I can have I can vary the
    brightness of red, green and blue light.
  • 6:58 - 7:04
    And it turns out, you can make any color
    by combining just the right proportions of
  • 7:04 - 7:08
    red, green and blue. So. I'll show some examples.
    Well, so obviously if I wanna make red, I
  • 7:08 - 7:12
    would just turn red up all the way, and
    likewise if I wanna make green, I would
  • 7:12 - 7:16
    just turn green up all the way. If, now if
    you turn it all the way you get kind of a
  • 7:16 - 7:20
    bright version. If I want a darker
    green, well, I could start with green and,
  • 7:20 - 7:24
    and then just sort of turn it down. So
    that I get darker green. In this
  • 7:24 - 7:28
    way. Now really, the left-hand side here,
    the zero numbers represents black. So in a
  • 7:28 - 7:32
    sense what I'm doing is I'm taking green,
    I'm like, well I just sorta go closer to
  • 7:32 - 7:36
    black. And that's, that's dark green. So,
    the other end, if I wanna make white, this
  • 7:36 - 7:40
    is the case where I take red and I turn it
    all the way up. And green and blue and
  • 7:40 - 7:46
    turn them all, all the up, and that's how
    I get white. So all the numbers at 255,
  • 7:46 - 7:52
    that's white. And then turning them all
    the way down here, all at zero, that's
  • 7:52 - 7:56
    black. So let me show just a few
    combinations here. I think probably the
  • 7:56 - 8:01
    most interesting one is, is red plus
    green. So, if I turn red up, and I turn
  • 8:01 - 8:06
    green all the way up, what I get is
    yellow. And if I wanted to make maybe a
  • 8:06 - 8:11
    slightly darker yellow, well I can st,
    keep red and green sort of close to each
  • 8:11 - 8:15
    other, but just turn them both down a
    little bit, a little bit towards black,
  • 8:15 - 8:20
    and I get a darker yellow, or we'll go
    this way, we'll get an even darker yellow.
  • 8:20 - 8:25
    If I want to make orange. What I'm gonna
    do is I'm, I think of orange as being
  • 8:25 - 8:28
    like, well it's kinda like yellow but
    instead of red and green being similar,
  • 8:28 - 8:33
    the red is a little stronger. So I'll have
    red and green here and I'll just turn the
  • 8:33 - 8:37
    red up a little bit. And I'll turn the
    green down a bit. And we can get a nice
  • 8:37 - 8:41
    orange there, that's kind of a. Road cone
    color, kind of a nice orange. So this sort
  • 8:41 - 8:46
    of just gives you the flavor of how you
    can, you know, by tweaking things end up
  • 8:47 - 8:51
    making a lot of fun colors. Let's see,
    there was one other attempt I wanted to
  • 8:51 - 8:57
    do. Oh yeah, I'll make kind of a, a light
    green. So I'll, actually, let me show you
  • 8:57 - 9:01
    how to make a pastel yellow. So here
    I've got red and green turned up all the
  • 9:01 - 9:06
    way so I'm getting this very bright
    yellow. And so pastel you think of as
  • 9:06 - 9:10
    being kind of more diffuse, more sort of
    foggy. And so the way to do that is
  • 9:10 - 9:15
    actually I'm going to add in blue. So I'll
    turn the blue up to about 180, 185 here.
  • 9:15 - 9:19
    And as you can see, well it's still
    yellow, but it's kind of pastel, foggy.
  • 9:19 - 9:24
    And the way to think about that is like
    well, if I had all three of these all the
  • 9:24 - 9:28
    way at max, that was white. And so, by
    turning the blue up, I've sort of gone
  • 9:28 - 9:33
    towards white but instead of just pure
    white, by having the red and green a
  • 9:33 - 9:38
    little bit of the head of the blue, I end
    up with this yellow cast. Now the way this
  • 9:38 - 9:43
    is going to work for this class is, I'm,
    I'm not requiring that you have you know,
  • 9:43 - 9:47
    you can just plug there what the three
    numbers are for any particular color. It's
  • 9:47 - 9:52
    just that you under, you appreciate that
    there is this basic scheme to make colors
  • 9:52 - 9:57
    just by varying red, green, and blue.
    Let's see, there is just one other one I
  • 9:57 - 10:02
    want to show. So we did red, green,
    yellow, is important, and we'll do the
  • 10:02 - 10:07
    other combinations. So blue plus green you
    can actually see a kind of turquoise, kind
  • 10:07 - 10:13
    of makes sense sort of a blue green. And
    our last combination will be red plus
  • 10:13 - 10:18
    blue, so red plus blue you get a kind of a
    violet. Kind of makes sense does seem to
  • 10:18 - 10:23
    be a combination of red and blue. Alright,
    so let me go here back to our images. So
  • 10:23 - 10:29
    we've got this idea that you can take red,
    green, and blue light and mix them
  • 10:29 - 10:34
    together. And so what that means in terms
    of the image is that I've got all those
  • 10:34 - 10:40
    pixels, for every pixel is gonna have
    some color. And that color is gonna be
  • 10:40 - 10:45
    defined by red, green, blue levels. Or, in
    terms of numbers, what it means is,
  • 10:45 - 10:50
    basically, every pixel just has three
    numbers. So I could say, well, red is 250,
  • 10:50 - 10:56
    and green is 10, and, blue is 240. But, I
    mean, more likely, we were to say, oh
  • 10:56 - 11:01
    yeah. That pixel is (250, 10, 40). So, we tend
    to always use the order, the red number,
  • 11:01 - 11:08
    then the green number, then the blue
    number. So I can sort of refine my diagram
  • 11:08 - 11:14
    here. So, here's my grid of pixels. It's
    making up the image and we've got the x, y
  • 11:14 - 11:19
    like we had before and now. Essentially
    what, what's going on with each one of
  • 11:19 - 11:25
    these pixels is that there's each one has
    it's own three numbers. So, maybe this one
  • 11:25 - 11:31
    is (6, 250, 7) right, so 6 is very
    low; green 250, very high; blue 7 is
  • 11:31 - 11:38
    low. Basically green, right? The green
    number is very high and this pixel might
  • 11:38 - 11:42
    be a (241, 252, 23) so. Red and green are
    very high, blue is very low. Yeah, it's
  • 11:42 - 11:46
    basically some shade of yellow. I should
    say that when we take digital images in
  • 11:46 - 11:50
    the real world. Right, when I was playing
    with the sliders, well, I tended to have,
  • 11:50 - 11:54
    you know, either 255 or zero. In the real
    world, you always get some inter-,
  • 11:54 - 11:57
    intermediate number, like 237 or 26.
    Whatever, in they're, they're mixed
  • 11:57 - 12:01
    together to whatever, make whatever that
    particular shade is. So this is gonna be
  • 12:01 - 12:05
    our kinda working definition of an image
    for now. So we've got this big grid of
  • 12:05 - 12:09
    pixels. Every pixel just shows, each pixel
    shows one color. And that color is
  • 12:09 - 12:16
    completely captured by just three numbers.
    So kind of stepping back a little bit, we
  • 12:16 - 12:23
    started with you know, this whole, this
    whole image. And I've reduced it. To just
  • 12:23 - 12:28
    this grid that has a lot of numbers. And
    that's actually a very common theme in
  • 12:28 - 12:32
    computer science. You start off with a
    whole image, or a whole sounds, or a whole
  • 12:32 - 12:37
    encyclopedia or something. Which, as a
    human, we think of that as sort of this
  • 12:37 - 12:41
    organic whole. In the computer, inevitably,
    all that data, there's some organizational
  • 12:41 - 12:46
    scheme where it's structured down to just
    a lot of little numbers. That is how, that
  • 12:46 - 12:51
    is how it's gonna be represented in the
    computer. And, if we think of an operation
  • 12:51 - 12:55
    on the data, so if I wanted to take an
    image, and maybe make it a little lighter.
  • 12:55 - 12:59
    In the computer, we're gonna translate
    that into some operation on the numbers.
  • 12:59 - 13:03
    So, for example, for an image, if I wanted
    to make it a little lighter. Like, oh
  • 13:03 - 13:07
    jeez, we've got all these, red, green,
    blue numbers. Maybe what I could do is
  • 13:07 - 13:11
    just go through and add ten to each one.
    And if you think back to the RGB explorer,
  • 13:11 - 13:15
    I'm gonna shift each one a little bit to
    the right, just make it a little big
  • 13:15 - 13:19
    lighter. Anyway, that's gonna be, a few
    sections from now. But the, the general
  • 13:19 - 13:23
    them that in the computer, [inaudible] a
    lot of little numbers, and that's kinda,
  • 13:23 - 13:27
    that's what the computer domain looks
    like. That is, that is certainly something
  • 13:27 - 13:28
    we'll be seeing a lot of.
Title:
Introduction to Digital Images
Video Language:
English

English subtitles

Revisions