Hi and welcome back.
So we're going to take a look at the crab cut algorithm for Beckham removal, which is a very cool algorithm,
so let's take a look at this lesson.
So let's load on libraries and images.
We actually download images that we're using in this lesson separately from my GitHub using a cat.
So all of that should be done.
There we go.
So let's take a look at the crabcakes algorithm.
So before we actually explain this, let me just take a look.
Show you the output of our code.
So what do we do?
We define we have to manually target as we define a box around the foreground.
If we wish to extract, what we want to do is extract only the woman and put everything that's around
to to be black, except for the background from it, basically.
So the output that we want is going to look like this.
See this.
It's fairly well done.
And nowadays there's a lot of very cool, deep learning methods which you will see in the feature in
the other section of the course, the deep learning part of it that does this quite well, but grab
cut was one of the more effective algorithms I did back when removal back in the day of classical division.
When I see back in the day, I mean, like 2015, 2016 and a few years prior to that, a few years before.
So the things have certainly changed since 2016, which is why this course was created, because there's
a lot of different deep learning techniques being pioneered and implemented right now that are changing
computer vision.
However, it's still very good to know the classical computer vision techniques because you do tend
to use them a lot in conjunction with deep learning.
So let's take a look at how the grab algorithm works.
So as I said, the user defines a rectangle and this rectangle will be taken as basically the foreground
and the background.
But we don't know what it is, but we just know that foreground is in that rectangle.
So the algorithm using Gaussian mixture models GNN, basically, it tries to predict whether the pixels
in that box belong to the foreground or the background.
How it does it is that it creates a graph that is built from the pixel distribution and the nodes in
these graphs pixels effectively where the additional nodes are.
I did, where we have a source and sync node.
So what this means is that every foreground pixel is connected to a source node and every background
pixel is connected to sync node.
So that syncs end button upon.
So the width of these edges connecting the pixels to the source node and node, or defined by the probability
of pixel being in the foreground or background.
So that's how the glamour basically separates it.
And then if there's a large difference in the pixel color, the edge between them will get a little
wet, which means that then the mini cut algorithm is used to segment the graph at that point, so it
cuts the graph into two separate sources there the source node in the sink node using a minimum cost
function.
And, of course, function is the sum of all tweets, and the edges of this can get a bit confusing.
So I don't expect you to fully understand the algorithm here, but we can take a look of this picture
in these pictures here that will help illustrate the concept a bit.
So you start with image e and you can see this is the background here, and this is the foreground image
with seeds and you can see the construct this graph to control the pixels pixels here.
So we have a mapping of it here, and the object basically sinks the sync node here, and you can see
the signs of probability of each pixel belonging to the foreground of background based on that.
So you get the segmentation results because this is effectively a segmentation algorithm and then we
implement a cut here.
So actually goes from B to C to D, which is the final result, actually.
But hopefully that do you understand that?
And you can take a look at the people here, which is quite good to look at, as well as the open CV
documentation.
So firstly, let's take a look at how we implement this using open.
So we create a mask of a black masquerade here of the same size shape as our original image, and then
we just separate.
We create this empty ambitieux matrix, red background, middle and foreground model from the specific
linked here.
We don't change this layout.
And then we set the box, which is this bounding box here.
That's a region of interest, so our way.
Alternatively, if we use it using this in your local system, you could use V to select our way to
actually use your mouse to select these pixels.
We expect drawing a rectangle here, so that's how we interpret this.
So let's run this.
There we go.
So now we're going to look at a grab algorithm itself.
So the inputs, this image can see it here or this look a reference here by that point to here.
So we have an image to mask.
We defined above the rectangle, which we drew, which hardcoded into the background model the full.
Which is a fixed what could see it here and then we said this, this is a parameter here that actually
just tells us which which drawing wants it to use.
OK, so no, we just take this.
You get the image mass multiplied by the mask and create this new image out of it.
That's how we get mask here.
So we have mask being shown here so that we can actually see the pixels a bit brighter.
This one here, we just make it everything that's thorough background and foreground at that point,
using graphic as it gives us.
And then we get the final image output here, which is the output we wanted.
So that's pretty cool.
You can mess around with your own images with dropkicked.
I haven't used it that much in practice, to be fair, but I know a couple of guys who do and they use
it to good effect with with separating some background stuff from photographs.
So I wish you luck with this and I'll see you the next lesson where we took a look at optical character
recognition using PI Tesseract, which is a very cool library that is OCR.
So stay tuned for that.
Thank you.