And welcome to Section 37, where we take a look at the painting function in open copy that we're going
to use to restore a damaged photo.
So let's open this notebook and Ludo libraries and immature function and downloaded images that we're
going to use in this project.
We're not loading any models externally.
This time we're using Earth open the function directly.
That's part of the library called in paint.
So let's take a look at what we what we're doing.
So for this, for this to work, let's take a look at what the damage photo looks like.
So we have this damaged photo of Abraham Lincoln.
You can see this is in an image that basically takes the kind of distracts you from the actual image
itself.
So we want to find a way to remove this crease in a way that it looks like it wasn't artificially removed.
And you know, it looks nice.
It looks like it's a seamless, corrected image.
So what we need to do, we need to basically create a mask.
And the mask we're creating here, which I did using windows pins, I believe, is just you draw a line
across the crease here.
So it wasn't typically done, in my opinion.
I did make some mistakes, but we use dilation to increase the pixels to decrease the thickness of this
line afterward.
So it does cover all of the line here.
So we have this mess that we created here.
So this mess, we would crush all the mass to get it here.
You can see there are some white lines in the image here that also show up.
I didn't actually draw a mask on this.
These are just sort of the whitish lines in the image.
So actually, no, sorry, I didn't.
It looks like I did draw a line under this as well.
So we have those lines here, so we threshold.
We do a binary Treasure Island.
So everything outside of those lines is black, and everything along those lines are white, mostly.
But you can see it's quite spotty.
It's quite patchy.
So we need to use dilation to enhance the thickness of those.
So we use them dilation to bulk and flatten those lines up.
And then what we do, we take the stylized mask.
We take the image you can see in this important function.
Here we do take the image, the input image, the mask of these some parameters in the in brain function
that allows you to control how much you want.
This is an algorithm we're going to use to to leave one.
I'm not sure there are others built into Open Sea V. But you can check the documentation to see there's
always a lot of enhancement enhancements with different versions of OpenCV.
So they may have other ones right now, and it gives you the output, which is a restored image.
So let's run all of this code because before we were looking at code that was previously run and saved.
So this is a restored image.
This looks really, really good, in my opinion.
You can see that it does have some smudges.
It doesn't look perfect to be done here can still see the line, but this part of the image is very
well.
Then his hairline.
You can still see a faint bit of the line here, but it looks really well done.
It looks almost seamless, almost perfect.
And those vertical white lines here are also totally removed.
Let's take a look at the original image and you can compare and you can see how distracting these little
pieces were and these lines.
So that's how we used to in paint function.
So I hope you enjoyed this lesson.
Now we're going to move on to removing and adding noise to images and fixing contrast with histogram
equalization.
It's just a more computational photography type algorithms, so I'll see you in the next lesson.
Thank you.