huggingface / huggingface/diffusers

Difference in Output When Using PIL.Image vs numpy.array for Image and Mask Input.

Open
#10,755 2 comments 0 reactions 0 assignees View on GitHub
stale
Dominant language
Python
Stars
34.5k
Forks
7.3k
Avg merge
3d 3h
Merged PRs (30d)
91

Description

hi.
I get different results when providing image and mask as input using PIL.Image versus numpy. array. Why does this happen?
Is there an issue with my normalization method?

| pillow | array |
|---|---|
| ![Image](https://github.com/user-attachments/assets/8e8a3af8-00cd-4675-93ce-b1c05eec4eb5) | ![Image](https://github.com/user-attachments/assets/25253b2a-9758-4a0f-8925-42e7a1558e50) |

#### pillow code
```python
image = Image.open(image_path).convert("RGB")
mask = Image.open(mask_path).convert("L")

output_image = pipeline(
image=image,
mask_image=mask,
generator=torch.Generator(device=self.device).manual_seed(0),
).images[0]

```
#### array code
```python
image = Image.open(image_path).convert("RGB")
mask = Image.open(mask_path).convert("L")
image_array = np.array(image) / 255.0
mask_array = np.array(mask) / 255.0

output_image = pipeline(
image=image_array,
mask_image=mask_array,
generator=torch.Generator(device=self.device).manual_seed(0),
).images[0]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.