python-pillow / python-pillow/Pillow

Allow arbitrary extrapolation methods

Open
#703 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement
Dominant language
Python
Stars
13.8k
Forks
2.5k
Avg merge
2d 8h
Merged PRs (30d)
89

Description

Whenever a function needs to extrapolate values of non-existing pixels (i.e. pixels outside of the image), it should be possible to specify the extrapolation method to use.

The extrapolation methods I consider to be most useful are:

  • replicate border
  • replicate border, with alpha set to 0
  • arbitrary constant
  • wrap around
  • arbitrary Python function

See the introduction to http://docs.opencv.org/modules/imgproc/doc/filtering.html for further explanation and other extrapolation methods. There are several Pillow functions where this comes in handy. For example,

image.transform(size, PIL.Image.AFFINE, data, PIL.Image.BICUBIC, extrapolate=REPLICATE_BORDER_ALPHA0)

might produce a rotated and scaled version of the source image on top of a transparent background so you can paste this transformed image into other images easily. Another example:

image.filter(filter, extrapolate=WRAP_AROUND)

might produce a blurred image that you can use for a tiled wallpaper without ugly tile borders.

If you need to prioritize, I consider Image.transform to be more important than Image.filter. (This is because it is quite easy to work around this issue for Image.filter as soon as this is implemented for Image.transform.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Image.transform entry point, which the issue identifies as the priority, and compare how Image.filter handles pixels outside the image. Define the supported extrapolation methods and verify that transform can apply them, including an arbitrary Python function, with tests covering the listed border behaviors and transparent output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.