Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Add primary color dithering to ImageOps#9339

Open
Marcelo-MConti wants to merge 11 commits intopython-pillow:mainfrom
Marcelo-MConti:feature-filter-composition
Open

Add primary color dithering to ImageOps#9339
Marcelo-MConti wants to merge 11 commits intopython-pillow:mainfrom
Marcelo-MConti:feature-filter-composition

Conversation

@Marcelo-MConti
Copy link

What does this PR do?

This PR adds a new image operation toPIL.ImageOps that applies a
primary-color dithering filter (RGB only).

The filter:

  • Thresholds RGB channels to primary colors (0 or 255)
  • Applies a simple dithering strategy to preserve local contrast
  • Returns a new image, leaving the input unchanged

Why is this useful?

Primary-color dithering can be useful for:

  • Educational purposes (image processing fundamentals)
  • Artistic and stylized image transformations
  • Low-color or hardware-constrained displays

What is included?

  • New function:ImageOps.dither_primary
  • Unit tests covering basic behavior and output properties
  • Documentation added to the ImageOps module

Notes

  • The function expects an RGB image
  • The implementation follows existing ImageOps conventions

Before Filter

mario

After Filter

composition

@Marcelo-MContiMarcelo-MConti deleted the feature-filter-composition branchDecember 12, 2025 22:28
@Marcelo-MContiMarcelo-MConti restored the feature-filter-composition branchDecember 12, 2025 22:31
radarhereand others added4 commitsDecember 13, 2025 10:07
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@radarhere
Copy link
Member

I've createdMarcelo-MConti#1 to fix the lint failures.

@radarhere
Copy link
Member

I've createdMarcelo-MConti#2 with an idea - process the image by band, instead of all bands at once. I find it is a bit faster, and neater.

Marcelo-MConti reacted with heart emoji

@Marcelo-MConti
Copy link
Author

Marcelo-MConti commentedDec 18, 2025
edited by radarhere
Loading

Thanks so much for your help!

return 255 if quadrant in (0, 3) else 0
if value > 32:
return 255 if quadrant == 1 else 0
return 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Did you want to explain a bit where this logic comes from? Whyvalue > 233, whyquadrant in (0, 3), etc.?

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

Reviewers

@radarhereradarhereradarhere left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@Marcelo-MConti@radarhere

[8]ページ先頭

©2009-2026 Movatter.jp