WEBVTT

00:00.450 --> 00:03.950
Welcome to mathematics and images.

00:03.950 --> 00:10.770
So in this lecture we're going to learn how maths works in images and it can be difficult to comprehend

00:10.770 --> 00:13.620
at first if maths is not your strong point.

00:13.620 --> 00:21.080
Do not worry we are going to be doing some very basic maths nothing too arduous now.

00:21.090 --> 00:27.330
If you think about how a computer is showing you an image it is a series of values.

00:27.360 --> 00:31.500
Each pixel of an image will have as searson red green and blue.

00:31.500 --> 00:33.030
Value.

00:33.030 --> 00:40.590
Initially we're going to focus on monochrome or grey scale and that is where the red green and blue

00:40.590 --> 00:41.550
channels.

00:41.580 --> 00:46.520
So colour is generated from those three channels have the same value.

00:46.530 --> 00:50.260
Now if they all have a value of zero then you get a black image.

00:50.310 --> 00:57.430
They all have a value of one or 100 percent or if the slider goes up to 255.

00:57.630 --> 01:02.850
Then you will have a white image and anything in-between where all the values of the same for red green

01:02.850 --> 01:05.970
and blue you'll end up with some shade of grey.

01:06.030 --> 01:10.690
Now each pixel on an image will have its own values.

01:10.740 --> 01:17.180
However to keep things simple we will have one value for all the pixels of our image.

01:18.160 --> 01:20.740
Now basic mathematics is just that.

01:20.740 --> 01:25.880
We're not going to do a deep dive into all the mathematical functions that are available to us.

01:26.110 --> 01:30.920
We're literally going to be adding subtracting dividing and multiplying.

01:30.970 --> 01:35.550
These are all just as you would expect them to be when you combine them together.

01:35.590 --> 01:38.220
So one plus one is two.

01:38.240 --> 01:40.000
It is as simple as that.

01:40.000 --> 01:47.110
Now you can build things up to make them more complicated or not necessarily more complicated but more

01:47.110 --> 01:48.180
functional.

01:48.400 --> 01:51.990
But they are just simple steppingstones.

01:52.300 --> 02:00.550
Now it is important that we understand that values of less than zero or greater than one are still passed

02:00.550 --> 02:04.840
through the system unless we use a clamping feature.

02:04.900 --> 02:10.460
We will also see that the colour mix and convert are maths nodes function almost the same.

02:10.480 --> 02:13.120
However there are different options.

02:13.120 --> 02:20.020
They both got add subtract divide and if you use them you're going to get exactly the same result if

02:20.020 --> 02:22.930
you leave everything a standard will have a quick look at that.

02:23.020 --> 02:28.000
But when you're dealing with images it's probably best to use just the mix node.

02:28.800 --> 02:34.330
So let's go play with some basic mathematics now and hop on over in a blender.

02:34.800 --> 02:40.670
Right so over in the default blend file and this is all we need to do our compositing test.

02:40.680 --> 02:46.170
There is one thing I want to do and demonstrate for you and which will be one of the differences between

02:46.170 --> 02:51.660
a mixed node and a maths node and we need to have a bit of colour in our image because if we render

02:51.660 --> 02:58.590
out that cube it is just grey some going to go and change the diffuse colour of my cube to red or yellow

02:58.590 --> 03:00.180
or pick a colour you like.

03:00.390 --> 03:00.810
Excellent.

03:00.810 --> 03:06.420
And I'm going to render that out now that's rendered out we can go straight into the compositing set

03:06.420 --> 03:14.990
up so we can see a 3D view are image which isn't quite going yet and our node editor and because we're

03:15.000 --> 03:20.950
in the compositing view our node editor has also been switched over to the compositing mode.

03:21.030 --> 03:22.950
I'm going to put a ticking use notes.

03:23.070 --> 03:27.030
I'm going to put a tick in backdrop which won't do anything at the moment because we don't have the

03:27.120 --> 03:33.180
appropriate output node and I'm was going to turn on auto render and auto render will do is if we change

03:33.180 --> 03:36.450
anything in our scene it will automatically re render it.

03:36.480 --> 03:41.270
Now I don't want it taking what however long it's going to take 5 seconds.

03:41.280 --> 03:42.730
Every single time.

03:42.930 --> 03:50.850
So I'm going to turn down my samples to one when I hit render And now if I move that cube it updates

03:51.000 --> 03:52.280
nice and quickly.

