"ImageEnhance (Color/Contrast/Brightness/Sharpness) .enhance(factor=NaN) silently returns an all-black image"
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #10570 của @lazerg — đã đóng, không merge
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 1/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
Hướng nghiên cứu
Read PIL/ImageEnhance.py at _Enhance.enhance, where all four enhancement classes share the call to Image.blend. Check the existing enhancement tests for the right place to cover a NaN factor across the classes. Done means the shared implementation rejects NaN while preserving the documented behavior for finite factors; pull request #10570 is already open for this issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
enhance() blends the image with its degenerate version using factor;
a NaN factor poisons the blend, and every resulting byte casts back to
uint8 as 0. The result has the exact size and mode of the input - every
downstream check passes - but contains a single value, 0. No exception,
no warning. All four enhancement classes share the behavior (they share the same
base implementation):
import numpy as np
from PIL import Image, ImageEnhance
rs = np.random.RandomState(42)
img = Image.fromarray((np.stack([rs.rand(32, 32), rs.rand(32, 32), rs.rand(32, 32)],
axis=-1) * 255).astype(np.uint8)) # RGB, independent channels
for cls in (ImageEnhance.Color, ImageEnhance.Contrast,
ImageEnhance.Brightness, ImageEnhance.Sharpness):
out = np.asarray(cls(img).enhance(float("nan")))
assert out.shape == (32, 32, 3) and np.all(out == 0)
# uniform 0, unique values = 1, mode/size unchanged;
# cls(img).enhance(1.0) still returns the original image
(An RGB input keeps the test uniform across all four classes. Side note:
on an L-mode input Color is inherently a no-op - its degenerate IS the
image object, and blending an image with itself returns a copy - so the
L-mode Color path is identity for every factor; the other three have
distinct degenerate images in every mode.)
Root cause (verified, Pillow 13.0.0 source)
PIL/ImageEnhance.py:25-39 - the shared base class:
class _Enhance:
def enhance(self, factor: float) -> Image.Image:
...
return Image.blend(self.degenerate, self.image, factor)
factor is passed to Image.blend unchecked; blend computes
im1 * (1 - factor) + im2 * factor per pixel, and with factor = NaN
every byte becomes NaN, casting to uint8 as 0. There is no NaN check at
any layer.
Scope note (why NaN only)
Per #7043, the documented contract is that the enhancement factor has
no range limits - large or negative finite factors are legitimate
and their outputs are the expected clamped/saturated blends (e.g.
factor=float("inf") gives a saturated two-value or all-255 result,
Brightness(-inf) clamps to black - consistent with blending toward an
extreme). NaN is not a factor value at all: it silently collapses the
image to a constant that no choice of finite factor produces on typical
inputs.
Impact
Factors are usually computed (new/old with old=0 producing NaN, or
parsed config values); one NaN silently blanks that image, and the
surrounding batch pipeline "succeeds" - shape, mode, and dtype all look
correct.
Suggested fix
Reject NaN in the shared implementation (covers all four classes at
once), leaving finite factors - of any magnitude or sign - untouched:
# PIL/ImageEnhance.py, _Enhance.enhance
if factor != factor: # NaN check
raise ValueError("factor must not be NaN")
Environment
- Pillow 13.0.0, numpy 2.5.5, Python 3.12.16, macOS arm64 (aarch64)
Prior-art check (2026-11-20)
Related: #7043 (enhancement factor range discussion; maintainers state
factors are intentionally unbounded). No report found for the
NaN-factor all-black output. Re-search "ImageEnhance nan" on submission
day.
- Ngôn ngữ chính
- Python
- Star
- 14k
- Fork
- 2.6k
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 205
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python-pillow/Pillow
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
python-pillow/Pillow#10590 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
python-pillow/Pillow#10589 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Sun raster files with RLE encoding and odd-width rows decode shiftedCó thể đã có người làm @PerryLink đã nhận 21 ngày trước. Đang mở🤖-assisted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
python-pillow/Pillow#10370 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm buildCó thể đã có người làm @Syamjith-NK đã nhận 85 ngày trước. Đang mởDocumentation Font Rendering PNG Third Party Framework
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
python-pillow/Pillow#9907 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Example code in ImageText documentation makes incorrect use of get_bbox()Có thể đã có người làm @mmporong đã nhận hôm nay. Đang mởDocumentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 25/100
python-pillow/Pillow#10583 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python-pillow/Pillow
Issue tương tự
-
[Bug]: DoubleMLData.from_arrays checks the treatment d with force_all_x_finite instead of force_all_d_finiteCó thể đã có người làm @leninworld đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
DoubleML/doubleml-for-py#471 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
BUG: ZarrTrace fails in init_trace for models with datetime coordinates (object dtype coord array)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] Default key routing (JavaStringHash) picks a different partition than the Java client for about half of keysCó thể đã có người làm @0z5a đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
apache/pulsar-client-go#1575 ·
Maintainer thường phản hồi trong vòng 2 ngày