1
00:00:00,150 --> 00:00:08,370
Hi and welcome to lesson number 20, which deals with comparing images using the mean square as well

2
00:00:08,370 --> 00:00:10,690
as comparing them using structural similarity.

3
00:00:10,770 --> 00:00:12,540
So let's take a look at this lesson.

4
00:00:13,140 --> 00:00:17,460
So open up this notebook and let's load images, which I've already done here.

5
00:00:18,060 --> 00:00:21,990
And let's take a look at what mean Square is now.

6
00:00:22,380 --> 00:00:24,810
Before I go into this, I want to explain something.

7
00:00:25,170 --> 00:00:31,290
The reason we're doing this lesson is because telling the difference between images is actually quite

8
00:00:31,290 --> 00:00:33,150
important and has a lot of use cases.

9
00:00:33,600 --> 00:00:37,140
One of them, a simple one to understand, is motion detection.

10
00:00:37,590 --> 00:00:43,170
You can easily use changes in the images to detect when motion has been.

11
00:00:43,650 --> 00:00:46,320
Is this happening where a call comes into a frame?

12
00:00:46,320 --> 00:00:51,420
You know the image is different, and that gives us a different means quit arrow compared to the previous

13
00:00:51,420 --> 00:00:51,780
image.

14
00:00:52,290 --> 00:00:55,760
So let's take a look at what means Square is means Twitter.

15
00:00:55,800 --> 00:00:56,730
Let's look at the function.

16
00:00:57,630 --> 00:01:04,560
Is this empty some, which is a sum of this this image minus this image?

17
00:01:04,800 --> 00:01:05,280
Square.

18
00:01:05,940 --> 00:01:10,770
So effectively, we're just comparing two images we're minus kingdom from each other, which means that

19
00:01:10,770 --> 00:01:17,310
we're doing an element wise array of subtraction and then we're taking that value once we subtract matrices

20
00:01:17,310 --> 00:01:19,260
together and we're squaring it.

21
00:01:19,530 --> 00:01:24,720
And that gives us basically the MSI, the embassy here.

22
00:01:24,720 --> 00:01:27,240
I'm saying this means great error between those two images.

23
00:01:27,420 --> 00:01:31,440
So MSI is a tomb because it's a it's a loss.

24
00:01:31,440 --> 00:01:38,370
Basically, it uses the lost function and a lot of other aspects, but it's a very simple formula that

25
00:01:38,370 --> 00:01:41,160
gives us the sum squared difference between to up.

26
00:01:41,160 --> 00:01:48,240
It's a two and two matrices to anything, anything busy, but the two mathematical matrices.

27
00:01:49,140 --> 00:01:53,940
So let's define this function, and then let's compare three images.

28
00:01:54,510 --> 00:02:00,390
So we're going to load two fireworks images that I've taken with my cell phone and what we're going

29
00:02:00,390 --> 00:02:00,810
to do.

30
00:02:01,320 --> 00:02:03,720
We're going to just compare to compare this.

31
00:02:04,530 --> 00:02:05,880
We're going to actually sorry and compare this.

32
00:02:06,270 --> 00:02:08,670
We're going to actually first Brighton one of the images.

33
00:02:09,600 --> 00:02:14,490
So we're going to add a hundred to it and then we're going to show the outputs and then after we're

34
00:02:14,490 --> 00:02:15,180
going to compare it.

35
00:02:15,660 --> 00:02:17,620
So let's just performs operations here.

36
00:02:17,640 --> 00:02:21,450
So now we have three images, so we have the original fireworks image.

37
00:02:21,480 --> 00:02:22,920
This one has been brightened.

38
00:02:23,550 --> 00:02:27,180
And then this one, which has shown some change in fireworks.

39
00:02:27,690 --> 00:02:33,450
It's this one was a bit before this one or maybe something after I can't really recall.

40
00:02:34,440 --> 00:02:41,640
So we're going to create a function that gives us compare the comparison between them using bullet structural

41
00:02:41,640 --> 00:02:43,320
similarity and MSI.

42
00:02:43,980 --> 00:02:51,990
So the social similarity function is a function that skew metrics provides that it's a complicated algorithm

43
00:02:52,440 --> 00:03:00,210
that gives us basically these structural similarity based on neighborhood relationships between matrices

44
00:03:00,630 --> 00:03:01,530
to tell the difference.

45
00:03:01,680 --> 00:03:03,690
So that's another way we can do this.

46
00:03:04,110 --> 00:03:05,230
That's different, MSI.

47
00:03:06,090 --> 00:03:12,300
So now let's look at this function, and then we're going to compare fireworks one with fireworks,

48
00:03:12,300 --> 00:03:17,810
one which is the same image, which means that obviously this new MSI difference and our structure or

49
00:03:17,820 --> 00:03:20,700
max structural similarity score is one.

50
00:03:21,780 --> 00:03:23,780
So, you know, those are the metrics that we're looking at.

51
00:03:24,540 --> 00:03:24,870
OK.

52
00:03:25,080 --> 00:03:31,500
So the high MSI means big difference, the low so structural similarity means big difference as well.

53
00:03:32,280 --> 00:03:35,580
So let's compare fireworks one with the fireworks to image.

54
00:03:36,390 --> 00:03:39,060
You can see that these are vastly different.

55
00:03:39,570 --> 00:03:43,020
No structural similarity ranges between zero and one.

56
00:03:43,590 --> 00:03:49,140
Whereas MSI can be any value, basically, and it's usually quite large values because you're scoring

57
00:03:49,140 --> 00:03:49,680
numbers.

58
00:03:50,790 --> 00:03:54,450
So now let's compare fireworks one with the brightened image.

59
00:03:55,000 --> 00:03:56,880
Nowadays, you can expect these.

60
00:03:56,880 --> 00:03:58,590
This image here is very different.

61
00:03:58,590 --> 00:04:03,420
This, even though it's the same image, it's been brightened, so you would expect that it would have

62
00:04:03,420 --> 00:04:04,080
a big difference.

63
00:04:05,010 --> 00:04:08,070
So now we can compare them and you can see the embassy is quite large.

64
00:04:08,370 --> 00:04:09,320
Sorry, that problem.

65
00:04:09,780 --> 00:04:14,700
The MSI is definitely larger than when you compared fireworks, when the fireworks to which makes sense

66
00:04:14,700 --> 00:04:20,260
because fireworks to can here is pretty much very similar to fireworks one.

67
00:04:20,310 --> 00:04:21,510
It's not that big a difference.

68
00:04:21,870 --> 00:04:26,550
However, this one that's been brightened is a big difference if you think about it from an image perspective.

69
00:04:28,380 --> 00:04:35,250
So we have that and then we have the structural similarity score, which is point five to 2.5 to means

70
00:04:35,250 --> 00:04:38,210
that remember, remember one means they're identical.

71
00:04:38,220 --> 00:04:44,220
So one five two means there is basically identical, somewhat identical, not to identical.

72
00:04:44,880 --> 00:04:45,870
That's what it's showing us.

73
00:04:46,170 --> 00:04:50,220
Remember a lower score and we'll see in this fireworks to compare to brightness one.

74
00:04:50,640 --> 00:04:55,620
A lower score means they're very different in terms of SS, which is structural similarity.

75
00:04:56,190 --> 00:04:59,550
So you can see when we compare the fireworks to which is a second in.

76
00:04:59,610 --> 00:05:02,280
Is here with the brightened image here.

77
00:05:02,730 --> 00:05:08,100
You can see you get even a larger difference between the images, which is what you would expect.

78
00:05:08,640 --> 00:05:13,020
So but MSI and Asus give intuitively give the correct values we want.

79
00:05:13,440 --> 00:05:18,390
However, in real life, if you're creating a motion detection, you may have to tweak the threshold.

80
00:05:18,390 --> 00:05:27,600
So like when MSI is greater than, say, 5000 or 400 or 100, even, that's how you actually compare

81
00:05:27,600 --> 00:05:31,740
the images and use the thresholds to get the detect when motion has changed.

82
00:05:32,400 --> 00:05:38,070
So this is a very nifty and cool algorithm you can use for your for your work.

83
00:05:38,820 --> 00:05:44,850
So this concludes this lesson, and now we'll move on to filter colors, which is a very important lesson

84
00:05:45,270 --> 00:05:47,160
in open CV and can be division.

85
00:05:47,430 --> 00:05:47,850
Thank you.