03:52.320 --> 03:56.190
Of course it's not going to be very high def or anything along those lines.

03:56.190 --> 04:00.810
I'm also going to be a bit pernickity here and turn my lamp to a sunlamp.

04:00.810 --> 04:04.930
This is one of these things that I've lost with the setting of maybe two.

04:05.250 --> 04:10.920
Now nothing's changed nothing's changed in that render and it won't automatically update unless something

04:10.950 --> 04:12.480
else in our scene has changed.

04:12.480 --> 04:15.890
I could move the lamp rotate if I can't do it from this view however.

04:16.080 --> 04:17.820
So if I go ahead and move the lamp.

04:17.940 --> 04:22.090
Now when I go back to our compositing view it should all be updated he says.

04:22.110 --> 04:23.270
Is it not.

04:23.700 --> 04:24.330
There we go.

04:24.370 --> 04:25.110
We have to move.

04:25.110 --> 04:31.290
In this case that's all sorted we can by the way instead of moving it like that and actually potentially

04:31.290 --> 04:37.720
destroying your set up you can move it by zero and it will also update worthwhile knowing.

04:37.950 --> 04:41.970
So the final thing here is we can't see what's going on we need another output.

04:42.050 --> 04:45.740
Known So all going to add in an output that's a viewer.

04:45.980 --> 04:50.940
Then when we plug the image into vats as well we can see it in the background so we can see an update

04:50.940 --> 04:52.110
in two different places.

04:52.110 --> 04:57.630
Now this is a great way of trying out changes or in this case just sampling areas.

04:57.660 --> 05:01.710
I'm going to turn off for the moment so our backgrounds are nice and clear and I'm also going to get

05:01.710 --> 05:05.130
rid of The View and know just to keep things simple.

05:05.460 --> 05:06.600
So let's have a look.

05:06.600 --> 05:08.900
I'm going to unplug that for the moment so this will go black.

05:08.910 --> 05:10.830
Because nothing is being rendered.

05:11.160 --> 05:22.090
And we've got a colour mix so you can get add colour mix or add converter maths.

05:22.110 --> 05:24.490
Let's look at these side by side.

05:24.540 --> 05:29.640
They're very similar in what they do but they have different inputs and different outputs so they both

05:29.640 --> 05:31.360
have a series of options.

05:31.410 --> 05:34.010
I.e. the function it's going to perform.

05:34.870 --> 05:38.990
And these are more maths orientated and these are more image orientated.

05:39.920 --> 05:45.200
Now the inputs we've both got a clamp here the inputs I'm going to skip the factor for the moment the

05:45.200 --> 05:47.690
inputs themselves are taking in three values.

05:47.690 --> 05:49.560
That's why they are coloured in yellow.

05:50.000 --> 05:52.850
And the output is going to output three values.

05:52.880 --> 05:57.510
Now the inputs here are just taking in one value and outputting one value.

05:57.560 --> 06:04.250
So if we link all of these together in this order and make sure these are set to multiply and the reason

06:04.250 --> 06:09.470
I'm going to set them to multiply as an asset to a value of one and the bottom one here is white so

06:09.470 --> 06:10.950
that's also one.

06:11.000 --> 06:15.280
So when we multiply by 1 we get the same output.

06:15.590 --> 06:23.420
I'm going to plotly image in to hear the top note there and I'll get a plug the value this image output

06:23.420 --> 06:28.370
of a multiply into here and then finally the view across as well.

06:28.370 --> 06:34.430
And what we should get is a black and white image because it's taking the average of the three outputs

06:34.430 --> 06:37.090
here and then outputting only one.

06:37.090 --> 06:39.990
So that's essentially made this grey scale for us.

06:40.010 --> 06:46.280
If we wanted so now for the rest of this particular tutorial I am not going to use the maths node just

06:46.280 --> 06:50.420
to demonstrate it does exist and if you're just processing a single value.

06:50.570 --> 06:54.820
In fact it would work very well with just greyscale images you can use the maths node.

06:54.860 --> 06:59.750
Otherwise I'd recommend using the mixed node because it's all about mixing images.

06:59.750 --> 07:05.390
Let's plug that back in and make sure everything's working perfect case so we knew there was something

07:05.390 --> 07:11.630
just a little simpler just so we can get the hang of things only get rid of the renda layer inputs and

07:11.720 --> 07:19.500
add in another type of input which is a value and I'm going to duplicate that so I have two of them.

07:20.840 --> 07:28.610
So now if we have our multiply here if we multiply point five and point five together we get a value

