Skip to content

BOX filter missed some edge-case pixels #9939

Description

@AlttiRi

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions