Podcast Lookup

Image Processing

Programming Throwdown

  • March 26, 2013
  • 1 h 7 min
  • Episode 26
Episode page
About this episodeThis show covers Image Processing, techniques for manipulating images and extracting other useful information from them. Tools of the…

This show covers Image Processing, techniques for manipulating images and extracting other useful information from them. Tools of the show: Moon+ Reader Pro and Spaceteam. Books of the show: Do Androids Dream of Electric Sheep? (Kindle: http://amzn.to/14mk17G ), (Paperback: http://amzn.to/XamtLA) and Foundation (Kindle: http://amzn.to/XamMWD), (Paperback: http://amzn.to/WUb1Cg)

★ Support this podcast on Patreon ★

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

Image Processing

00:00—
  1. A

    Hosting provided by Host Tornado. They offer website hosting packages, dedicated servers, and VPS solutions: HostTornado.net. Programming Throwdown, episode 26: Image Processing. Take it away, Patrick. All right.

  2. B

    I never know who's going to open the show. Then Jason just starts talking. We record that part like ten times.

  3. A

    We both breathe in. We go, and then whoever says it first. See? I beat you.

  4. B

    First, I want to talk about a new website. Actually, this is much, much belated, and I owe my apologies. My brother was nice enough to buy us ProgrammingThrowdown.com for Christmas. Pretty awesome. He actually built a little website there. You guys can check that out: ProgrammingThrowdown.com. Yeah. That's spelled—no, I'm not going to spell it. It's too long. Google it. ProgrammingThrowdown.com. And so that's going to be our new website. We're going to start talking about that instead of our Blogspot, ProgrammingThrowdown.blogspot.com. That's too long.

  5. A

    Yeah. We removed Blogspot. We—efficiency. We dissected it. Okay.

  6. B

    We saved you a bunch of typing. Congratulations. So anyways, you guys can check that out, and hopefully that'll be good for us. So on to the news.

  7. A

    Yeah.

  8. B

    So when we're recording this, the big news has been SimCity.

  9. A

    Oh my gosh. What a fail, man. So I've heard various things. Wait, but

  10. B

    I've heard people saying, like, it's addictive. Like, oh, you shouldn't play this because you'll lose, like, hours and hours and days of your lives. Yeah.

  11. A

    for the server to allow you to. Oh, no. I didn't mean it's that good. But, yeah, what I've heard has been that basically, so there's two issues. There's a technical issue, which is that the servers have a very fixed number of people that they're allowing in. And so a lot of people just can't play the game after they bought it, which is kind of sad. Another issue is that they are doing microtransactions. So, you know, you kind of build your city up. Your people are pretty happy. All of a sudden, you know, Joe Brown wants to get from his residential district over into the city, and he needs a commuter train. What? Oh, that's going to be $2 of real money, right? So they've started this, you know, microtransactions, and it's just like League of Legends. You end up having to pay $500 if you want all the content or something. Oh, wow. Okay. League of Legends is

  12. B

    Pretty ridiculous. So the fundamental issue here, to describe it, is that they decided—the makers of SimCity decided that they wanted this to be an online game. So even though a large portion of SimCity has always been kind of focused on single player, and even this game largely is kind of a single player game, but you have interactions with other people's cities online, and then they want to do—they're saying that they do a lot of the processing online. Like, it wouldn't be possible. People are like, 'Oh, just make an offline version.' Like, this online version is terrible. And they're saying, like, 'Oh, but an online version is necessary because of the amount of modeling we want to do. Because we want to handle a lot of these things on our servers.'

  13. A

    Oh, I see.

  14. B

    That's great in a way—like, City in the cloud. But maybe that's not possible, right? Like, I mean, if it wasn't ready and they didn't kind of expect it. But it's also hard because at launch week, month, or whatever, everybody is going to be on at the same time. After that, people aren't going to be playing it as much, you know. There's going to be people drop off, and so it goes way down. So, when launching a product, this is a common issue, aside from the problems we can talk about SimCity. But when you launch, you have to balance this—you want to scale up. If you're going to have a really, really big launch, having a lot of servers, that's really expensive. And then you may not need them after that, right? And so, this balance of what is that? If you design for what peak capacity you can handle, you can't just make that infinite or you'll spend infinite money.

  15. A

    Yeah, exactly. Or even, you know, you should make it elastic, right? So they should have jumped on some Amazon Web Services or something like that where they could, you know, start off with a ton of servers, and as people dropped off, they could.

  16. B

    Probably is on Amazon. Well, I saw an article report. It kind of said it was connecting to Amazon servers. Oh, really? Yeah. So they'd already be doing that. Apparently not well. But yeah. So, do you think the world is ready? Like, I mean, I don't think this is going to be isolated, right? I think this is the wave of future games which are requiring online, not just for DRM, which is a big thing. Like, we've talked about that in the past. Like, 'Oh, what happens when the DRM server is down or not working or whatever?' But those are pretty relatively easy to alleviate most of the problems with, aside from the fundamental issue of DRM. Right? Like, you know, 'Oh, okay.' Eventually you could release a patch which disables the DRM if the server goes away. Whether or not they'll do that is the question. But in general, you can make it that, 'Oh, it only has to check the DRM every month or something,' right? Like, 'Oh, okay, fine.' But this—like, 'Oh, we're going to do a pair of processing. Like, a lot of the processing is happening in the cloud and you have a thin client in your house.' I mean, this is the dream of what 15, 20 years ago, right?

  17. A

    Yeah. Like, oh,

  18. B

    Everybody's going to have thin clients. Oh,

  19. A

    Yeah. We're all going to be connected to massive machines in the back end. There was a thing where you would play a PlayStation game over the internet without having a PlayStation. So there's OnLive, which does that. OnLive, that's right. But

  20. B

    That's not just PlayStation games. But yeah. So, I mean, this is becoming more and more of the future, right? Or you can look at even some of the products coming out, like Google with their Chromebook thing, right? Like, mostly Chromebook is a thin client. It doesn't do much except for run Chrome, and then it depends on all the Google services in the cloud. So I feel like this is the old is new again.

  21. A

    I wonder if they'll make a Minecraft kind of like this where everyone's playing in one huge world. Oh, that'd be pretty awesome. Griefing would

  22. B

    be your problem.

  23. A

    Oh, yeah, yeah. I'd just go in and flood your house every day.

  24. B

    But yeah, that would be interesting, right? But you would need a server to do that, right? Like, you would have to have, like, a legitimate, like, very scalable big server. Right.

  25. A

    Yeah, totally. That's interesting. We'll see. That'd be pretty awesome.

  26. B

    Internet connections aren't that reliable yet in general. And then you have overloading, right? So I'm not sure we're ready for this.

  27. A

    Yeah, this might be a little too forward thinking. So my news of the day is, news of the show is AngularStrap. And so AngularStrap is a wrapper that somebody wrote or a set of libraries that gives you Bootstrap functionality in AngularJS. And I'll explain all of this. Okay, good. Bootstrap is a set of JavaScript libraries written by Twitter—by Twitter for Twitter, but they open-sourced it so anyone can use it. And it handles a lot of things like modal dialogs. So, you know, if you're in the browser, you know, if you're writing some code for the browser and somebody, you know, clicks on login, and you want to give them sort of, like, what feels like a new login window that they can't get out of when they put in, you know, their username, password, and stuff like that. That's called a modal (M-O-D-A-L) dialog. And, you know, Angular Bootstrap has a way of just doing this. Like, you just say 'modal,' and then pass it some, you know, text and things like that, and it creates one for you. So Twitter has a lot of these libraries that do all sorts of really cool things. And then let's talk about AngularJS. AngularJS is what's called a reactive programming library. So it's pretty cool. You actually make these declarative statements like, you know, this section of the website will have the person's name. It's kind of like Prologue. I think we talked about Prologue in an earlier show. But you make a lot of these declarative statements. And then as you change variables, AngularJS sort of just does the right thing to make those declarative statements still true. So, for example, if you say, you know, take the person's username and put it here on the website. And the person's not logged in. They have no name. It'll just put empty string, right? But then as soon as Patrick logs in, it's going to put Patrick there. Like, you don't have to write any code saying, 'Oh, Patrick's logged in. Let's fill in the name.' It just does it, right? So AngularStrap is all of the Twitter cool, awesome UI Bootstrap library but written in AngularJS. So you can get the best of both worlds. And it's pretty freaking awesome. I have a link. You guys should definitely check it out if you want to do anything on the browser. So

  28. B

    Have you used this yet?

  29. A

    I have actually used both of these. I haven't used AngularStrap, but I've used AngularJS. And I've actually used Bootstrap with AngularJS where I had to do the glue part myself. Oh. Did you write this? No, I did not write AngularStrap. Well, technically I wrote, you know, 1% of it. But they don't know that. And they rewrote it. You should have open-sourced your 1%. Yeah, it's true. They are the 99%. They have done this work for you so you don't have to reinvent the wheel as I did. And it's definitely worth checking out. So be

  30. B

    Better than Jason and download this. Yeah,

  31. A

    Check this out. Do yourself a favor and do me a favor and check out AngularStrap.

  32. B

    All right. Well, time for Tool of the Show.

  33. A

    You're up first. All right. My Tool of the Show is I've been doing a lot of reading lately. Ever since we started Book of the Show, actually, I've been doing a lot more reading. I thought you were going

  34. B

    To say since kindergarten.

  35. A

    Yeah, since we did Book of the Show and Tell, I've been anyways. So I'm doing a lot of reading lately, both to, you know, have good books to share with you guys and also just because it's kind of fun. So to do this reading, I've used Moon Reader Pro, which is a pretty awesome Android app. I'll tell you guys about it. It synchronizes what page you're on with, well, actually, so if people are familiar with Google Reader, which we can, you know, download books from the Google Store, and then if you get the book on the tablet and the phone, and it keeps it in sync.

  36. B

    Because the Kindle Reader does this.

  37. A

    Oh, really? So if you read on the desktop, it'll keep your page. Yeah, so it

  38. B

    synchronizes what page you're on across your devices.

  39. A

    Yeah, yeah, yeah. So this does that, but for arbitrary PDFs, EPUBs, like any file format you want. So it's pretty amazing. Also, a really cool feature I like that Adobe Reader doesn't have is it'll let you invert the colors. So I really don't like black text on a white background when the device is lit. Like on a Kindle, it makes sense. But for a device that has an LCD panel, it really makes sense to have white text on black.

  40. B

    I don't think I've ever tried this.

  41. A

    Oh, man, you should totally try. So they have a free version, which is Moon Reader, not Pro, Moon Reader free. Try this out. Invert the colors. Read white text on black background. I guarantee you'll love it. And then this app was only, when I bought it, it was only, I think, $2. Do they have this on iOS? I don't know. We can check. But basically, it uses Dropbox, so you need a Dropbox account. And it actually synchronizes your books and what page you're on using Dropbox. So I'm assuming everyone has.

  42. B

    A brief search doesn't reveal that it looks like it's on iOS.

  43. A

    Oh, somewhere. But if you have an Android device, definitely get Moon Reader Pro. Best $2 you've ever spent.

  44. B

    Oh, best. Wow, that's lofty statements.

  45. A

    I know. That pack of gum has nothing on Moon Reader Pro. What about when you were so

  46. B

    dying of thirst in the desert, and that guy came by and sold you a bottle of water? He charged me $3.

  47. A

    Oh, okay. I know. It was brutal. But that was the best two-thirds of $3 I've ever spent. Okay,

  48. B

    Sorry. That was terrible. So mine's an Android. Mine will be iOS. But mine's not a utility.

  49. A

    You're the ying to my yang.

  50. B

    I used the tool very loosely. And it doesn't

  51. A

    have to actually

  52. B

    be. So this is Space Team. This is a game.

  53. A

    Okay.

  54. B

    This is not a single-player game. It's a multiplayer game, but it's local. I can't really show you because you don't have it. Or else we could play it. But then people would be like, 'What's going on?' So what this is is it simulates you and the other people in your room. You are together. You need to be together, and you're on the same Wi-Fi. And so it does a Wi-Fi link between your devices or whatever. And it simulates that you're all flying a spaceship. But your spaceship is having problems. Lots of problems. So that's kind of the theme, right? But in reality, what it is, is on your device, it gives you kind of a control panel with various different knobs or sliders or switches or push buttons or meters or whatever. And they're named very crazy things, right? So like the Discombobulator switch, the Amazingness slider—like names literally like this, right? And every person's device has different control pieces. Okay. So nobody's is the same. And then across the top of everybody's screen comes a different thing that needs to be done to continue flying the ship. But it may or may not be on your screen. So mine might say, 'Move the Pretty Meter to six.' Well, I look, I don't have pretty meter. So I have to shout, 'Somebody move the Pretty Meter to six!' Oh, but they don't know that they have to move. But they don't know because theirs says something else. Oh. And so I'm like, 'Move the Pretty Meter to six.' Move the Pretty Meter. And you're saying something at the same time. You're saying, 'Move the Moon Disk to seven.' Move the Moon Disk to seven. Or sometimes it's words like, 'Turn the Space Heater to Cold,' you know,

  55. A

    or something.

  56. B

    Like it could be anything, right? Like, and so you're all shouting different things. That's so good. And sometimes you don't realize you're shouting something that's actually you need to do. You'll hear somebody else, and you have to like acknowledge it so the person can stop. But you kind of know because it will go away. It's like a little timer. So like the longer you take—if you take too long, like your spaceship kind of has problems, right? So then eventually stuff begins to go wrong. So like the levels get harder. So if you keep going, like it'll stop being words and being symbols. So like instead of, it'll just be like this weird triangle with a circle around its symbol. Like 'Push that button.'

  57. A

    Move that. Yeah,

  58. B

    it's really, it gets harder, right? But then also if you do bad, your panels will break. So like green ooze might start coming down over the things and it's hard to see. Or they might start dangling down from their

  59. A

    screws and swinging back and forth. And you need to

  60. B

    kind of like pin them back in or try to tap them as they're swinging. That's so good. So this is like really crazy and fun. And you typically die like really quickly. But if you want to have like a blast, I recommend this for, you know, people who are not in an area which needs to be quiet. And, you know, everybody's kind of goofy and in the same mood. But as like a party game, this is a lot of fun.

  61. A

    Yeah, that's amazing. I'll have to check that out.

  62. B

    I forgot about that. But I had played that over Christmas with my family.

  63. A

    That was a lot of fun. But everybody else,

  64. B

    was like, 'What are you guys doing?' And the more people, it actually gets kind of harder because then it's like, but it's funnier because, you know, people are screaming. Anyways, I think it's free. So that's really

  65. A

    Good. Oh, wow.

  66. B

    And then I think you can buy like they have like additional features and missions and that kind of stuff or whatever. But I mean, for me, it was just kind of a good couple times to play it.

  67. A

    Yeah, it sounds amazing. I'm going to have to check this out. So it's not for Android. I just looked it up, unfortunately, but maybe there'll be a—maybe someone from someone in the audience can look for a Moonreader Pro for iOS variant and a Space Team for Android and we can be complete. There we go. All right. All right. So it's time for Book of the Show. Show, show, show, show. So my book of the show is The Android's Dream of Electric Sheep. I don't know, did I? Spoiler alert. No, I'm just kidding. I won't tell you. But it's by Philip K. Dick. And it was pretty good. Basically, it's about sort of this futuristic world where they can make androids so real that it's hard to distinguish them from people. And it sort of gets into this whole, you know, at what point is an android a person? And there's this person who's actually a bounty hunter who goes around killing androids that have sort of that have done certain things without spoiling too much. Let's say malfunctioned in a certain way. And along the way, he sort of starts to really care for these androids. And he realizes that they are starting to develop like human-like qualities. And it's a pretty cool book. I liked it. Thought it was pretty fun. And you guys should definitely check it out.

  68. B

    So this is the book that the Blade Runner movie was loosely based on.

  69. A

    That's right. If you've seen Blade Runner, supposedly, neither Patrick nor I have seen Blade Runner. I've seen parts

  70. B

    of it, like I'm familiar enough. I think it's like the general, like that same theme, like a bounty hunter who like is trying to determine if these things he finds are androids or humans. Right? This central theme and some other kind of sub-themes is shared. But the actual story, I believe, is quite different.

  71. A

    Like you're not

  72. B

    going to find the same scenes like, you know, from the book or not in the movie and vice versa. Oh, I see. That's kind of my understanding.

  73. A

    Yeah, yeah. It's pretty interesting. He administers a test to determine whether it's an android or a human. And the test by itself is kind of interesting. Yeah. I don't want to say anything because I feel like I'm going to spoil stuff. Yeah, we won't spoil it. Yeah, we're always worried about spoiling. We won't do that this time. But you guys should definitely check it out. I'm sure we've spoiled other things in the past.

  74. B

    So what is your book of the show? Mine is Foundation, Book one of the Foundation series by Isaac Asimov. So actually, now I was trying to look. I don't remember how many books are in the series. It's a

  75. A

    lot. So, yeah, there's actually three. But then it's sort of like Star Wars. It's exactly like Star Wars. Oh, is that what it is? Okay, so it's a trilogy. He wrote four through six and then he wrote one through three later. But you can actually skip one through three and still be okay. Oh,

  76. B

    I didn't know that's how it was. So I've read—I don't know how many books in this series. I think the trilogy, the first released trilogy or whatever. And then I've read various other books which are also in it. So I'm kind of confused now. I generally know the story arc but kind of not really. Gotcha. So it's confusing. But I haven't read them all. But I've read this book and I believe I remember what happens. This is a very intriguing science fiction book where it kind of goes under this idea of like—which is classical, and that it is actually true in history. That people tried to say if you could measure kind of like all the variables of something, could you predict what was happening in the future? Right? So if you had like some isolated system and you knew the measurement of everything, is like—is it deterministic or is it still like, oh, you don't know what's going to happen because there's some source of kind of randomness? Yeah. And so this is like a classic pursuit of philosophy, I guess. I don't know what exactly field it falls into. And so this kind of explores a notion of that where like if you could do this what's called psychohistory, so like measurements about society, could you come up with statistical models that say whether or not certain actions are likely? Gotcha. And so it's about this guy who is in the Galactic Empire, which is kind of like seen as this all good thing and has been ruling for like 12,000 years. And there's this guy who develops this psychohistory and begins to kind of understand that bad things are going to happen. And he's on a quest to try to stop it. And then without spoiling anything, I mean that happens like really early in the book is you essentially figure out that he's like, you know, maybe there isn't a way to stop it. So if there's not a way to stop it, is there a way to kind of like make it less worse? Right? And what steps would you do? And so he tries to make all these measurements and kind of take precautions to figure out what he would do. And that's what the book's about. But it's really interesting. I mean it's been around a while. So some of these themes—I never know this when I read books that are kind of older. Like if the themes in them were original to them or re-shared

  77. A

    or common? Yeah, I was wondering. Because like I

  78. B

    read other books and I'm like, oh, I've seen this before. I'll predict the outcome of the book. Yeah. And it's because like, oh, it's because this was the original source of that idea but has been rehashed so many other times.

  79. A

    Yeah. There was a movie with I think Nicolas Cage, right, where either him or his daughter or somebody could know what was going to happen. And he went to a plane crash before it happened. Is that a TV series or a movie? Yeah, I think I remember seeing this. Yeah,

  80. B

    he was seeing it. I didn't see the movie but I saw the previews.

  81. A

    Yeah, yeah. So this is a classic story, but this is—but maybe he was the origin of it. Yeah, this is the best incarnation of it. A lot of people have recommended this book. Okay, yeah.

  82. B

    Foundation by Isaac Asimov. It is good.

  83. A

    Isaac Asimov.

  84. B

    We're probably saying that wrong, but that's okay.

  85. A

    Yeah, poor guy. All right. So on to our discussion. Yeah, image processing. Image processing. Wait, did you?

  86. B

    Say this at the beginning in the lead-in? I don't remember now. I did. Maybe not.

  87. A

    Maybe this is a surprise. I think I did. Okay. Anyways, so we're talking about image processing, and it's pretty timely considering there's all this talk in Congress about drones and crazy—Oh, I didn't make that connection. I guess. Okay. Interesting. Oh, actually I posted in the Programming Throwdown community that we're going to be doing image processing. Oh, did you? Okay, good. Yeah, yeah. So people are

  88. B

    doing their pre-work.

  89. A

    Yeah, yeah. So people can ask us some questions even though it's one way. Wait, what? Okay, I don't know what that

  90. B

    —it doesn't make sense. Okay, anyways. So to talk about what image processing is from a high level—so I actually struggled with this. I was thinking like, oh, what's the best way to describe it? Because it kind of involves many related things in that they all start with an image, but you kind of—from there it goes into like whole fields which are kind of under the banner of image processing. So Wikipedia, I just stole what they wrote because I thought it was pretty good.

  91. A

    So they divided it—they did a really good

  92. B

    job. They divided it into three categories, which some of them I might name them different or maybe not, but it's as useful a categorization as any. Yep. So the first is image processing, just image processing. So this is—you start with an image and you get an image. Yep.

  93. A

    So for example, if you want to say blur an image, what you end up with is a blurred version of your original image, but you still end up with an image. It's just been transformed.

  94. B

    Right? Or you want to find—even higher levels, like I want to find—I want an image that shows me where the edges in the original image are. So things that basically produce some sort of image on the output that's been processed in some way from it. And maybe it's just the same image. Maybe that's like—oh,

  95. A

    Yeah. The ultimate process.

  96. B

    Okay. So the second one is image analysis.

  97. A

    Yep. So image analysis is where an image comes in and then some kind of measurements come out. So for example, maybe you're interested in what's called the edge density of the image. So what percentage of the pixels are edge pixels, right? So in this case, an image is coming in and just a number between zero and one is coming out. You might be interested in other things like, for example, the saturation of the image. You might be interested in how much contrast there is. Maybe you want to increase the gain based on what the image looks like. And so—yeah, but it doesn't have

  98. B

    to just be a single number, though. Like I put into here things like a histogram.

  99. A

    Oh,

  100. B

    Yeah. So a histogram is like you go—so let's talk about—oh, we actually—this is a good point to talk about this. So different kinds of image. So you might think immediately about like a color image, right? But a color image is really a case of black and white image, but you have three of them. Yeah. For a red one black and white, essentially one grayscale image, which—oh, man, I'm mixing up the terms. Okay, let's try. Okay. So let's start with this like a

  101. A

    simple case. Let's do image representation. Yes.

  102. B

    Image representation. Okay, go. You go first.

  103. A

    You have binary images, which means a pixel is either black or white. Wait, what's a pixel? You got to—I mean, we got to—okay. So you have a grid. Yeah, you have a grid of pixels. Each pixel represents some quantile of photons, or something, anything. Yeah, that's true. Image really can be anything. But if you're talking about an image that you took with a camera or something like that, each pixel—which is a lot

  104. B

    of discussion, but

  105. A

    go ahead. Each pixel is sort of, you know, a pool of photons over time. It's a measurement. It's just a measurement. Yeah. So you can have a binary image where each pixel is just a 1 or a 0. And that binary image could be a result of some threshold, some logic there, or who knows, right? You can also have a grayscale image, which means that each pixel is somewhere between completely white, which is usually represented as 1.0. Or if you're looking at an 8-bit number, this would be 255, the biggest number, right? Or a completely black, 0, or somewhere in between. So that's a grayscale image. A color image is actually represented as three channels. Three

  106. B

    grayscale images. Yeah,

  107. A

    three grays. So one way of doing it is RGB. This is what, you know, your computer monitor, for example, does. So your LCD panel actually has, you know, a red, a green, and a blue light right next to each other. Or actually, it seems to be an LED panel. But it would have a red, green, and blue light. They're very small right next to each other. And then by dialing each of those three in some combination, it can create any of the colors that you see on your LED TV. So you can actually, in image processing, you can take that apart and just look at the red channel, the green, or the blue channel. But it turns out that there actually are other ways to do this, too. One way is you can look at HSL, which is hue, saturation, and light. And there's kind of tradeoffs to doing these different techniques. Well, so, wow, we're getting a lot of tangents here. So,

  108. B

    I mean, there's, so RGB, red, green, blue, is the color. So because you can take red, green, and blue and represent any other color with some combination, if you have infinite adjustments in each of the three, you can represent any other color. So those three work. But there are other color spaces which also work. But even ones which are colors like cyan, magenta, and yellow. These ones also are, you know, colors that we see with our eyes. It's just another color. But they're, you know, also a mix of them can create. And so, like, that's useful depending on what your end result is going to be. You may want to do that because it's better for printing. So printing is typically done not with red, green, and blue as lights are, but with cyan, magenta, and yellow, and sometimes black. But that's just kind of like a bonus thing, but cyan, magenta, and yellow. And so, like, that's just, you can transform from one to the other. There's essentially a function which will map from one to the other for you. But then when Jason's talking about HSV, H and S and V aren't colors.

  109. A

    Right.

  110. B

    So you kind of change your mind around. It's three numbers, but they're not colors. But

  111. A

    they can still represent all the same colors as RGB.

  112. B

    But with those three values, you can represent any color. Right. But they're not colors themselves.

  113. A

    That's right. So let's talk about them briefly. So hue is actually effectively what color you want to display. So whether it's red, green, yellow, blue, et cetera, that's the hue. The value is the amount of light coming in. So as you increase the value, the pixel gets more and more close to white. And if the value is 100%, the hue doesn't even matter. The pixel is just going to be white. And then saturation is the hardest one to explain. And basically, I even have a hard time just even visualizing it. But the important thing about saturation is that it's sort of one of these things that stays relatively constant. So even as the light passes over an object, the saturation usually stays pretty much the same. And so HSV is actually used a lot of image processing because it has some really nice properties. Like, for example, if you want to do edge detection, you can do it just on the V channel. Right. And so that usually is pretty significant.

  114. B

    Or if you talk about, so

  115. A

    we're already kind of getting way off topic, but that's okay.

  116. B

    So if you want to talk about, like, oh, you want to do photo processing. So, like, I took pictures of my kid and I wanted to change it, right? So if you just are only able to edit the red, green, or blue, we call them channels, just meaning one of those sets of numbers, all the red, all the green, or all the blue together, that is limited in what you can do, right? So a single adjustment in that channel, like, multiply all the green values by, you know, 0.8, right? There's limited. I can't necessarily do all of the adjustments I want.

  117. A

    Right.

  118. B

    Versus if I had also the ability to edit the saturation value, right? That may mean altering all of the red, green, blue values, right? But I'm only having to alter one channel in the HSV image. So transferring between them can be interesting. So before we got off, we were talking about making measurements. So we have this grid of numbers. Like, let's just take a grayscale image and you have a bin and you want to say something about the image as an analysis. So you talked about, like, various measurements you want to take, but sometimes it's a series of measurements like histograms. So histogram is, like, not just images, but in general is used where you take a range and you make buckets. Yep. So if you had, so in a simple example, if your grayscale was 0 to 255, you could have 256 buckets. And then you just go through the image and every time you encounter a pixel, you take the value of that pixel and you increment the counter for that bucket by one.

  119. A

    Right.

  120. B

    Starting at zero and you count them all up. And then if you graph those numbers at the end, so for each bucket or just write them out, each bucket, how many you have, it gives you an idea of where the content in your scene is. Like, oh, it's really, really bright. Then, you know, you're going to have a lot of numbers in 253, 254, 255. If it's really, really dark, you might have a lot of zeros and ones. You know, and what you want to see there to best utilize the space of your image in some operations, you want to see that it's kind of level across the whole thing. Because that means you're using all of the possible numbers to the best of your ability.

  121. A

    Right. So to Patrick's point, if you have, say, a camera, what your camera is constantly doing is it's taking a histogram of the image that it's seeing at the moment. And if the histogram is, you know, completely dominated on the right side, so if almost all the numbers are white, you know, almost all the numbers are close to 1.0 or close to 255 and 8-bit, then your camera will actually lower the, I think, the exposure. Is that right? Well, it's complicated because there's a whole certain... Patrick goes a lot more about cameras than I do.

  122. B

    It'll try to make the image darker.

  123. A

    That's right. So the camera is constantly calculating the histogram and then, based on the results of that histogram, trying to allow less photons into the bucket next time around or more until the histogram falls somewhere in the middle. And so that's why when, let's say you have a camera or you're recording a video and you're in a dark room and then all of a sudden you walk out your front porch, boom, like everything's super bright and the camera just, all it sees is just this white flood. But then that histogram gets calculated and starts getting shifted over and then it starts to see, oh, you're on the street or something like that.

  124. B

    This brings up the reason for doing this, and this is something you run into over and over again in all the image processing, is that fundamentally you're trying to represent something which is, for most intensive purposes, infinite in scale. So, like, you know, there's... And you can have all the way from zero photons, which is black, black, you know, one photon up to, like, I don't even know, what is trillions of photons fall on a cell? Like, I don't know how

  125. A

    many photons... At some point you get blinded.

  126. B

    Like, you just... I mean, there's a huge scale, right? Like, it could be any number in there. And yet the camera's forced to kind of pick somewhere in there to say, you know, here's the darkest one I want to represent and here's the brightest one I want to represent. Right.

  127. A

    And your eye does the same thing, too. I

  128. B

    mean... By shrinking your iris or making it bigger, right? Like, your eyes dilate and contract, right? That is your eye trying to let less light in or more light in.

  129. A

    Yeah. So when it's a very dark room, your iris increases. And so this allows more photons to hit the part of your eye that's used for image processing. When it's very bright out, your pupils shrink. And then this causes less light to hit that spot. And so you're able to do sort of the same computation.

  130. B

    But it's fundamentally a limitation because we don't have eye sensors. We don't have sensors which can detect the whole scale. All the way down from zero photons (black), all the way up to whatever, surface of the sun (bright), right? Like, we don't have something that can hold that much data all at once. And even if you did, you run into another problem, which is what I want to bring up here. Say you're representing zero to 255. You only have 255 numbers to choose from. But yet, if you're inside a dim building, all of your numbers—if you try to represent, you know, black hole (black) and surface of the sun (white/bright). You know, if you try to represent all of those, all of your data might fall in just one number.

  131. A

    Right.

  132. B

    You know, because you have to adjust. And so a lot of the techniques you run into are people trying to do things to improve the fineness of the measurement. Because ultimately, once you take that measurement, that's it. You don't ever get more information, unlike CSI, where you can just say, 'Enhance.'

  133. A

    Oh, God. Enhance. Enhance, right? Once you take

  134. B

    an image, that's it. Like, you only have that data. Now, you can do things to make it look better or to pull more information. But ultimately, that's, like, once you take the image or you form the image, that's it. Yeah. So if you only have 255 values, you only have 255 values. So you've got to carefully choose what those map to.

  135. A

    Yeah. The CSI enhancing is hilarious. We watched a lot of those videos on YouTube. And yeah, it's just ridiculous. I saw one where the person actually saw the killer off a reflection off the victim's eyeball. So they were able to enhance off this person's eyeball—just one pixel—and somehow create a whole other image. And it just does not work that way. But there are two limitations. One limitation is the one Patrick talked about where, in the end, your values are distributed into these buckets. There's another limitation, which is that the pixel size—yeah, the resolution. So, you know, photons are collected in these buckets. And the buckets are, you know, dependent on your hardware. And then each bucket can represent one pixel. Or, you know, there's some cleverness that they do there. But for the most part, yeah, there's no way to increase the resolution once you've taken a picture. I mean, you can do some, you know, you can increase the size of the image and then try to interpolate the pixels that aren't there. But you'll never be able to enhance. Yeah, but you're not creating new information. Right? Right.

  136. B

    We should probably talk sometime about cameras. This is actually really fascinating, right? But to try to avoid that topic, yes, resolution. You have one measurement in space and then one measurement in essentially brightness, color, intensity, depending on what you're using. So the last one is image understanding. Yeah.

  137. A

    Yeah. And so this is where, you know, an image comes in and then what comes out is, you know, lion prairie or something like that. Right? So you actually take the image and you convert it. You transform the model from a model of pixels to, say, a model of text or maybe even a model in some other domain. So you can turn it from an image into... a thing. Some other thing. Yeah, exactly.

  138. B

    So this is... So interestingly, the way I think about this one is, and this maybe stuck with the way I took my courses at the university, but... So I thought it's funny. So when you do image understanding or image recognition or a lot of image processing, what you're doing is you're taking... Ultimately, you had the real world and you somehow captured it through a drawing, a painting, a, you know, digital camera, a video camera, whatever it may be, some sensor. You captured something, right? So you captured an approximation of the real world, right? And then when you do image processing, image recognition, you're trying to get back to a model of the real world.

  139. A

    Yeah.

  140. B

    Right? And so you're trying to take that approximation and get back and infer stuff about what happens. So when you look at a pretty picture on your screen and you do, you know, tweaking to it to try to make it look better, what you're trying to do is either make it look artistic or make it more like what your eyes saw there in the real world. Or in image recognition, you're trying to get back, like, 'I want a model that, like, I know that those pixels were a cat.' Okay, good. Like, good cat. Then you can go a step further. And once you have some sort of representation, you can do 3D graphics, which is taking a model and trying to get back to making an image. Right? Yeah. Which is kind of like, in my mind, that's like the pipeline. You have, like, real world, you know, some sort of sensor. And then you have image processing, trying to get to a model. And then 3D graphics is, like, taking the model and trying to get back to something that looks like what would have been taken with a sensor that would map back to the real world. Yeah.

  141. A

    Yeah. So, like, it's a... Or thinking about it in terms of your brain, you have photons that are hitting your eye. You have image processing in your brain that's turning it into different, you know, your brain actually does many different filters. And so it turns into, you know, an edge detection, you know, mask and then several other filters. And then it hits your neocortex, which is responsible to think, oh, this, you know, this crackle of energy is actually a lion, right? And then you dream and you recreate the lion in your dream. So it's kind of amazing. Yeah. So there's... So, yeah, those are the three big things: image processing, analysis, and understanding.

  142. B

    We're going to try to cover all of them at a high level.

  143. A

    Yeah, definitely. We

  144. B

    already did kind of, sort of.

  145. A

    Yeah. So images are really connected to matrices, which I think we did a show on MATLAB. Yeah. Yeah, we definitely did. So go back and check out that show if you're not familiar with matrices and matrix operations, things like that. But, in fact, a lot of image processing is done in MATLAB for this reason. So an image kind of fits naturally with a matrix because an image is just a 2D grid of values, and that's exactly what a matrix is.

  146. B

    Well, a grayscale one or binary would be. But then

  147. A

    A color would be... Oh, yeah, that's true.

  148. B

    A 3D matrix: at X by Y by layer,

  149. A

    number, channels,

  150. B

    Yeah.

  151. A

    Yeah. So, yeah, matrix math is really important for image processing.

  152. B

    So we talked a lot. We already started using things that may not be obvious with them. So we talked about, like, edge detection, or we talked about blurring. So these things which are kind of effects you do or operations you do on an image. Some people might call them effects. It depends on what your domain space is. But so if you take these operations, so kind of like the base of that is the convolution. Right? So matrix math itself, if you're talking about, like, linear algebra, is a lot more about, like, oh, inverse of a matrix and, you know, matrix multiplying, finding the determinant. Finding the determinant, these kinds of things. And you do those sometimes on small pieces of an image or something. But for a lot of image processing, you're not talking about that same kind of matrix math. Instead, you're talking about slightly different matrix math. And so one of those is the basic one is, like, an image convolution. So this is you have a big image. Let's say a whopping 20 by 20 image or 32 by 32. Let's take an old

  153. A

    icon. Oh, man.

  154. B

    32 by 32 image, right? And you want to blur what's there. So you want to take what's there and kind of average it into the things around it. Yeah. Right? So one thing is you could write, like, a little program that, like, so for the first pixel, look at all the pixels around me and take an average of that. Right? And then set that to the pixel I am. And then go to the next pixel and do the same thing. And you run into the problem, like, oh, you need two images, right? Because you need the image that's the input. Because you don't want to keep blurring against something you've already blurred. Right? Or you might cause problems. So you're transforming from one image to another. So you're kind of updating this in place. But the way they represent that in image processing is an image convolution where you take another matrix, so let's say a 3 by 3, and you put numbers in each of the cells. Yeah. Each of the cells of the matrix. And that represents what you want to, when you overlay that matrix in some portion of the original image matrix, you want to multiply that source pixel by this new value. So in the case of an average, if you had a 3 by 3, you'd want it to be 1 over 9. Right? So you want to take 1 over 9 times the pixel underneath me and do that for all 9 pixels, add them all up together, and then set the pixel where I'm currently at to that value. Yeah. And then go to the next pixel and do the same thing.

  155. A

    Yep. So the big difference between matrix multiplication and image convolution is with matrix multiplication, you know, if you remember, if you have, say, an X by Y matrix, you have to multiply it with another matrix that's a Y by Z matrix. So in other words, the number of columns in the matrix that you did on the left side of the operation has to be equal to the number of rows of the matrix on the right side. And you end up with what's called, this is known as the outer product of the two matrices, right? So in image convolution, it's totally different where you are basically, you're doing, you're taking a 3 by 3 window of the original matrix. And then you're doing the outer product, or the inner product, rather, of that and this convolution, what you call a convolution mask. This is what Patrick was talking about, the 1 over 9. So you take a small piece of the image, and you do an inner product between that and your mask. And then you take that result, and you put it back in where the center of that window was that you took out. And so you do that for all the possible windows you can cut into that image. And what you're left with is a new image with all new values.

  156. B

    So you can get more advanced, so this 3 by 3, 1/9 averaging thing, right, will produce something that looks a little bit like a blur. But it might not be pleasing because, for instance, pixel, like let's say it was bigger, a pixel that's far away is going to contribute exactly the same as a pixel that's really close to the center.

  157. A

    Right.

  158. B

    And that's a problem because that's probably not how blurs in physics really work. So, I mean, and if you want to try to model what would be in the physical world a blur, like looking through something that's blurry, you're going to end up with more what's called a Gaussian blur. So then there's something to tell you what numbers to stick in each one of the mask cells so that pixels far away contribute very little and pixels very close contribute a lot. Right? And this produces, you know, a more pleasing blur. And so you'll see even in Photoshop there's, you know, Gaussian blur this image. And it asks you questions. You know, what size of Gaussian blur do you want? What standard deviation of Gaussian blur do you want? Right? And all this affects how much the nearness or farness of pixels contribute to what the value of the destination pixel should be.

  159. A

    Yep. Yeah, there's a lot going on in image processing. It's a lot of heavy math, but it's also a lot of fun. It is.

  160. B

    So, I mean, the nice thing is you do something, well, with many of these, you do something and you get back some picture you can look at, right? Yeah. Or you get some answer out that's probably wrong, you know, cat and you want a dog or something. But, I mean, you get something back and especially the ones where you get an image out is really rewarding because you can tweak something and see what happened, right? Yeah. And so

  161. A

    we'll do a little bit of a tangent. We're actually going to do a two-part series on AI in the future. But for this episode, you know, there's also a lot of AI in image processing and we'll kind of gloss over that because we'll cover a lot of it in a future episode. But needless to say, you have to do a lot of AI. If you want to detect whether it's an image of a cat or a dog or neither, that's, you know, fundamentally artificial intelligence or a machine learning problem. So, often the way these techniques work is they convert the image into what's called a feature vector. So, imagine all those things that we talked about earlier, like the edge density, you know, histograms, a histogram of the edge. You can actually do an edge convolution and now you're left with an image where it's white where there's an edge and black where there isn't an edge. And it's gray where it's not really sure if there's an edge or not. You could take that image and then create histograms of that image. You know, is that image really bright? You know, is the histogram far to the right? If it is, then there's a lot of edges in this image. But it's better than having that histogram is more information than just having one number, right, as to like the edge density. So, you can take these edge density, these scalar values, you can take these histograms, do some convolutions, some more histograms. And you end up with just a ton of numbers, but each one sort of has more meaning than a single pixel in an image. So, a single pixel really doesn't tell a good story. But a lot of these features in the feature vector kind of tell a story about the image. So, many AI techniques will first do a lot of image processing and image analysis to create a feature vector. And then at that point, it just becomes a standard AI or machine learning problem. At that point, it doesn't even matter that you're using images because you've converted the image to some other representation. So, we'll get to more of that later. But that's why a lot of this image processing is so important is that it sets the groundwork for doing some of that other cool stuff.

  162. B

    Yeah, I guess that's because the first two things we talked about—image processing and image analysis—are really separate but linked together. And then they produce something which is further processed by some, like you said, general machine learning algorithm. But it's the fact that it came from a source that was an image that matters; that makes it image understanding, makes it image recognition.

  163. A

    One other part of image processing that's really important is—a lot of people say, 'Well, image processing, that's just AI, right?' But the reality is, your eye, so just from a physiological standpoint, your eye and the early parts of what's called your retinotopic map—the part of your brain that takes a signal from your eye and just does some basic things to it—that's kind of just the way it is because of biology. And so a lot of image processing is just about sort of capturing the way that biology made us how we are. For example, one common thing in image compression, which is a way to represent an image using very little data, less data. Yeah. By default, an image is, as we mentioned, a set of pixels. And you could just store a number, or I guess three numbers of its color, for every pixel. But this is a lot of numbers to have to store. So image compression involves sort of storing coefficients of a function. You might have some function that's very good at describing almost any image, as long as you set a couple of parameters right. And so image compression is about finding those cool functions and then, at that point, just using those coefficients for the function to represent the image. One trick to image compression is the fact that our eyes aren't very good at representing blue. So it turns out that light blue versus dark blue, our eyes just aren't good at distinguishing the two. If I gave you two shades of blue and they were very similar, you would have a hard time knowing that they were different. But red, on the other hand, we're actually very tuned for red—green. Green. Both red and green. Yeah. So I think it has to do with, like, predators or, you know, we have people hide. Actually, Patrick is right. Green is the one we're most tuned to. It has to do with, you know, predators are in the jungle, and we've been biologically, you know, evolved to be able to pick things out from the jungle, pick the lion out that's chasing after us. Like the ones that saw the lion in the jungle survived and the ones that didn't, those early humans died. And so what's left are people who are very tuned for green and red. So, you know, image processing, part of image compression is taking advantage of the way that our eyes and the way that our brains work. And so once you've captured a lot of that, then you can do, you know, AI, machine learning, cool stuff on top of it.

  164. B

    I think that's an interesting—there is an interesting point there that a lot of image processing is knowing what your ultimate goal is. So a lot of this is a field that's very ripe with applications because sure there may be—I'm sure there's theoretical stuff that goes on—but a lot of it you kind of relate back to something somebody's trying to do. Like, you're saying compression based on the human eye. Well, it depends on what you want to do with it, right? If you're trying to make certain kinds of measurements, you might not want that. You might want, you know, representing what a camera would see really, really well.

  165. A

    Because that's what

  166. B

    you're intending to do. You're going to use a camera to navigate a robot, right? And then so you want the

  167. A

    thing that measures

  168. B

    best the scene you're in versus acting most like a human.

  169. A

    Yeah, exactly. Just because humans aren't good at representing blue doesn't mean that drone, robot drone, should have the same handicap.

  170. B

    Right. So, I mean, but it's interesting because you kind of got to know that you want to do something better, but you need to have your end goal in mind to figure out what's the best way of doing that or any of these things. So, you know, even blurring. You might want to blur an image again to help on compression because you want to, you know, say, like, oh, I want to represent with less. So I'm going to kind of do like a little bit of a blur so that when I subsample the image, when I take only every other pixel, I know that I am not going to just completely lose what was in between. I get some of that data. But you might want to do a different blur for that than a blur that's just, you know, to make somebody's face look less blemished in a photograph. Right? When I'm going to send the picture to my mom, you know, like, oh, I want to apply this blur because it kind of makes the wrinkles look a little bit less noticed because they kind of blend in with the rest of the skin. Right? Yeah. And so that blur may be a very, very different blur than what you're trying to do when you're trying to do compression.

  171. A

    Yeah. Yeah, definitely. Yeah. So a big part of image processing is sort of deconstructing how our image system works. You know, many of the applications are sort of to either mimic a human or to augment a human's vision or to provide some information. Those are my

  172. B

    favorite, augmenting humans.

  173. A

    Augmenting a human in themselves. So there,

  174. B

    are a lot of common challenges across this, though. The first is that, I mean, everybody knows the whole megapixel race of cameras and just in general sensors and the data. But it's not just about how many pixels you are, but about the bit depth—is what it's called—of the pixels. So instead of using 256 values for every color, I want to use, you know, 1024 for every color. Or I want to use, you know, whatever some outrageously large amount of data to represent blue. So I want like a 16-bit image where every channel is 16 bits instead of just 8 bits. So I can represent that many more levels in my image. And then if that source data is better, all my further processing is going to be better. But every time you do this, you make your amount of—if you're going to do, for instance, convolution—the number of times you have to do convolution and the precision with which we have to do it just, you know, gets bigger and bigger. And you run into kind of a squared problem, right? So like if you increase each of the dimensions by two, you really made the size of the image go up by four. So, you know, this is like one of the fundamental issues with image processing: is that as your images get bigger and bigger, you have tons more processing that you have to do. And in a lot of applications, like in robots, a lot of image processing is done. You have a deadline. You can't just sit around chugging for five minutes saying, 'Please wait, please wait, please.' I mean, you have like—you have to get some answer about what is the robot seeing? What does the robot need to do? And so you need to be able to do these very large calculations very, very, very quickly.

  175. A

    Yeah. Yeah, definitely. Yeah. I mean, I think the amount of data is really staggering. I think that a lot of people find it kind of hard to appreciate. But I mean, one way to look at it is, you know, I was trying to look this up on the Internet, but it's not easy to find out. But there's so one thing I did find on there: there's about 100,000 words in the Oxford Dictionary. So there's 100,000 words that need to be defined, right? So let's say each definition was how many words would there be? Ten. Ten words in the definition. Okay. So there's a million words in the Oxford Dictionary. Like, if you were to count how many words in the dictionary—let's say the average word is three letters long—that's three million letters in the whole dictionary. So that is only what is the square root of three million? It's like, I don't know, 5,000 or something. The point I'm getting at is, yeah, it's about 5,000, maybe 5,500. So if you have an image that's 5,000 by 5,000 pixels—let's just say it's a grayscale image—in that image is enough data to hold the dictionary and all of its definitions, right? The entire dictionary. And people take pictures with 5,000 by 5,000 pixels nowadays; cameras can do that, modern cameras. That's not that big. Yeah.

  176. B

    Well, you said it was 3 million, right? Yeah. So that's 3 million. That's 3 megapixels. That's 3

  177. A

    megapixels. So every time you take a 3 megapixel picture, you're taking—you have enough information there to represent the entire Oxford Dictionary. Well, way more, because you're taking it

  178. B

    in color, and

  179. A

    you're taking it,

  180. B

    with higher bit depth than that.

  181. A

    Yeah, so think about the scale of the amount of data that you're processing that has to be processed. It's massive.

  182. B

    So it is really crazy because sometimes you go look at like, oh, an old text file—like, wow, is a really big, like I typed a lot of words in this doc file or this, you know, PDF or whatever, you know, LaTeX. Yeah. You know, oh, I typed a lot of words here. And then you go look at the size and it's like, what? It's so tiny, right? And like one image—one image, you know, will easily be, you know, 20, 30 megabytes, 40 megabytes. And that's with compression sometimes, you know. Yeah. And it's like, wow, like this is crazy. And then if you talk about video,

  183. A

    I talked about this.

  184. B

    So image processing plays a lot with video, but all video is—so aside from the compression parts of it—video is just, you know, some regular interval of pictures. Right? So you just have a camera that's taking pictures at some regular interval. So in case of like broadcast TV videos, 30 frames per second, 29.97 or whatever. Yeah, 29.97. But you have, you know, 30 times a second the camera is snapping a picture—snap a picture, snap a picture, snap a picture, snap a picture. Yeah. 30 times every second. You have 30 of these. And if you're going to process it in real time, quote unquote, that means to keep up, you need to process it in 1/30th of a second, right? Just really fast.

  185. A

    These images can be really big. Yeah, imagine you know, you're a production movie. They're filming a production movie, right? So that's easily going to be 3 megapixels because it's going to go on a huge TV screen. It's probably going to be many more than, much more than 3 megapixels.

  186. B

    I think it's, I think HDTV is about two, like 1080p is about like 2 megapixels. Yeah, but what would it be for a theater? So it's 1920 by 1080. I

  187. A

    mean, this would be a huge theater.

  188. B

    So it's like

  189. A

    4K by,

  190. B

    don't know. I don't know. It's huge. Let's

  191. A

    call it 10 megapixels. 10 megapixels. So, and you're recording 10, you're taking a 10 megapixel. So you're taking 30 10 megapixel pictures every second.

  192. B

    Well, movies are 24 frames per second.

  193. A

    Oh yeah, that's true. Okay, 24. So you're capturing. Well, old ones. New ones are different. Are they really?

  194. B

    Yeah. Well, this is the whole Hobbit thing. You

  195. A

    didn't come out. Okay. Let's skip this because this

  196. B

    is a tangent.

  197. A

    So you're taking 24 pictures, each picture holding more than the entire dictionary worth of data every second. So it's just a staggering amount of data. And only now, actually, that where we have the kind of computational power and the knowledge of distributed systems, things like that, are we able to sort of tackle videos and do the cool kind of things that we have been wanting to do.

  198. B

    Yeah. And still, it's hard. Like if you've ever done video processing on your computer.

  199. A

    Oh yeah, on one machine.

  200. B

    So like at first you're like, oh man, like I'm using this to edit this video and I'm trying to do trimming it or, you know, whatever, doing various things. You're like, why does it take so long? And then you export it. It's like, oh man, it's going to take an hour? Like what? It's a five-minute video. And you get kind of mad. But then you think about like Jason's trying to get us to get a little bit of understanding of how much data it's really, really got to go through. And you begin to kind of realize why it's taking that long, even on really fast modern hardware.

  201. A

    Yeah, definitely. So some other challenges of image processing besides handling all that data is that you are looking at an image. And depending, you know, there are the cases where you have video, but in many cases you're just looking at a single image. And so you might be at a frame where there's a lot of, say, what's called occlusion. So for example, you might be trying to build a person recognizer, a person detector. Like yes, if there's a person in this image, no, if there isn't. And your system does really well when it's head on. So if it's taking, you know, if you're taking a picture of your brother and he's just like smiling, standing next to a rock or something, it does a great job. What happens all of a sudden, your brother turns to his side. And then now, you know, you can't tell his arm is just on top of his shoulder in the picture. Right? And his other arm is completely occluded, which means a picture, because it's two-dimensional, it's sort of squished his arm behind his body. And you can't even tell it's there. So occlusion in image processing is a massive, massive problem. I mean, if your image processing algorithm detects humans by, say, looking for two eyes. Now, if the person turns to the side, one of their eyes is occluded. Now your image processing algorithm doesn't work anymore. Right? So occlusion and along the same lines, orientation. So, you know, even if something isn't occluded, you might look for two eyes and you might look for them to be around the same size. But if a person turns their head to the side 45 degrees, now one eye is bigger than the other. Right? And so your algorithm doesn't work.

  202. B

    So one eye appears bigger than the other.

  203. A

    Oh, that's right. Yeah. No, actually, it grows. Oh, that's creepy. As you turn your head to the side, your eye just bulges out. So these are huge problems to deal with.

  204. B

    Well, even if you manage to capture the ideal, you know, shot of the person, you still deal with a lot of noise. So this is something else. Oh, yeah. Noise is also problem. So you have an eye and I have this perfect measurement of Jason. The color of his eye is the whatever beautiful. What color are they? You're getting me out. Okay. So you have a perfect representation of his eye. You know, you're using ultimately some something to take a measurement of the scene. Right? To be able to do this. And we talked about like, oh, first of all, there's a problem of bit depth. Like I only have 256 levels to choose from and I have to represent everything in the scene. So challenge one. Challenge two is, you know, photons are falling in my sensor and I need to be able to measure them perfectly exactly. Right? That just doesn't happen. Yeah. So even if even if you had a perfect number to represent it, you have to perfectly make that measurement. It would never happen. So if you had like think of you're looking at a plane, a whiteboard, a dry erase board and you took a picture of a pure white erase board with perfect uniform lighting. None of this would happen, but it's all perfect. Right? And you try to take a picture of you're still not going to get all white. You're going to get some stuff that's slightly less white than other stuff. And it's going to have all these little variations in it just from the fact that you can't capture a perfect image of it. You know, or there might even be like, what if there's a little dust in the air?

  205. A

    Yeah, that's exactly. Or like heat waves coming up from the ground. Right. Like even if you could exactly measure exactly how many photons hit this spot, the reality is it would be different because one photon bounces off a dust particle in the air and another photo, two other photons collide and bounce off in a weird way. And so there's always going to be a lot of noise no matter what.

  206. B

    And then that doesn't even get into the aspect of like, oh, when you take up, you're taking a picture, it's not instantaneous. You have to sit there and, you know, look at it for a little bit. So this is, you know, what you're talking about, shutter time, shutter speed. So even if there's not an actual shutter, there might be an electronic shutter. But it's something to say how long to let the photons collect for. Right? And that length of time, the thing can move. Jason can blink. Now his eyes are like half open, half closed in my image. Like what the heck? Like, oh, now this is a problem for me. Right? Like, and you have to deal with that. Yeah. And all of these image processing things.

  207. A

    Yeah. And I mean, and the other problem too, and I think we should talk about is that all of these effects are cumulative. You know, if you, if you have some algorithm that does edge detection, let's say, it's not going to be perfect. There's going to be some edge cases, things like that. And it's going to sort of introduce noise and it's going to, you're going to lose some of your information. Right? And anything that runs on top of that is already at a disadvantage. And then it's also going to have introduced its own artifacts. Right? And so all these artifacts are cumulative. And that's one of the biggest challenges in image processing is knowing where in your pipeline you can get the most bang for your buck.

  208. B

    Yep. All right. Well, we could go on for a long time about this. Yeah.

  209. A

    We'll talk about a long time. Talk about some, some tools.

  210. B

    Yeah. So first one I use, I'll talk about is

  211. A

    OpenCV, which is Open Computer Vision. Yeah. It's amazing.

  212. B

    There's a lot of history of this. I think it used to be Intel product.

  213. A

    Yeah. And it was open source.

  214. B

    And now it's getting aside from the background of it.

  215. A

    There's a lot of plugin—not plugins, but wrappers, I think is what the right term. But you can write OpenCV. You can access OpenCV code from Java, Python, many of them. Yeah. So a lot of

  216. B

    them, cause it's basically a framework. So to represent images, we talked about like, oh, they're matrices, but there's a lot of common things you want to do, like, oh, I want to represent a convolution kernel. I want

  217. A

    to represent an

  218. B

    image. I want to run like all these different things. There's a common kind of way to do it. So part of what OpenCV is doing is like, oh, here's a common framework for doing that. Yeah. But then, yeah, like Jason said, a lot of not only languages work with it, but a lot of people have written their, you know, university research paper in OpenCV. So they'll release like, oh, here's my OpenCV code that does this crazy, you know, fancy, whatever magic that you want it to do. Yeah. Yeah. You know, or like, oh, here's an edge detector. Even to have things like, oh, here's something that if you take two images, it'll try to align them so that they, you know, kind of overlap correctly because you had slight vibration in the camera between the two pictures. Yep.

  219. A

    So things as complicated as that. That's called image registration. Yeah. When you have two images and you think that they're the same content, but one is maybe shifted or skewed or rotated, and you want to sort of come up with the transformation that puts them, that aligns the two images. Yeah. Right.

  220. B

    So, yeah, they all even have code as complicated for things like that. I don't think they'd go as far as like having Optical Character Recognition (OCR), or like detecting cats.

  221. A

    But the basis for that, you know, is kind of in there. So they have several methods for transforming an image into a set of features, which is what we just learned, which is image analysis. They actually have several libraries that do that. So they have SIFT, which is Scale and Variant Feature Transform. They also have SURF, which is similar to SIFT, is not as good, but it's high performance. I forgot the acronym stands for. But basically, it does the same thing, but faster. So it's really meant for videos and processing just many frames of images. And so if you need, you know, to just get an image and just turn it into a bunch of features for you to do something else with, OpenCV has all of that built in.

  222. B

    Yeah. So there's also the Python Imaging Library?

  223. A

    Yeah. So this one is in Python. It has a lot of sort of convolutions, these kind of things. It works with NumPy. So if you are a Python user and you've needed matrices before, I'm sure you've used NumPy. This is tightly integrated with that. And it supports opening and saving files in many different formats.

  224. B

    So we already talked about MATLAB, Matrix Laboratory. But, you know, MATLAB or I guess Octave has probably the... Oh, yeah. Octave has image processing in it as well. Yeah. So one of the nice things about MATLAB, Octave, and the image processing is, like, there's a lot of code to write, you know, if you're using a language which you don't have a good library for already, just to, like, get to this, you know, array representation. And the code is what it'll be, not a matrix, but an array. And so you have this array representation. Once you get there, there's a lot of fun you can do just to play around. But to get there, there's a lot of codes. Having a batteries included, something that does that, or finding a good library to do it for you, is a huge thing. Because you don't want to figure out how to, you know, it's not stored as just a list of numbers. There's always, there's like headers, and there might be various compression. And you've got to figure out how to undo all of this stuff to get back to your array of numbers. And things like, you know, Python Imaging Library, MATLAB, OpenCV have those functions in them. Which is really good, because that stuff's interesting. But for me, that's not the part I wanted to play with when I started.

  225. A

    Yeah, exactly. I mean, the other thing to know is, if you aren't taking the video yourself, so in other words, you know, if you're recording a video on your camera, you can record the video even uncompressed, right? But you could also do, you know, MPEG-2 or MPEG-3, and you just know what it is. But if you want to just collect a bunch of videos from the internet, they could be encoded, and each one could be encoded slightly differently. Like, one could be MPEG-4, one could be XVID, one could be uncompressed. And you don't want your image processing algorithm to be dependent on one of these input formats. So by using something like PIL or OpenCV or MATLAB, you just say, hey, take this image and turn it into a bunch of ones and zeros. Like, I don't, it's JPEG, it's PNG, it's MP4. I don't know what any of those mean, but I just want, you know, a matrix. And it will handle all that stuff.

  226. B

    So the other thing, and it's kind of a tool, kind of a, you know, whatever. Anyways, for photographers and images that are taken with cameras especially, you have Photoshop and GIMP. And so this is still useful because, like I said, there's things like Gaussian blur in there. You'll see that. Or you can do things like run, like do edge detection. It'll show you what the edges in the image are, which are transitions from dark to light or light to dark or colors. But they'll have those kinds of things in there. So the one, they're useful for like, oh, that's what that looks like really quickly. I wonder if that's what I want to implement or not. But even otherwise, sometimes if you want to pre-process your image in some way. So like, oh, I got this really dark image and I'd rather make it brighter because my algorithm works better that way. You know, sure, you probably should write something that does it automatically in your code, but initially you're not going to have that. So having something like GIMP or Photoshop, whenever I was doing image processing, I used these tools very heavily. Both for opening images and then like, oh, I want to crop it down to a power of two size because some algorithms want that. Like doing all those things, I don't want to write code to do that because it's typically a one-off where I need to use human judgment to make something. And sure, a final system can't do that. But for testing and prototyping, you know, these tools are invaluable.

  227. A

    Yeah, definitely. They're both awesome. Highly recommended.

  228. B

    And then also, I guess if you get to become an image processing guru, you can contribute to GIMP or go work for Adobe and make the next Photoshop because they really have to do crazy stuff in there to implement all these things we talk about.

  229. A

    Yeah, yeah. I mean, the latest Photoshop has this ridiculous stuff. Have you seen this magic eraser? No. It actually, well, it uses a bunch of techniques, really advanced techniques, but the idea is you can sort of erase something and it will blend in. It will replace it with, you know, a blended in of its

  230. B

    surroundings. I've seen this before. Yeah, yeah. A content-aware

  231. A

    stuff. Yeah, that's what

  232. B

    it is. It's the same thing. Yeah, like, oh, I'm deleting something from grass, so it knows to go find other grass and like stick it there.

  233. A

    from the image. Yeah, yeah, yeah. And it sort of keeps the frequencies intact and it keeps like L2 continuity, so it actually, you can't even tell that there was, you know, the pixels next to the one.

  234. B

    Right, so there's a huge math research definition of it, but then ultimately those people aren't using it. It's people who are like photographers saying like, oh, man, there's like an ugly cockroach on this wall in this house and I want to just

  235. A

    like remove that cockroach.

  236. B

    He doesn't want to think.

  237. A

    about. I wonder what the gradient of this area needs?

  238. B

    To be for. Okay, 'gradient' is actually an overloaded term there. That's the ultimate meaning, so okay, anyways, we'll skip on. But

  239. A

    Yeah, it's pretty amazing. Photoshop gives a great way to start off. But yeah, hopefully you'll make some of your own image processing algorithms and share it with us. It'd be pretty cool.

  240. B

    It's a huge field. This is only a light glossing over, but hopefully we've enlightened someone or yeah, definitely. At least entertained you.

  241. A

    For any questions about image processing, feel free to post it on the discussion in the Programming Throwdown community.

  242. B

    All right, that's all I got. Cool. Have a good one, guys. See you next week, next two weeks.

  243. A

    The intro music is Axo by Binar Pilot. Programming Throwdown is distributed under a Creative Commons Attribution Sharealike 2.0 license. You're free to share, copy, distribute, transmit the work, to remix, adapt the work, but you must provide attribution to Patrick and I and share alike in kind.