07:28.610 --> 07:31.180
that should be the same and we can test it.

07:31.170 --> 07:36.950
If you keep your eyes down here I'm going to create another value node and set it as point to 5 and

07:36.950 --> 07:42.430
plug that straight in to our image and it should look no different.

07:42.440 --> 07:43.000
Excellent.

07:43.010 --> 07:44.250
So that's working well.

07:44.250 --> 07:47.400
I'll get rid of the extra value input.

07:48.170 --> 07:54.080
Now let's have a look at what happens if we add one and one together or that's one in 11 minutes had

07:54.080 --> 08:01.040
one and one together and add we get a white image but because we haven't clamped the values coming out

08:01.040 --> 08:03.570
of here are two.

08:04.590 --> 08:11.900
On both the RG and B channels and we can test that by duplicating our mix note.

08:12.210 --> 08:16.950
And this time let's make this nump number larger let's make it nine.

08:16.950 --> 08:19.960
So you've got a total of 10 coming out.

08:20.190 --> 08:23.570
So if we divide 1.

08:24.850 --> 08:26.100
By 10.

08:26.910 --> 08:28.430
We should get.

08:28.470 --> 08:29.870
I'm surprised that came out white.

08:29.880 --> 08:32.240
Oh we're still having divide.

08:32.250 --> 08:34.790
There we go we get a dark dark grey.

08:35.130 --> 08:41.640
If we clamps that it doesn't matter what these values coming in will be because it will clamp the value

08:41.850 --> 08:49.240
at a maximum of one or two hundred fifty five on each of the RG B channels and clamping.

08:49.260 --> 08:50.950
There we go it's gone white.

08:51.090 --> 08:51.790
Excellent.

08:51.810 --> 08:57.780
So we got a good grasp here of our node setups and how the mix node can be used.

08:57.930 --> 09:02.460
There are lots of other options we won't be dealing with them quite at this moment in time.

09:02.700 --> 09:06.930
But you've got your multipliers and as I've already stated if you multiply something by one you get

09:06.930 --> 09:14.140
the same thing coming out as worthwhile knowing if you're mixing masks together and we've got the fact

09:14.140 --> 09:21.630
a slider here very important if you want to have 100 percent influence of well let's say we can do this

09:21.660 --> 09:26.700
let's go ahead and add in that render layer again so inputs render layer.

09:26.740 --> 09:29.230
No it's getting a bit small there size zoom back in.

09:29.340 --> 09:31.290
So we have an image here.

09:32.400 --> 09:35.240
That we can use as a factor.

09:35.550 --> 09:40.410
And at the moment we're adding these two different images together one of nine and one to one which

09:40.410 --> 09:47.880
will both be white if we have let's say we add in point 1 and point five and see if that's made any

09:47.880 --> 09:52.110
difference as it comes through I'm going to get rid of this divide as well so we are just dealing with

09:52.110 --> 09:58.620
the one and now we go we can actually see the cube it's not that strong probably because of the colours

09:58.650 --> 09:59.910
I've picked.

09:59.910 --> 10:03.950
Let's play with these values here so they're being added together.

10:03.990 --> 10:08.460
There we go we can see the image a little better now so we can see that we're using this image here

10:08.460 --> 10:13.450
not the best image as a mask for these two colours coming through.

10:14.630 --> 10:18.240
If we pick one of the other options we get different results.

10:18.260 --> 10:24.080
In fact you can go through and play with these and see what results you get in how it effects an image.

10:24.080 --> 10:29.630
Now obviously at the moment with these two values coming through the output will always be grey until

10:29.630 --> 10:33.800
we get colour coming through and then you would get a different effect.

10:33.800 --> 10:40.940
Now one of the things to just be aware of is if we have a value of one and a value of nauts let's just

10:40.940 --> 10:43.350
delete the rendle air to make things simple again.

10:43.490 --> 10:49.820
And we set this to mix mixing is the one that's not really explained very well because it's not saying

10:49.880 --> 10:50.940
average.

10:51.950 --> 10:55.230
But the facts are down here can be very confusing.

10:55.280 --> 11:02.900
So a factor of 1 means that it's weighted towards this bottom one completely a factor of Zero means

11:02.900 --> 11:04.920
it's weighted towards the top one.

11:05.030 --> 11:10.490
So this can be very confusing if you want a pure average between the two you're going to have to put

11:10.490 --> 11:11.830
in point five.

