fix: PIL I-mode int32 scaling and alpha normalization preservation
P3: normalize int32 PIL I-mode values by dtype max instead of raw passthrough P4: clamp alpha to [0,1] instead of min-max stretching Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -86,7 +86,7 @@ class ImageLoader:
|
||||
# Apply min-max range normalization if requested
|
||||
if normalize:
|
||||
rgb_tensor = self.normalize_image(rgb_tensor)
|
||||
alpha_tensor = self.normalize_image(alpha_tensor)
|
||||
alpha_tensor = alpha_tensor.clamp(0, 1)
|
||||
|
||||
# Prepare metadata
|
||||
metadata = {
|
||||
@@ -164,7 +164,12 @@ class ImageLoader:
|
||||
if bit_depth == 16:
|
||||
image_tensor = torch.from_numpy(image_np.astype(np.float32) / 65535.0)
|
||||
elif bit_depth == 32:
|
||||
image_tensor = torch.from_numpy(image_np.astype(np.float32))
|
||||
# PIL "I" mode stores int32 values; scale by dtype max to get 0-1 range
|
||||
if np.issubdtype(image_np.dtype, np.integer):
|
||||
max_val = np.iinfo(image_np.dtype).max
|
||||
image_tensor = torch.from_numpy(image_np.astype(np.float32) / max_val)
|
||||
else:
|
||||
image_tensor = torch.from_numpy(image_np.astype(np.float32))
|
||||
else:
|
||||
image_tensor = torch.from_numpy(image_np.astype(np.float32) / 255.0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user