Welcome to mathematics and images.
So in this lecture we're going to learn how maths works in images and it can be difficult to comprehend
at first if maths is not your strong point.
Do not worry we are going to be doing some very basic maths nothing too arduous now.
If you think about how a computer is showing you an image it is a series of values.
Each pixel of an image will have as searson red green and blue.
Value.
Initially we're going to focus on monochrome or grey scale and that is where the red green and blue
channels.
So colour is generated from those three channels have the same value.
Now if they all have a value of zero then you get a black image.
They all have a value of one or 100 percent or if the slider goes up to 255.
Then you will have a white image and anything in-between where all the values of the same for red green
and blue you'll end up with some shade of grey.
Now each pixel on an image will have its own values.
However to keep things simple we will have one value for all the pixels of our image.
Now basic mathematics is just that.
We're not going to do a deep dive into all the mathematical functions that are available to us.
We're literally going to be adding subtracting dividing and multiplying.
These are all just as you would expect them to be when you combine them together.
So one plus one is two.
It is as simple as that.
Now you can build things up to make them more complicated or not necessarily more complicated but more
functional.
But they are just simple steppingstones.
Now it is important that we understand that values of less than zero or greater than one are still passed
through the system unless we use a clamping feature.
We will also see that the colour mix and convert are maths nodes function almost the same.
However there are different options.
They both got add subtract divide and if you use them you're going to get exactly the same result if
you leave everything a standard will have a quick look at that.
But when you're dealing with images it's probably best to use just the mix node.
So let's go play with some basic mathematics now and hop on over in a blender.
Right so over in the default blend file and this is all we need to do our compositing test.
There is one thing I want to do and demonstrate for you and which will be one of the differences between
a mixed node and a maths node and we need to have a bit of colour in our image because if we render
out that cube it is just grey some going to go and change the diffuse colour of my cube to red or yellow
or pick a colour you like.
Excellent.
And I'm going to render that out now that's rendered out we can go straight into the compositing set
up so we can see a 3D view are image which isn't quite going yet and our node editor and because we're
in the compositing view our node editor has also been switched over to the compositing mode.
I'm going to put a ticking use notes.
I'm going to put a tick in backdrop which won't do anything at the moment because we don't have the
appropriate output node and I'm was going to turn on auto render and auto render will do is if we change
anything in our scene it will automatically re render it.
Now I don't want it taking what however long it's going to take 5 seconds.
Every single time.
So I'm going to turn down my samples to one when I hit render And now if I move that cube it updates
nice and quickly.
Of course it's not going to be very high def or anything along those lines.
I'm also going to be a bit pernickity here and turn my lamp to a sunlamp.
This is one of these things that I've lost with the setting of maybe two.
Now nothing's changed nothing's changed in that render and it won't automatically update unless something
else in our scene has changed.
I could move the lamp rotate if I can't do it from this view however.
So if I go ahead and move the lamp.
Now when I go back to our compositing view it should all be updated he says.
Is it not.
There we go.
We have to move.
In this case that's all sorted we can by the way instead of moving it like that and actually potentially
destroying your set up you can move it by zero and it will also update worthwhile knowing.
So the final thing here is we can't see what's going on we need another output.
Known So all going to add in an output that's a viewer.
Then when we plug the image into vats as well we can see it in the background so we can see an update
in two different places.
Now this is a great way of trying out changes or in this case just sampling areas.
I'm going to turn off for the moment so our backgrounds are nice and clear and I'm also going to get
rid of The View and know just to keep things simple.
So let's have a look.
I'm going to unplug that for the moment so this will go black.
Because nothing is being rendered.
And we've got a colour mix so you can get add colour mix or add converter maths.
Let's look at these side by side.
They're very similar in what they do but they have different inputs and different outputs so they both
have a series of options.
I.e. the function it's going to perform.
And these are more maths orientated and these are more image orientated.
Now the inputs we've both got a clamp here the inputs I'm going to skip the factor for the moment the
inputs themselves are taking in three values.
That's why they are coloured in yellow.
And the output is going to output three values.
Now the inputs here are just taking in one value and outputting one value.
So if we link all of these together in this order and make sure these are set to multiply and the reason
I'm going to set them to multiply as an asset to a value of one and the bottom one here is white so
that's also one.
So when we multiply by 1 we get the same output.
I'm going to plotly image in to hear the top note there and I'll get a plug the value this image output
of a multiply into here and then finally the view across as well.
And what we should get is a black and white image because it's taking the average of the three outputs
here and then outputting only one.
So that's essentially made this grey scale for us.
If we wanted so now for the rest of this particular tutorial I am not going to use the maths node just
to demonstrate it does exist and if you're just processing a single value.
In fact it would work very well with just greyscale images you can use the maths node.
Otherwise I'd recommend using the mixed node because it's all about mixing images.
Let's plug that back in and make sure everything's working perfect case so we knew there was something
just a little simpler just so we can get the hang of things only get rid of the renda layer inputs and
add in another type of input which is a value and I'm going to duplicate that so I have two of them.
So now if we have our multiply here if we multiply point five and point five together we get a value
that should be the same and we can test it.
If you keep your eyes down here I'm going to create another value node and set it as point to 5 and
plug that straight in to our image and it should look no different.
Excellent.
So that's working well.
I'll get rid of the extra value input.
Now let's have a look at what happens if we add one and one together or that's one in 11 minutes had
one and one together and add we get a white image but because we haven't clamped the values coming out
of here are two.
On both the RG and B channels and we can test that by duplicating our mix note.
And this time let's make this nump number larger let's make it nine.
So you've got a total of 10 coming out.
So if we divide 1.
By 10.
We should get.
I'm surprised that came out white.
Oh we're still having divide.
There we go we get a dark dark grey.
If we clamps that it doesn't matter what these values coming in will be because it will clamp the value
at a maximum of one or two hundred fifty five on each of the RG B channels and clamping.
There we go it's gone white.
Excellent.
So we got a good grasp here of our node setups and how the mix node can be used.
There are lots of other options we won't be dealing with them quite at this moment in time.
But you've got your multipliers and as I've already stated if you multiply something by one you get
the same thing coming out as worthwhile knowing if you're mixing masks together and we've got the fact
a slider here very important if you want to have 100 percent influence of well let's say we can do this
let's go ahead and add in that render layer again so inputs render layer.
No it's getting a bit small there size zoom back in.
So we have an image here.
That we can use as a factor.
And at the moment we're adding these two different images together one of nine and one to one which
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
difference as it comes through I'm going to get rid of this divide as well so we are just dealing with
the one and now we go we can actually see the cube it's not that strong probably because of the colours
I've picked.
Let's play with these values here so they're being added together.
There we go we can see the image a little better now so we can see that we're using this image here
not the best image as a mask for these two colours coming through.
If we pick one of the other options we get different results.
In fact you can go through and play with these and see what results you get in how it effects an image.
Now obviously at the moment with these two values coming through the output will always be grey until
we get colour coming through and then you would get a different effect.
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
delete the rendle air to make things simple again.
And we set this to mix mixing is the one that's not really explained very well because it's not saying
average.
But the facts are down here can be very confusing.
So a factor of 1 means that it's weighted towards this bottom one completely a factor of Zero means
it's weighted towards the top one.
So this can be very confusing if you want a pure average between the two you're going to have to put
in point five.
And then the average of 1 and 0 when you add them together and divide them by the total number you have.
So you will end up with point five.
Now I'm going to test my theory here by making another valley you know putting in point five and just
linking it across and seeing if there's any change in the image.
There's not so that just confirms that a factor of point five when your mixing will average the two
inputs.
Excellent.
Now we've got a handle on using image a maths together.
It's time for a challenge and our challenge is what is the output value.
Now this is going to be quite straightforward mathematics.
If your experience with mathematics you may even find this a real doddle.
But what I'd also like you to do as well as giving the answer is what the Shade of Grey will be.
Or whether it'll be black or white and do compare that over in blender as well and make sure what you
think the answer results in is what happens.
So what happens if you add point five and point five together.
What happens if you subtract one from point five.
Clamped.
What does adding point five and one result in.
What happens if you multiply point five and point five.
What happens if you multiply 0 by 1.
What happens if you divide point 5 by 1.
And what happens if you divide point five by point five.
Pause a video now go through those.
Answer them and do check over in blender.
If the colour output that you thought would happen is what happens.
Okay Welcome back let's go have a look at the answers so giving an answer and what the Shade of Grey
will be.
Or of course if it's black or white.
So what happens when you add point five and point five when you get one which will turn out to be white.
What happens when you subtract one from point five you get minus point five which is black because we've
gone to zero and we can't really go beyond it.
If clamped.
What does adding point five and one equal or that equals one because it's clamped so it can't go any
higher than one.
If you added a million and one together you would still get the answer one.
And that would also be white.
Now what does a multiplying point five point five together you'll get a point twenty five together which
will be a darker grey than you had initially.
What does multiplying zero by 1 while multiplying anything by zero is always zero.
They do have to be cautious about this because if you got something in your scene that is zero and you're
not using it as a mask it will cancel out colours especially when multiplying and will result in black.
And of course as we've experienced in the past nothing in the real world except maybe a black hole is
truly black.
So do be very cautious if you ever end up multiplying something by zero unless it's a mask.
Now dividing north point five by one well you get point five which is a mid level grey.
And then finally point five by point five.
If you divide them you get a value of one which is white.
How did you guys get on.
Did you find this straightforward.
It is pretty basic maths but when you think about how it relates to colours sometimes that can be a
little confusing.
Remember to play with the sliders see if you can get a bit of an intuition for it.
Share your work in discussions in anything you've discovered over on the forum and I will see you guys
in the next lecture.