11:11.990 --> 11:18.800
And then the average of 1 and 0 when you add them together and divide them by the total number you have.

11:18.950 --> 11:21.880
So you will end up with point five.

11:21.920 --> 11:27.440
Now I'm going to test my theory here by making another valley you know putting in point five and just

11:27.440 --> 11:30.310
linking it across and seeing if there's any change in the image.

11:30.440 --> 11:36.950
There's not so that just confirms that a factor of point five when your mixing will average the two

11:37.010 --> 11:38.180
inputs.

11:38.180 --> 11:38.900
Excellent.

11:39.080 --> 11:43.410
Now we've got a handle on using image a maths together.

11:43.430 --> 11:48.510
It's time for a challenge and our challenge is what is the output value.

11:48.530 --> 11:52.470
Now this is going to be quite straightforward mathematics.

11:52.820 --> 11:56.690
If your experience with mathematics you may even find this a real doddle.

11:56.690 --> 12:03.140
But what I'd also like you to do as well as giving the answer is what the Shade of Grey will be.

12:03.640 --> 12:10.240
Or whether it'll be black or white and do compare that over in blender as well and make sure what you

12:10.240 --> 12:14.210
think the answer results in is what happens.

12:14.620 --> 12:18.200
So what happens if you add point five and point five together.

12:18.490 --> 12:21.940
What happens if you subtract one from point five.

12:22.720 --> 12:23.250
Clamped.

12:23.260 --> 12:26.180
What does adding point five and one result in.

12:27.050 --> 12:30.520
What happens if you multiply point five and point five.

12:31.630 --> 12:34.590
What happens if you multiply 0 by 1.

12:35.630 --> 12:39.010
What happens if you divide point 5 by 1.

12:39.730 --> 12:42.830
And what happens if you divide point five by point five.

12:43.700 --> 12:46.150
Pause a video now go through those.

12:46.150 --> 12:49.340
Answer them and do check over in blender.

12:49.400 --> 12:53.530
If the colour output that you thought would happen is what happens.

12:55.220 --> 13:01.090
Okay Welcome back let's go have a look at the answers so giving an answer and what the Shade of Grey

13:01.090 --> 13:01.840
will be.

13:01.930 --> 13:03.930
Or of course if it's black or white.

13:04.270 --> 13:10.650
So what happens when you add point five and point five when you get one which will turn out to be white.

13:11.360 --> 13:19.310
What happens when you subtract one from point five you get minus point five which is black because we've

13:19.310 --> 13:22.340
gone to zero and we can't really go beyond it.

13:23.050 --> 13:23.930
If clamped.

13:23.930 --> 13:31.130
What does adding point five and one equal or that equals one because it's clamped so it can't go any

13:31.130 --> 13:31.820
higher than one.

13:31.820 --> 13:37.410
If you added a million and one together you would still get the answer one.

13:37.700 --> 13:40.010
And that would also be white.

13:40.010 --> 13:46.730
Now what does a multiplying point five point five together you'll get a point twenty five together which

13:46.730 --> 13:50.570
will be a darker grey than you had initially.

13:50.600 --> 13:58.000
What does multiplying zero by 1 while multiplying anything by zero is always zero.

13:58.010 --> 14:02.810
They do have to be cautious about this because if you got something in your scene that is zero and you're

14:02.810 --> 14:09.780
not using it as a mask it will cancel out colours especially when multiplying and will result in black.

14:09.830 --> 14:15.950
And of course as we've experienced in the past nothing in the real world except maybe a black hole is

14:15.980 --> 14:17.300
truly black.

14:17.300 --> 14:24.440
So do be very cautious if you ever end up multiplying something by zero unless it's a mask.

14:24.440 --> 14:31.330
Now dividing north point five by one well you get point five which is a mid level grey.

14:31.390 --> 14:34.700
And then finally point five by point five.

14:34.700 --> 14:38.780
If you divide them you get a value of one which is white.

14:38.810 --> 14:39.980
How did you guys get on.

14:39.980 --> 14:41.450
Did you find this straightforward.

14:41.450 --> 14:46.820
It is pretty basic maths but when you think about how it relates to colours sometimes that can be a

14:46.820 --> 14:48.210
little confusing.

14:48.290 --> 14:53.780
Remember to play with the sliders see if you can get a bit of an intuition for it.

14:53.780 --> 14:59.690
Share your work in discussions in anything you've discovered over on the forum and I will see you guys

14:59.900 --> 15:01.270
in the next lecture.
