All right, we're gonna learn how to do outpainting, which is when you zoom out from an image.
So this is the original image.
You see how close it is to the chairs.
And I added a mask with some border around the outside.
And then we generated an image where we zoomed out a little bit from the chairs.
And you can keep going with this as well.
But that's the general idea.
All right.
That's what we're trying to accomplish.
And let's walk through how to do it.
First we need to install the file client.
That's where we're going to call to use the Outpainting model.
And then we're going to create.
I'm going to get the environment variables for the API.
So we're calling that.
And then we're going to import file client and requests and image bytesio.
We also need a display as well.
So from IPython display import display.
All right.
Those packages are going to help us work with the images.
So we're just gonna say original image?
I'm just going to upload that image of a rhino in a suit up to file.
And then we're going to.
Work on adding some padding.
Actually I'm just going to load that image first.
So we're going to add some padding.
The way we do that is we need to kind of shrink the image first because it needs to be in the right
size.
So that is going to be it's going to shrink it by say 200.
Reduce this by 200.
So it's going to shrink the original image.
And then that's going to do the resizing.
And then the new shift is going to be the original dimension.
Original dimension.
We need to make a new image which is just white.
And then we need to paste that offset on.
That's what we've done.
We've created this new image.
Now it's basically the same image, but we made it smaller and put it in the middle of this kind of
wider image.
We should be able to save that.
And then we've got the.
We need.
Yeah.
This is the padded image here.
And then you need to create the mask.
So notice that you need a white background.
You need an inner box.
And then you just need to paste a black rectangle in the middle of that inner box.
And this is all going to be the same size essentially.
And then we just need to save that image and then upload the file.
So now we have this like temp mask file.
All right.
So let's see what we did.
And so we're going to make sense in a second.
But we're using we're going to be using the inpainting model.
And normally in inpainting you create a mask by coloring in within the image.
In this case outpainting is adding to the outside of the image.
So you can see here that there's this overall padding.
There's white around the image.
And then we add the mask which blacks out the image itself.
And that way it's only going to generate in the white.
So it's still using inpainting.
It's just a cheeky way to do it.
So all the rest is just similar.
Typical inpainting code.
What I've done is I've used the same prompt I used to generate the original image, so it's going to
keep that relatively consistent.
The main difference is you want to use this fill model.
I found it didn't really work unless you use this.
This one seems to be pretty good at painting.
Specifically, it's on Flux Pro and I'm just going to hit generate, but it's the same as any inpainting.
It's just that we've added a special type of mask and there you go.
You can see we've got like a zoomed out version with a bit more space around the image.
You could zoom out quite far if you wanted.
You can adjust the parameters.
You could also keep zooming out if you want, and eventually the Rhino would be a small section in the
middle.
So yeah, that's how Outpainting works.