#9939·Pillow

BOX filter missed some edge-case pixels

Author: AlttiRiCreated Sep 1, 2026Updated Sep 3, 2026

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