10.6: Pixel Neighbors - Processing Tutorial
-
0:02 - 0:03Ok, so here's another important aspect
-
0:03 - 0:05about image processing that we left out
-
0:05 - 0:07in the previous video.
-
0:07 - 0:08(clears throat)
-
0:08 - 0:09So what did we do?
-
0:09 - 0:12We had, an image of a frog
-
0:12 - 0:16we processed every single pixel and we
-
0:16 - 0:22copied that pixel to our processing display
window and maybe we manipulated it while -
0:22 - 0:25copying it, we made it brighter
we changed it's color, we did all sorts of things. -
0:26 - 0:30This is, I would say, pixel point processing.
-
0:30 - 0:33What we are doing is there's a one to one
-
0:33 - 0:35relationship, for this pixel
-
0:36 - 0:38change this pixel
-
0:38 - 0:39for the next pixel, change this pixel
-
0:40 - 0:41for the next pixel, change the next pixel.
-
0:42 - 0:45However, most sophisticated image processing
-
0:45 - 0:47algorithms that you might find in
-
0:47 - 0:48not to keep using photoshop as an example
-
0:48 - 0:51photoshop or a ** image processing.
-
0:51 - 0:54actually process goups of pixels
-
0:54 - 0:55for example,
-
0:55 - 0:58let's say this is my frog
-
0:58 - 0:59pixel
-
1:00 - 1:01my frog image
-
1:01 - 1:03and this here is my processing window,
-
1:04 - 1:06and let's say this is the pixel I want to
-
1:06 - 1:08set here in my processing window.
-
1:08 - 1:11What if inorder to set this pixel
I actually -
1:11 - 1:15used a whole bunch of neighbouring pixels
-
1:15 - 1:17around that pixel, so that pixel
-
1:17 - 1:18is over here
-
1:18 - 1:22I don't know what am drawing here exactly
umm but I actually took all of the -
1:22 - 1:27pixels in five by five matrix around it and
this is the roo.. the color of this pixel -
1:27 - 1:30is a function of all of these pixels
combined. -
1:30 - 1:34Ahh aah, a classic image processing
-
1:34 - 1:35algorithm that you might
-
1:35 - 1:36have used before is a blur.
-
1:36 - 1:38What if you take a pic.. an image
-
1:38 - 1:40and blur it making it fuzzier,
-
1:40 - 1:43less sharp, less in focus.
-
1:43 - 1:46Well actually if you average all of the pixels
-
1:46 - 1:47of an area
-
1:47 - 1:49to set a particular pixel, that's a
-
1:49 - 1:51blur algorithm.
-
1:51 - 1:53It is making each pixel
-
1:53 - 1:54more like it's neighbours
-
1:54 - 1:57almost ahh bluring it, averaging it,
-
1:57 - 1:58smoothing it between pixels.
-
1:58 - 2:00So this is a actually an algorithm
-
2:00 - 2:01and sharpening it is the opposite
-
2:01 - 2:03taking each pixel and making it more
-
2:03 - 2:04different than it's neighbours.
-
2:05 - 2:09Umm another example
of an algorithm is finding the edges -
2:09 - 2:13in an image.
So if I have a silhouette of a person -
2:13 - 2:14(chuckles)
-
2:14 - 2:15this looks nothing like a person
-
2:15 - 2:16and I don't know..
-
2:16 - 2:17some weird ghost alien thing
-
2:17 - 2:20and I wanna find the edges of this person
-
2:20 - 2:22well let's say this person was wearing
-
2:22 - 2:24a black shirt,
-
2:24 - 2:26much like the.. my black shirt here
-
2:26 - 2:27how would I find the edges?
-
2:27 - 2:28Well, if this is
-
2:28 - 2:30if you're looking at an image of me
-
2:30 - 2:31the pixels that are very different
-
2:31 - 2:33the white pixels and these black pixels
-
2:33 - 2:35a pixel that's very different
-
2:35 - 2:37from it's neighbours is an edge right?
-
2:37 - 2:37(finger taps his microphone twice)
-
2:37 - 2:39this pixel over here is very similar to
-
2:39 - 2:40all it's neighbours.
-
2:40 - 2:41This pixel right here is quite different
-
2:41 - 2:43than it's neighbours it must be
-
2:43 - 2:44on an edge.
-
2:44 - 2:45So, finding the edges of an image
-
2:45 - 2:47has to do with looking for pixels that
-
2:47 - 2:48are very different from their neighbours.
-
2:48 - 2:50Let's actually see if we can,
-
2:50 - 2:51implement this really really quickly
-
2:51 - 2:53in our frog example.
-
2:53 - 2:53(taps to switch cameras)
-
2:53 - 2:56So if I come over here, to the frog
-
2:56 - 3:01and if I look at this froooooog
-
3:01 - 3:03and what where we doing here?
-
3:03 - 3:05We were ahh kinda doing this threshold
-
3:05 - 3:07thing, that's where we last were.
-
3:07 - 3:10Well, let me say, let's aah
-
3:10 - 3:11take all this out and
-
3:11 - 3:13let's take all this out.
-
3:13 - 3:17Here is a particular pixel location,
-
3:17 - 3:19what if I want to look at this pixel
-
3:19 - 3:22relative to the pixel to it's right
-
3:22 - 3:24or to it's left, or above or below.
-
3:24 - 3:26Well, what will that pixel be this is
-
3:26 - 3:30location1 another location might be
-
3:30 - 3:35(x+1) times y times width
-
3:35 - 3:37and if you look at this what is
-
3:37 - 3:38the difference here?
-
3:38 - 3:42Now am saying, let me look at pixel x + y
-
3:42 - 3:45xy and let me look at pixel x+1, y
-
3:45 - 3:49right? Here ahh if am over here and then
-
3:49 - 3:50am in some image
-
3:50 - 3:53if this is pixel x - oh you can't see that.
-
3:53 - 3:58If this is pixel x, y then this right here
-
3:58 - 4:00right next to it is pixel x+1, y
-
4:00 - 4:02so ofcourse a more sophisticated algorithm
-
4:02 - 4:06migh look at x+1 and x-1 and y+1 and y-1
-
4:06 - 4:08x+2 and y+2 aloot of pixels
-
4:08 - 4:10in the neigboring area but just to
-
4:10 - 4:12start really simply let's look at this pixel
-
4:12 - 4:14and the one next to it.
-
4:14 - 4:14(taps to switch camera)
-
4:14 - 4:17So if I'm looking at this pixel and
-
4:17 - 4:19the one next to it, I can look at both
-
4:19 - 4:20of the brightness of both of those pixels.
-
4:20 - 4:24b1 equals frog.pixels[loc1];
-
4:24 - 4:29b2 equals frog.pixels[loc2];
-
4:29 - 4:32Aaah those cameras are always shutting off
-
4:32 - 4:33am gonna fix that in the middle
-
4:33 - 4:36of this video look I turned black
-
4:36 - 4:38for a second and am back
-
4:38 - 4:40and am just going to fix this one
-
4:40 - 4:41you'll have to bear with me, there's
-
4:41 - 4:43nothing I can do about this right now.
-
4:43 - 4:45ohhh come back (taps twice)
-
4:45 - 4:48Ok, am back I'l edit all that out later
-
4:48 - 4:52ok so now uhh I could get a
-
4:52 - 4:54difference which is maybe am just gonna
-
4:54 - 4:57say the absolute value of (b1-b2)
-
4:57 - 5:01and let's set the pixel of the window
-
5:01 - 5:04equal to that difference
-
5:04 - 5:08noow, oops loc1
-
5:08 - 5:10so loc1 is kind of my core original
-
5:10 - 5:13location so I wanna set that individual
-
5:13 - 5:15pixel but I wanna look at it as a function
-
5:15 - 5:17the value of that pixel as a function of
-
5:17 - 5:18two pixels that are next to each other
-
5:18 - 5:21let's run this and by the way
-
5:21 - 5:24we got this sad, very difficult, really
-
5:24 - 5:26traumatic array out of bounds exception
-
5:26 - 5:28this error is something that will happen
-
5:28 - 5:30to you as soon as you start doing any
-
5:30 - 5:32image processing work. What happened?
-
5:32 - 5:34I tried to look at, investigate,
-
5:34 - 5:36think about access a picel that doesn't
-
5:36 - 5:39exist, because at some point I was at a
-
5:39 - 5:40pixel that was all the way at the edge
-
5:40 - 5:42of my image and I tried to look at
-
5:42 - 5:43pixel one more to the edge
-
5:43 - 5:45which doesn't exist.
-
5:45 - 5:47So there's alot of strategies around this
-
5:47 - 5:48problem for right now am just going to
-
5:48 - 5:49do something which is kind of simple
-
5:49 - 5:51which is say let me just look at all the
-
5:51 - 5:52pixels all the way up to one before the
edge -
5:53 - 5:54and that will kind of like deal with this
-
5:54 - 5:55problem but you can think of other things
-
5:55 - 5:57you could have pixels wrap around
-
5:57 - 5:58there's lots of other ways you could
-
5:58 - 5:59approach this problem
-
5:59 - 6:00but now we can see
-
6:00 - 6:02you know this isn't the perfect
-
6:02 - 6:04demonstration but I've kinda really got
-
6:04 - 6:07something here the the frog by the way
-
6:07 - 6:10was had a lot of similar colors so am
-
6:10 - 6:12getting ummm umm
-
6:12 - 6:14actually am not exactly getting
-
6:14 - 6:16what I expected I guess the frog actually
-
6:16 - 6:18didn't have lots of similar colors it's
-
6:18 - 6:20very different cuz we're getting we're
-
6:20 - 6:22getting a very bright color everywhere
-
6:22 - 6:24there. I guess there's a big difference
-
6:24 - 6:25of all the pixels inside the frog
-
6:25 - 6:26and the background is very
-
6:26 - 6:28noisy so there's a couple of things
-
6:28 - 6:30we're noticing here; one - this isn't
-
6:30 - 6:32such a great algorithm am only looking
-
6:32 - 6:35at the pixels to the left coming to the
right and to the left if I looked at the -
6:35 - 6:37pixels above and below and diagonally
-
6:37 - 6:39I might be able to uhh determine
-
6:39 - 6:40alot more about the image
-
6:40 - 6:42the other thing is - this particular
-
6:42 - 6:44image has alot of noise in it
-
6:44 - 6:46so I'm am there's so much noise that
-
6:46 - 6:48am not really getting accurate edges
-
6:48 - 6:50maybe blurring the image first and then
-
6:50 - 6:53looking at it looking to the edges might
help, but in the end am actually -
6:53 - 6:54visually able to see something here
-
6:54 - 6:56but this wasn't the exact demonstration
-
6:56 - 6:58I was hoping for but uhh
-
6:58 - 7:00to.. look at this, maybe try to
-
7:00 - 7:02oohhh I know what the problem is
-
7:02 - 7:04huuuuuh (sighs deeply)
-
7:04 - 7:05am gonna have to re-record this video
-
7:05 - 7:08but what did I just do here?
I did the thing that I did originally -
7:08 - 7:12which is just I looked at the arbitrary
difference between the giant integer value -
7:12 - 7:15you're probably all just watching this
like yelling at the screen like you're -
7:15 - 7:17doing it wrong, what I wanted to do was
-
7:17 - 7:18look at the brightness of each one of
-
7:18 - 7:20this pixels just forgot like I wanna
-
7:20 - 7:22compare the brightness of each one of
-
7:22 - 7:24these pixels. This is gonna give us
-
7:24 - 7:27something much much more umm
-
7:27 - 7:30oh yeah and it's very hard to see here
-
7:30 - 7:32but actually this really worked.
-
7:32 - 7:34I'm really getting the edges I'm really
-
7:34 - 7:35getting the edges cause the edges of
-
7:35 - 7:38the frog that's where the pixels are most
-
7:38 - 7:39different and infact if I want
-
7:39 - 7:43to be a bit more thoughtful about this
-
7:43 - 7:45I might just come up with some threshold
-
7:45 - 7:48like if the pixel values are at all
-
7:48 - 7:50different then,
-
7:50 - 7:56draw black otherwise draw white
-
7:56 - 7:58and now if I run this, we can see
-
7:58 - 7:59aah I'm really starting to see the
-
7:59 - 8:01contours of this frog. I think this could
-
8:01 - 8:03be a better demonstration. So here
-
8:03 - 8:05we're seeing just a really basic
-
8:05 - 8:07algorithm for looking at the comparison
-
8:07 - 8:10between two pixels and finding the edges
-
8:10 - 8:13now again this was a very simplistic
-
8:13 - 8:15approach most of the time what you wanna
-
8:15 - 8:18do wooah haha all that work and this
-
8:18 - 8:20camera is not even on umm most of
-
8:20 - 8:21the time what you wanna do is look
-
8:21 - 8:24at a whole selection of pixels and in fact
-
8:24 - 8:25this is something that you might not
-
8:25 - 8:27be aware of this is right there bring up
-
8:27 - 8:29photoshop for a second if I go to
-
8:29 - 8:31photoshop and I've got my frog loaded
-
8:31 - 8:35in here and I go to filter ahh ahh ah
-
8:35 - 8:39other custom what I dont..
-
8:40 - 8:41what your actually seeing here
-
8:41 - 8:43is an and this is hard for you to see
-
8:43 - 8:46is this are the weights of a pixel
-
8:46 - 8:48If I wanna make a pixel on the center
-
8:48 - 8:50much more important than the ones in
-
8:50 - 8:52the area, that's a sharpening.
-
8:52 - 8:55I want the pixel to be more different
-
8:55 - 8:56than it's neighbours I actually ahh
-
8:56 - 9:00repr.. ahh oops I created very quickly a
-
9:00 - 9:02blur and you can see here
-
9:02 - 9:05this this would be a blur, what if
-
9:05 - 9:07I take all the pixels in a huge neighbour
-
9:07 - 9:09space, add them all together
-
9:09 - 9:11divide them by 25 as an average
-
9:11 - 9:13and you can see here that this
-
9:13 - 9:15umm frog is now blurred am gonna uncheck
-
9:15 - 9:18the preview let me kind of zoom in here
-
9:18 - 9:22umm you can see ahh over here
-
9:22 - 9:24look over here, that frog is blurred
-
9:24 - 9:26that frog is not blurred so this
-
9:26 - 9:28particular algorithm is blurring that
-
9:28 - 9:31image by adding all the pixels together
-
9:31 - 9:33and infact umm you know am not
-
9:33 - 9:35gonna go through the code for this
-
9:35 - 9:39in detail but we can look at this
-
9:39 - 9:42right here so if I look at this particular
-
9:42 - 9:46example this this particular example you can
-
9:46 - 9:49see here if I zoom in to it that the
-
9:49 - 9:52pixels inside the rectangle are being
-
9:52 - 9:54blurred and the pixels outside are not
-
9:54 - 9:57you can see kinda all the arm above me as
-
9:57 - 9:58I move the rectangle over am kinda
-
9:58 - 10:00blurring out that pixel those pixels
-
10:00 - 10:03if I go back to the code, and I put in
-
10:03 - 10:08these weights this is actually
-
10:08 - 10:10sharpening, again I want the pixel
-
10:10 - 10:12on the center to substract the pixels
-
10:12 - 10:14around it to be more different than
-
10:14 - 10:16the pixels around it and if I run this
-
10:16 - 10:19this is a bit more obvious, we can see
-
10:19 - 10:21that this is me sharpening that image
-
10:21 - 10:23now there's alot of noise is happening
-
10:23 - 10:25here am very zoomed in but you can
-
10:25 - 10:27see how this is changing the
-
10:27 - 10:29quality of the pixels so comparing the
-
10:29 - 10:31pixels and its neighbours this idea of
-
10:31 - 10:34looking at a pixel and looking at the
-
10:34 - 10:35ones that are right of it or above or
-
10:35 - 10:37below is an important powerful
-
10:37 - 10:39technique in image processing
-
10:39 - 10:41and we can just you know this video
-
10:41 - 10:42can go on for hours and hours and
-
10:42 - 10:44look at every image processing
-
10:44 - 10:45algorithm that photoshop uses
-
10:45 - 10:47that anyone uses and we can see this
-
10:47 - 10:49technique in alot of them. I guess
-
10:49 - 10:51what am saying here is see what you can
-
10:51 - 10:52do with this idea.
-
10:52 - 10:57What if you umm what if you ahh umm try
-
10:57 - 11:00to recreate this edge detection algorithm
-
11:00 - 11:01but actually use more than just the two
-
11:01 - 11:03pixels that are to the right and left
-
11:03 - 11:04what if you use the pixels above or down
-
11:04 - 11:06what if you actually were able to
-
11:06 - 11:08interactly select whether you're looking
-
11:08 - 11:10at the comparison of vertical pixels
-
11:10 - 11:11or horizontal pixels there's lots of
-
11:11 - 11:13possibilities you might explore and try
-
11:13 - 11:15here and actually something that I
-
11:15 - 11:17didn't do which I think will be
-
11:17 - 11:18really interesting to see which I
-
11:18 - 11:19would like to maybe add to another
-
11:19 - 11:20video at some point and I.. think of it
-
11:20 - 11:22as what happens
-
11:23 - 11:25when we're processing the pixels
-
11:25 - 11:28this pixel goes here this pixel goes here
-
11:28 - 11:30what if I start to move the pixel around?
-
11:30 - 11:33what if I take, what if every time I look
-
11:33 - 11:35at a pixel I actually offset put it in
-
11:35 - 11:37some like random location near where
-
11:37 - 11:39it originally was this will actually give
-
11:39 - 11:41me almost llike a watery effect because
-
11:41 - 11:42the pixels start to like look like
-
11:42 - 11:45they're dispersing or not. This this is an
-
11:45 - 11:47idea that I'd love to demonstrate
-
11:47 - 11:49so I think this video was already quite
-
11:49 - 11:50loong so am not gonna do it here umm
-
11:50 - 11:52but you can think of this as an excercise
-
11:52 - 11:54and I'll try to add one in at some point
-
11:54 - 11:55too that does this.
-
11:55 - 11:56So here are the things that are missing
-
11:56 - 11:59umm am gonna upload these so if you're
-
11:59 - 12:00watching these in the first pass
-
12:00 - 12:02this is where it's gonna stop
-
12:02 - 12:04but what I wanna get to in the next set
-
12:04 - 12:05of videos, number one I wanna look at
-
12:05 - 12:07moving the pixels around which will
-
12:07 - 12:09also be relevant to the idea of what
-
12:09 - 12:12happens if we just sort of like forget
-
12:12 - 12:14about this way of doing things entirely
-
12:14 - 12:16it's like this one to one pixel idea
-
12:16 - 12:18what if I just have a system where am
-
12:18 - 12:21drawing you know patterns and shapes
-
12:21 - 12:23to the screen maybe I draw grid of
-
12:23 - 12:24rectangles or I draw random circles
-
12:24 - 12:27everywhere or I draw swirls swirly spirals
-
12:27 - 12:29all over the screen what if just use an
-
12:29 - 12:32image essentially a database of color
-
12:32 - 12:33so what if I could like look up colors
-
12:33 - 12:35doing form a drawing algorithm
-
12:35 - 12:37create a painting for an image
-
12:37 - 12:38that's one thing I'm gonna look at
-
12:38 - 12:41and once we've done that, the next piece
-
12:41 - 12:42that I wanna look at is what happens
-
12:42 - 12:44when this images aren't static
-
12:44 - 12:46what if I'm getting images from a camera
-
12:46 - 12:49that are changing live real time images or
-
12:49 - 12:51images from a movie file.
-
12:51 - 12:53So those are the I guess there's like
-
12:53 - 12:55three more three/four more videos that
-
12:55 - 12:56need to come to kinda finish off
-
12:56 - 12:57all of these concepts.
-
12:57 - 13:00Ok so send me your feedback, umm I'll
-
13:00 - 13:03be happy to add more things, delete
-
13:03 - 13:06things, redo things or just go away not
-
13:06 - 13:08come back. (laughs) Ok so have good..
-
13:08 - 13:10enjoy your morning, evening, night.
-
13:10 - 13:13I don't know when you're watching this
and you're just like eating some cereal -
13:13 - 13:16at home that's... something
you might be doing and -
13:16 - 13:18enjoy that cereal (laughs) talk to you
later.
- Title:
- 10.6: Pixel Neighbors - Processing Tutorial
- Description:
-
Book: Learning Processing A Beginner's Guide to Programming, Images,Animation, and Interaction
Chapter: 15
Official book website: http://learningprocessing.com/
Twitter: https://twitter.com/shiffman
This video covers how to compare pixels to its neighbors for the purpose of image processing.
This video needs links to source code examples!
This video needs links to other things mentioned!
Please write in the comments what is missing and what would be helpful! - Video Language:
- English
- Duration:
- 13:20
![]() |
Gideonamani Marress edited English subtitles for 10.6: Pixel Neighbors - Processing Tutorial | |
![]() |
Gideonamani Marress edited English subtitles for 10.6: Pixel Neighbors - Processing Tutorial | |
![]() |
Gideonamani Marress edited English subtitles for 10.6: Pixel Neighbors - Processing Tutorial | |
![]() |
Gideonamani Marress edited English subtitles for 10.6: Pixel Neighbors - Processing Tutorial | |
![]() |
Gideonamani Marress edited English subtitles for 10.6: Pixel Neighbors - Processing Tutorial | |
![]() |
Gideonamani Marress edited English subtitles for 10.6: Pixel Neighbors - Processing Tutorial | |
![]() |
Gideonamani Marress edited English subtitles for 10.6: Pixel Neighbors - Processing Tutorial | |
![]() |
Gideonamani Marress edited English subtitles for 10.6: Pixel Neighbors - Processing Tutorial |