 Hello and welcome today. We're going to be looking at converting images to text now I don't mean we're going to be converting them to like ASCII art We're actually going to be converting the information of the image to text So what do I mean by that? Well, I have a folder here with two images We got this JPEG here and we have this little small bitmap image and here I am in the shell With those same that same folder with the same images now if you have image magic installed If you're on a Linux system you probably have installed if not probably gonna be in your package manager image magic allows you to manipulate images in all sorts of ways and Again, I have those two images I could take one of them and use the convert command which is part of image magic and I can can say convert IMG dot BMP to IMG dot JPEG and it has now created that JPEG right here So we did that and we can also go the other way. So if I have that Lake Dot JPEG I can say Lake dot either PNG or sorry I did image to PNG Lake dot PNG or bitmap or TIFF or all your standard image formats and Convert knows By what extension you give it what's converted to of course You can give it other parameters if you want to change other aspects of it And if I use the file commands look at all these it will tell us what each one is so we have a bitmap We have two JPEGs and we have our PNG image We can also convert to text. So for example, I can say convert Lake dot PNR Lake dots JPEG and I can convert that to Lake dot TXT And it will take a moment and I actually lower the resolution of this image because if you have a large image It really does take a long time, but you'll see if I now open that up with a text editor search such as VIM TXT we now have Every pixel written out so it says up here that this was converted by Image magic that pixels and then it tells us our resolution Things about the colors and then each year the first pixel the second pixel tells you the row that it's on and which pixel it is and then it gives you the RGB values here and then it also gives you the hex value and then a little more information about the RGB values over here So when would this be useful? Lots of times it's not I mean this is this is creating a rather large long file But back when I first started learning about shell scripting I actually wrote a script that's converted a video file to individual images and then it went through and Found certain colors on those using grep and I did a sort of a motion tracking with that Let me explain that a little more It's definitely not the best way to do something like that But it was something I was able to do with the knowledge I had which is part of programming taking the skills you have and solving your problems that way So let's look a little bit more at this. Let's take another look at that Lake dot TXT So again, it has all these RGB values, but if I search here through here for something like the word gray there are some like this one says gray 64 a gray 65 and They're actually going to be other color values. Let's look at this image here that I have drawn I have this is pure red So the value for this for RGB would be 255 for the red and 0 and 0 for the other colors The black would be 0 comma 0 comma 0 and white would be 255 comma 255 comma 255 But if I was take this bitmap image and use the convert command convert this BMP and I could say IMG dot txt Does very quick because this is a 20 by 20 pixels. I think is what I said this to so very small image But txt I can come in here now and you can see it gives us the RGB value here But over here it tells us that is white So there are certain colors will do that for if we come through here You can see there's black and red so when I was creating that motion tracking which I thought I uploaded the video to my YouTube channel I just tried looking for it and couldn't find it But basically I have hold a red LED and I moved it around and then I convert its images And then what it was I create a text file like this grep for the first red pixel And then I was able to overlay an image on that Adjusting the the center of the image a little bit and I was able to overlay an image wherever that red LED was again Not the best way to do that, but it worked so if you're doing a Pure red or pure pure green blue certain colors It will actually say the word which allows you to actually grep for the words But you can always grep for RGB values if you're looking for something like that now a little more on this subject If I was to do the convert command again instead of putting it into a file What I could do is txt colon dash and what that will do is dump the text out to the screen So then I can grep for it without actually creating a file. Let's do that again with the lake image Docs Jpeg there we go and you can see even though it's a low-resolution resolution image 640 by something It still takes a little while because it's sharing a lot of information It's giving a lot of information for each pixel the coordinates and three different values for the colors that you can use So something else to think about though Again, if I was to convert out our bitmap image here We have the reds and the whites here and again that would be this image here Now if I was to do the same thing for the same image that we convert to a JPEG We are now getting other values look we have some values here that aren't red black or White and we have some grays and some off whites. So again 255 255 255 would be white You can see here we're close, but they aren't quite so these are some off whites And if they were lower numbers, they might be Slightly lighter than the black and the reason for that is because of the JPEG compression So if I was to switch over here to the image again this is the bitmap image if I was to go here over to the PNG or I'm sorry the JPEG image You can see here that because of the compression there are some I don't know if that's coming up the view But I can have one here is slightly yellow slightly red slightly like a bluish color And we have some grays around the black and that's just part of the JPEG compression. So if you want to preserve those Hard lines around colors you're gonna want to use something that doesn't use a compression like that And that's gonna become important in a future video We're gonna be actually be using this technique to do something from the shell with images in a Upcoming video so watch for that subscribe if you haven't films by chris.com. That's chris the cake There's a link in the description and as always I hope that you have a great day