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.

Image example

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).

We'd be happy if you could join our Community Proposal at http://area51.stackexchange.com/proposals/86832 for Image Processing and Computer Vision.
We need more people to follow, up vote suggested questions with less than 10 up votes and suggest new questions.
Thank You.


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.

  • $\begingroup$ 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 $\endgroup$
    – hans-t
    Sep 24 '15 at 8:22
  • $\begingroup$ Saturation: do you understand clipping or clamping of the values ? $\endgroup$ Sep 24 '15 at 8:24
  • $\begingroup$ Nope, sorry. I'm new to this kind of stuff. $\endgroup$
    – hans-t
    Sep 24 '15 at 8:26
  • $\begingroup$ 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. $\endgroup$ Sep 24 '15 at 8:29
  • $\begingroup$ 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"? $\endgroup$
    – hans-t
    Sep 24 '15 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.