python-pillow / python-pillow/Pillow

BOX filter missed some edge-case pixels

Open
#9,939 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

What did you do?

I down-sample an image with BOX filter.

Here is the image:

table-51.png (width="2755" height="1837")


What did you expect to happen?

All pixels are counted while down-sampling.

The result should look like this (688x459, 459x306):

Image

box-js-v3-table-51.png-688x459-49c214b-pil-like.png

---

Image

box-js-v3-table-51.png-459x306-20d1f1f-pil-like.png


What actually happened?

Some edge-case pixels were skipped.

---

Downscaled 4 times to 688x459:

Image

box-pil-table-51.png-688x459-49c7ade.png

missed a central vertical line.

---

Downscaled 6 times to 459x306:

Image

box-pil-table-51.png-459x306-20d5e62.png

missed a central horizontal line.


What are your OS, Python and Pillow versions?
  • OS: Win 10
  • Python: 3.12
  • Pillow: 12.3.0
file_path = "./table-51.png"
scale = 4  # scale(-down)

image = Image.open(file_path)
image_gray = image.convert("L")
wh = (int(image.width / scale), int(image.height / scale))
image = image_gray.resize(wh, Image.Resampling.BOX)

Search words: off-by-one error, range rounding.

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 with the provided Image.resize example using Image.Resampling.BOX and the linked table-51.png input. Compare the 688x459 and 459x306 results with the expected images, focusing on the skipped central vertical and horizontal lines. Done means BOX downsampling counts all pixels and produces the expected edge-case output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.