Image Recognition and Python Part 7

sentdex · Beginner ·👁️ Computer Vision ·12y ago

Key Takeaways

Continues image recognition basics using Python

Full Transcript

hello everybody Welcome to part seven of image recognition and manipulation where we left off we were bringing up the images that we were going to consider and talking about thresholding and why we would want to and showing you the images that we're going to apply a threshold to we did begin building our threshold and now we're actually going to continue building it and now what I think I'm going to do is for now we'll just comment this out with three little quotes and at the end of it hit three quotes and down here uh we're going to pass [Music] through threshold and the image that we're going to want to do is going to be I guess we'll start with uh ir3 uh so we'll go ahead and save that run it and you should see the or the uh the text for the first pixel and the second pixel is basically we've got a 5-second timer on this so these are the pixel valuations right and this was that one that was really hard to read so anyway I'm going to stop it now now that we understand where we are I'm going to go ahead and we don't need to be printing out every pixel instead what we're going to do is we're going to average each of the pixels in there so we're going to make our averaging function so if you've watched some of my other videos I use this a lot but uh what we're going to use is reduce then we're going to make a Lambda uh x y and it's going to be x + y and we're going to use each piics and we don't really care about Alpha so we're just going to do to three we could go all the way to four but then we might adjust Alpha I don't want to be dealing with Alpha right now U maybe in another video anyway uh so that's the beginning there and then we want to divide by the length of each pics uh to three oops to three um or you could just divide by three really since it's only going to have three numbers in it but uh just to keep the average function working out for us anyway so that's that and then what we want to do is go balance wow it's learn to spell balance balance array. append and what do we want to append we want to append average num to that balance array done next once we've done that for every pixel right that's going to average like the average number in the pixel so how bright or how dark is each you know red green blue of that pixel now and then we append that to the balance array now we want to know like what is the average right of that so we'll say balance wow I did it again balance equals reduce and then again and um and in fact let's just copy and paste this save ourselves some time paste and now the only thing we need to change is instead of each picks to three we do balance array and oops balance array so that'll give us an average of uh the balance then what we're going to do is for uh each and we'll do the same thing we did before for each row in uh um new array so we're going to start changing up this new array because again like a numpy array is immutable you're not allowed to really mess with it so we're going to mess with it uh this way uh for each row in new array and then for each pics in each row then we're going to say um if the average because again you don't want to go by pixel by or or you don't want to do like red by Green by Blue you want to do like a combination of them and that will tell you cuz again right if if you remember what I was explaining before since it's an additive if you have like the full red and the full green that will make it even brighter than just a full red right so if you have full red full green and full blue now you've got a bright white right and if you just have full red and full green you've got something else and so on and so um so we don't really want to know per pixel and like change like the red the green the blue per pixel NE necessarily to threshold uh some thresholding operations you do and it just really depends what your goal is but in in our case we're just trying to make black and white right so we don't really want to do that so we're going to just say uh if reduce and we'll take we'll take this function right here this is exactly what we want if paste if that is greater than the balance right so if this one is more than the previous one what we want to do is each picks or if it's more than not previous one if it's more than the average right then that means this is one of our lighter colors right so then we're let's just convert everything so we'll say each Pi zero uh so like the first part of that pixel right so the red equals 255 and then we're just going to copy and paste this a few more times paste paste paste so each picks and then one two three obviously this is Alpha but we'll edit that one as well so all these values are going to be 255 and that will make us a nice pretty white else so if that's not the case then what do we want to do well we want to give everything a zero value besides the alpha so we'll just copy this come down paste and then 0 0 0 and we leave Alpha and then at the end of this uh function what we want it to do is we could print it out right but actually what we want to do is what's called return and so that actually like makes it act like it's like a math function right so if you do 1 plus one that's going to return something so we want to return new array but it just so happens this will end up modifying the array anyway so it's not we probably didn't really need to return anything but we will so um coming back down here now let's do uh we'll uncomment everything out and hopefully we didn't screw anything up and so we're going to let's first let's look at it one last time without the threshold so we'll run this and we get this and we're going to modify this image so you remember what it looks like right now very hard to look at and see but if we now call threshold for ir3 and run it and actually I think ir3 let me look let's look at this one5 yeah so we want ir3 anyway save that run that now that we're running the threshold and we got balance arrays not defined let's go back up here and look at it one last time oh man I so badly want to call it blance okay try again still remember what the other one looked like dude I did it again how many blance arrays did I do in here what I's see reduce blance I did it on all of them let's see here balance why didn't anybody tell me this okay hopefully we don't see that again that's pretty embarrassing anyway okay so now you can see that um it's been thresholded right so we've got white white and black and it looks nice and uh thresholded thresh held so now uh we could do it the same thing we could run threshold for ir2 as well so let's do that r that and so now we've got threshold threshold threshold and now let's threshold this sentex image and see how that looks so let's just copy paste and we'll threshold oops r four save that run it and now we can see what I was talking about as far as blur is concerned like the syntax image uh is a little like faded on the edges like it's it's not like like perfect right edges right got no threshold almost and uh so anyway this one you can see that you know the threshold held worked pretty well but again let's bring up just the regular uh image here you can see how it kind of like it's not like a solid here and it kind of Fades to White like it's not like I don't know a really sharp picture so we could bring up the other one too so here it is so you can see like at the tips the pixels slowly Fade to a white right so it just makes the picture look a little softer to the eyeballs and but anyway on a thresholding operation that can kind of throw it for a loop a little bit um so you get kind of like these little jaggedy edges but in the case of this image here you can see it's actually got um quite like 70 70 pixels so it's like a 70 by a 70 so if you were comparing this image to another one these little chunks that are almost missing wouldn't make a huge difference as far as comparing uh pattern to pattern pattern um or image array to image array that wouldn't make as big of a difference as it would here if these were like really jaggedy or whatnot so anyways uh that's the basics of our threshold and so if you have different colored images and stuff you would want to use threshold to uh basically make everything on the same playing field you know so you're dealing with the same exact numbers when you're considering so that's going to conclude tutorial number 7 as always thanks for watching thanks for your support your subscriptions and until next time so

Original Description

This is the seventh video to my image recognition basics series. Image recognition can be used for all sorts of things like facial recognition, identifying what is in pictures, character recognition, and more. Sentdex.com Facebook.com/sentdex Twitter.com/sentdex
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

Related AI Lessons

When the Camera Becomes an Exam Proctor: Building an AI-Powered Exam Monitoring System with…
Learn how to build an AI-powered exam monitoring system using Computer Vision and DeepFace to assist professional certification exams
Medium · Python
When the Camera Becomes an Exam Proctor: Building an AI-Powered Exam Monitoring System with…
Build an AI-powered exam monitoring system using Computer Vision and Deep Learning to enhance professional certification exams
Medium · Deep Learning
When the Camera Becomes an Exam Proctor: Building an AI-Powered Exam Monitoring System with…
Build an AI-powered exam monitoring system using Computer Vision and Deep Learning to enhance exam security and integrity
Medium · Cybersecurity
Your Face Is About to Become Your Phone Number
Indonesia's mandatory facial verification for SIM cards is a massive test for biometric identity verification at scale, with implications for developers in computer vision and biometrics
Dev.to AI
Up next
Marketing management for ugc net| Important topics of marketing management ugc net commerce dec 2023
Bhoomi Learning Centre~Dr. Muskan
Watch →