WEBVTT

00:00.120 --> 00:04.600
All right, we're gonna learn how to do outpainting, which is when you zoom out from an image.

00:04.720 --> 00:07.440
So this is the original image.

00:07.440 --> 00:09.280
You see how close it is to the chairs.

00:10.160 --> 00:13.760
And I added a mask with some border around the outside.

00:13.960 --> 00:18.280
And then we generated an image where we zoomed out a little bit from the chairs.

00:18.280 --> 00:19.960
And you can keep going with this as well.

00:19.960 --> 00:22.640
But that's the general idea.

00:22.680 --> 00:22.920
All right.

00:22.960 --> 00:24.680
That's what we're trying to accomplish.

00:24.680 --> 00:26.480
And let's walk through how to do it.

00:27.800 --> 00:30.720
First we need to install the file client.

00:30.720 --> 00:34.320
That's where we're going to call to use the Outpainting model.

00:34.320 --> 00:35.960
And then we're going to create.

00:38.520 --> 00:42.560
I'm going to get the environment variables for the API.

00:42.600 --> 00:44.560
So we're calling that.

00:44.560 --> 00:50.960
And then we're going to import file client and requests and image bytesio.

00:51.560 --> 00:53.880
We also need a display as well.

00:53.880 --> 00:58.760
So from IPython display import display.

00:58.800 --> 00:59.040
All right.

00:59.080 --> 01:01.720
Those packages are going to help us work with the images.

01:01.920 --> 01:04.400
So we're just gonna say original image?

01:05.200 --> 01:11.200
I'm just going to upload that image of a rhino in a suit up to file.

01:11.680 --> 01:14.440
And then we're going to.

01:16.560 --> 01:18.680
Work on adding some padding.

01:20.600 --> 01:22.800
Actually I'm just going to load that image first.

01:23.400 --> 01:24.800
So we're going to add some padding.

01:24.800 --> 01:31.840
The way we do that is we need to kind of shrink the image first because it needs to be in the right

01:31.840 --> 01:32.520
size.

01:33.120 --> 01:38.640
So that is going to be it's going to shrink it by say 200.

01:41.200 --> 01:42.800
Reduce this by 200.

01:44.280 --> 01:46.560
So it's going to shrink the original image.

01:47.080 --> 01:49.480
And then that's going to do the resizing.

01:50.840 --> 01:54.200
And then the new shift is going to be the original dimension.

01:55.360 --> 01:56.560
Original dimension.

01:56.600 --> 02:00.680
We need to make a new image which is just white.

02:00.680 --> 02:04.640
And then we need to paste that offset on.

02:05.560 --> 02:06.440
That's what we've done.

02:06.440 --> 02:08.200
We've created this new image.

02:08.200 --> 02:13.200
Now it's basically the same image, but we made it smaller and put it in the middle of this kind of

02:13.240 --> 02:14.040
wider image.

02:14.280 --> 02:16.080
We should be able to save that.

02:16.080 --> 02:18.320
And then we've got the.

02:21.160 --> 02:21.760
We need.

02:21.960 --> 02:22.160
Yeah.

02:22.200 --> 02:24.200
This is the padded image here.

02:25.080 --> 02:28.040
And then you need to create the mask.

02:29.720 --> 02:32.320
So notice that you need a white background.

02:32.320 --> 02:33.880
You need an inner box.

02:33.880 --> 02:40.160
And then you just need to paste a black rectangle in the middle of that inner box.

02:40.200 --> 02:43.080
And this is all going to be the same size essentially.

02:45.160 --> 02:47.960
And then we just need to save that image and then upload the file.

02:47.960 --> 02:50.040
So now we have this like temp mask file.

02:51.200 --> 02:51.560
All right.

02:51.640 --> 02:53.560
So let's see what we did.

02:53.600 --> 02:56.280
And so we're going to make sense in a second.

02:57.120 --> 03:00.160
But we're using we're going to be using the inpainting model.

03:00.320 --> 03:04.160
And normally in inpainting you create a mask by coloring in within the image.

03:04.160 --> 03:07.160
In this case outpainting is adding to the outside of the image.

03:07.270 --> 03:10.910
So you can see here that there's this overall padding.

03:11.470 --> 03:12.910
There's white around the image.

03:13.350 --> 03:17.350
And then we add the mask which blacks out the image itself.

03:17.350 --> 03:20.070
And that way it's only going to generate in the white.

03:20.310 --> 03:21.870
So it's still using inpainting.

03:21.870 --> 03:24.150
It's just a cheeky way to do it.

03:25.150 --> 03:27.230
So all the rest is just similar.

03:27.230 --> 03:29.310
Typical inpainting code.

03:29.310 --> 03:33.390
What I've done is I've used the same prompt I used to generate the original image, so it's going to

03:33.390 --> 03:35.070
keep that relatively consistent.

03:35.110 --> 03:37.310
The main difference is you want to use this fill model.

03:37.310 --> 03:39.950
I found it didn't really work unless you use this.

03:39.990 --> 03:41.950
This one seems to be pretty good at painting.

03:41.950 --> 03:49.270
Specifically, it's on Flux Pro and I'm just going to hit generate, but it's the same as any inpainting.

03:49.270 --> 03:54.030
It's just that we've added a special type of mask and there you go.

03:54.070 --> 03:58.710
You can see we've got like a zoomed out version with a bit more space around the image.

03:58.830 --> 04:00.830
You could zoom out quite far if you wanted.

04:00.870 --> 04:02.390
You can adjust the parameters.

04:02.390 --> 04:07.110
You could also keep zooming out if you want, and eventually the Rhino would be a small section in the

04:07.110 --> 04:07.550
middle.

04:07.550 --> 04:09.790
So yeah, that's how Outpainting works.
