# Extending Background Image

Suppose I have the following image. I want to extend/expand the grey background behind the model. The extension should only be upward and sideward. I don't want to extend downward because it will be ugly.

The purpose is to make the image into size (w, h) where w is greater than or equal to current image width and h is greater than or equal to current image height.

One way I could think is, to copy the pixel in the (0, 0) and fill the image extension using this pixel value. However, as you might notice, the grey background at bottom right is slightly different than the rest. This will make noticeable colour difference.

What are better algorithms that is usually used to do that? The resulting image should not have noticeable colour difference and looks natural.

What you're looking for basically is "Inpainting".

In Photoshop is called "Content Aware Fill".

You should look for articles for Inpainting.

Trivial option would be using "Replication" of the border and later enforce some smoothness (Either by Gaussian Blur or even Poisson Image Editing).

This background is nearly flat (saturated at RGB(245, 245, 245)), and you'll get good results by replicating the left edge leftward, the top edge upward, and the right edge rightward; corners both ways.

With a less uniform background, you could take values of the background pixels where there is no saturation, fit a smooth model such as quadratic (by least squares), and extrapolate out of the image, applying saturation.

• Could you explain what you mean with saturation and how to extrapolate using least squares model? or at least point me to some resources. Thanks Sep 24, 2015 at 8:22
• Saturation: do you understand clipping or clamping of the values ?
– user7657
Sep 24, 2015 at 8:24
• Nope, sorry. I'm new to this kind of stuff. Sep 24, 2015 at 8:26
• If you never heard of data fitting and the least squares approach, it is hard to point you to a good tutorial, as you need a number of concepts in linear algebra. You can start here en.wikipedia.org/wiki/Linear_least_squares_(mathematics). But I think you'd better have someone do it for you.
– user7657
Sep 24, 2015 at 8:29
• No, I know about least squares. Anyway, what do you mean with "you could take values of the background pixels where there is no saturation"? Sep 24, 2015 at 12:44