So now let's move on to a seventh lesson called the arithmetic and Bitwise operations already have it
open on this next tab here.
So let's begin.
So firstly, let's just quickly download and set up our libraries here will connect.
You can see connecting to your machine up here, and it should be done right about now.
There we go.
So we have a machine and we've downloaded and set up in our libraries and code.
So arithmetic operations, basically operations that allow us to add or subtract to the intensity or
the the values of the image.
OK.
So what we're going to do, we're going to load in an image as a grayscale image and haven't showed
you that did this before.
But when you're using the emerade function, if you put after you put the part of the image here and
the part basically is a file path of the image, which basically it's in here, how to point to remove
this directory, hit images and liberty.
So we have the file parts there.
And if you put a comma zero, basically this tells this function to read this and as a grayscale image.
So we're going to read it and as a grayscale image, and then we're going to create another image here.
This is basically the image matrix of ones that we're going to multiply by 100 to get a matrix that
is the same size of as this image here, but filled with values of 100.
So that's clear.
Actually, I can show you guys what it looks like.
You can see what I'm printing 'em here.
But for now, let's actually not print them here.
Let's just print the initial image here so we can actually take a look at it properly.
And let's add another code block here.
And oops, not not this.
Let's just print.
And here's it coming in on capital and capital and.
So you can see this is our image here.
This is devalues the greyscale values for this point.
Here you can see it's 41, 41 41, which means all of this is the same color gray and vice versa.
So you can see it actually forms this pretty cool image in the end.
No, when you have actually actually print this one, know this m here is the same dimension where we
specified it in the function to created that same shape as the input image here, but it's now just
fill the values of 100.
And why are we doing that?
What are we going to do?
We're going to add these two matrices together using the CV to add, and that effectively is going to
increase the brightness of the image.
So in case you're wondering how we have increased brightness of images, this is basically what it's
suddenly.
Just add more values to the original image, and this is how it's done programmatically with OpenCV.
So let's do it here.
So there's two methods we're going to do.
We're going to edit using the key to add function and then we're going to edit normally just like this,
adding two matrices together and see what happens.
And let's take a look and see why it's different.
So in the first case, with the using the key to that idea, you can see it looks as expected.
We get a nice, brighter image a bit too bright, but it's fine.
It's what we wanted.
By adding 100 to every value here, we increased the likeness.
When I say the likeness, I mean, instead of darker, it gets lighter, like library of the image.
Now look what happens if you just added here, this is where you actually see you get some black spots
here.
And that's because at Eclipse, remember the values only range and in these functions and these images
to 255.
So what if there was a point that was, say, 200 in the original image?
Let's go back to the original image.
Look, here might be high 200s.
If you add a hundredth of that, you would get 300 and something, but 300 and something, let's say
200 isn't allowed as an image value because the image values have only allowed to go up to 55.
So what's going to happen is that it's going to go back to zero and it's going to go back to zero.
But it's going to go back to fully zero.
It's a 300 minus 255 is 40.
So it's going to go all the way over to 255.
It's going to be sort of the 255.
It's going to basically go back from zero up to 40.
So something so that's why you'll see these dogs, you'll see dark spots in areas that were bright in
the original image.
So you can kind of see it here.
Some of these dark areas here will have bright spots in the original image like this wall here, especially
is very white and it's very dark.
So you can see that is why you probably don't want to just add values to images.
A like this here.
You want to use it.
You would actually keeps it at 255.
So instead of going over to 200 and then which is basically represented as like 40 in the end, what
you do here is you actually eclipse it and its max value keeps it at that.
So similarly, we can this we can subtract the values here.
You can see we do that using CB2 Dot Subtract.
It's a very similar function, and it does not allow values to go past zero.
So you can see it gets darker as expected here.
And now let's see what happens when we do the other one.
It looks quite weird again.
And that's because the values are actually going negative and they're not allowed to go negative, so
they're actually going in the other direction, which is from 255 downward.
So which is why you got so many bright areas when you're supposed to be darkening this image.
So now let's move on to Bitwise operations and masking.
So brightness and stuff is fine.
However, there are a lot of more operations that we can do in open TV that require something called
Bitwise operations.
And what are they exactly?
So let's to them this.
Let's just create some images here.
Let's create two images.
Let's create this white square in the middle of this image here by these lines of code here.
And that's making lips as well here.
So now we're going to use these two images.
We're going to do something called image operations.
Image Bitwise Operations, where we take two images and make them act on each other.
And you may remember this from maybe logic gates class in college.
Yeah, one college.
He did computer science in that trickle engineering or even physics or high school to do this in physics
classes or maths class as well.
So what are we going to do?
We're going to apply and all this is all and not OK.
So let's take the Bitwise operations.
Have these two images screen ellipse and we'll do an end here.
This is where we are.
We hope we apply to end Bitwise.
And I should say it gives an output.
Outputs a variable called recall, and we keep it as restored as and that we're going to do or extra
and not as well.
All of these have built in functions into open KV C v2 that Bitwise or not or.
And let's take a look.
Let's run this and let's take a look at the outputs.
Oh, square, we didn't define this here.
Remember, we needed to run that cell before we run this, so.
So let's stick a look at this.
So the end function you can see and basically is where both of them intersect only.
So let's take a look at that that can see in these images here where it's actually is.
Maybe it is in some middle area here, which is exactly what we're seeing this middle area right here.
So no, the wise or is basically both of them where everything is in both of them and XOR is actually
what you would expect BlackWidow intersecting and wide Twitter not intersecting buildings where they
exist still and not basically.
This is actually only run on one image the not one here on the square.
OK.
So it shows everything.
It isn't part of the square.
It isn't one with two images like the others before.
So you can see what not does.
So this is quite useful when you're doing things like with image masking and living color, inverting
images or buying arising in a way you don't really use it for binaries.
I mean, you can use it for a lot of the masking type operations where you want to actually keep things
or drop things, depending on what the logic is.
So I hope you found this less than useful.
A lot of these lessons there in isolation like this, you don't actually find them.
You don't find a use case for them.
However, when you're putting together computer vision applications that require like a pre-processing
pipeline of different things that you may want to do, it's good to know what these individual functions
do and how it are used so that you can actually implement some of the things you may want to implement.
So that's what opens you.
That's why open CV is so useful.
It allows you so much powerful image manipulations that you can't call yourself a computer vision practitioner
or engineer.
If you're not familiar with it, open CV or the functions implemented by open CV.
Now, open CV isn't the actual only tool that could do image operations in Python or in other programming
languages.
There are few others, but open CV is by far the most robust biggest library, one of the fastest libraries
out there because it's built in C++, so it's quite useful.
So I would I would encourage you to use strictly open CV as your main image processing tool.
Thank you.
So let's go on to the next lesson.