Hi and welcome to lesson number 20, which deals with comparing images using the mean square as well
as comparing them using structural similarity.
So let's take a look at this lesson.
So open up this notebook and let's load images, which I've already done here.
And let's take a look at what mean Square is now.
Before I go into this, I want to explain something.
The reason we're doing this lesson is because telling the difference between images is actually quite
important and has a lot of use cases.
One of them, a simple one to understand, is motion detection.
You can easily use changes in the images to detect when motion has been.
Is this happening where a call comes into a frame?
You know the image is different, and that gives us a different means quit arrow compared to the previous
image.
So let's take a look at what means Square is means Twitter.
Let's look at the function.
Is this empty some, which is a sum of this this image minus this image?
Square.
So effectively, we're just comparing two images we're minus kingdom from each other, which means that
we're doing an element wise array of subtraction and then we're taking that value once we subtract matrices
together and we're squaring it.
And that gives us basically the MSI, the embassy here.
I'm saying this means great error between those two images.
So MSI is a tomb because it's a it's a loss.
Basically, it uses the lost function and a lot of other aspects, but it's a very simple formula that
gives us the sum squared difference between to up.
It's a two and two matrices to anything, anything busy, but the two mathematical matrices.
So let's define this function, and then let's compare three images.
So we're going to load two fireworks images that I've taken with my cell phone and what we're going
to do.
We're going to just compare to compare this.
We're going to actually sorry and compare this.
We're going to actually first Brighton one of the images.
So we're going to add a hundred to it and then we're going to show the outputs and then after we're
going to compare it.
So let's just performs operations here.
So now we have three images, so we have the original fireworks image.
This one has been brightened.
And then this one, which has shown some change in fireworks.
It's this one was a bit before this one or maybe something after I can't really recall.
So we're going to create a function that gives us compare the comparison between them using bullet structural
similarity and MSI.
So the social similarity function is a function that skew metrics provides that it's a complicated algorithm
that gives us basically these structural similarity based on neighborhood relationships between matrices
to tell the difference.
So that's another way we can do this.
That's different, MSI.
So now let's look at this function, and then we're going to compare fireworks one with fireworks,
one which is the same image, which means that obviously this new MSI difference and our structure or
max structural similarity score is one.
So, you know, those are the metrics that we're looking at.
OK.
So the high MSI means big difference, the low so structural similarity means big difference as well.
So let's compare fireworks one with the fireworks to image.
You can see that these are vastly different.
No structural similarity ranges between zero and one.
Whereas MSI can be any value, basically, and it's usually quite large values because you're scoring
numbers.
So now let's compare fireworks one with the brightened image.
Nowadays, you can expect these.
This image here is very different.
This, even though it's the same image, it's been brightened, so you would expect that it would have
a big difference.
So now we can compare them and you can see the embassy is quite large.
Sorry, that problem.
The MSI is definitely larger than when you compared fireworks, when the fireworks to which makes sense
because fireworks to can here is pretty much very similar to fireworks one.
It's not that big a difference.
However, this one that's been brightened is a big difference if you think about it from an image perspective.
So we have that and then we have the structural similarity score, which is point five to 2.5 to means
that remember, remember one means they're identical.
So one five two means there is basically identical, somewhat identical, not to identical.
That's what it's showing us.
Remember a lower score and we'll see in this fireworks to compare to brightness one.
A lower score means they're very different in terms of SS, which is structural similarity.
So you can see when we compare the fireworks to which is a second in.
Is here with the brightened image here.
You can see you get even a larger difference between the images, which is what you would expect.
So but MSI and Asus give intuitively give the correct values we want.
However, in real life, if you're creating a motion detection, you may have to tweak the threshold.
So like when MSI is greater than, say, 5000 or 400 or 100, even, that's how you actually compare
the images and use the thresholds to get the detect when motion has changed.
So this is a very nifty and cool algorithm you can use for your for your work.
So this concludes this lesson, and now we'll move on to filter colors, which is a very important lesson
in open CV and can be division.
Thank you.