Skip to content

Commit 25cd360

Browse files
committed
Image
1 parent afab176 commit 25cd360

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1692,12 +1692,22 @@ height = 100
16921692
size = width * height
16931693
pixels = [255 * i/size for i in range(size)]
16941694

1695-
img_hsv = Image.new('HSV', (width, height), 'white')
1695+
img_hsv = Image.new('HSV', (width, height))
16961696
img_hsv.putdata([(int(a), 255, 255) for a in pixels])
16971697
img_rgb = img_hsv.convert(mode='RGB')
16981698
img_rgb.save('test.png')
16991699
```
17001700

1701+
#### Adds noise to image:
1702+
```python
1703+
from random import randint
1704+
add_noise = lambda value: max(0, min(255, value + randint(-20, 20)))
1705+
img = Image.open('test.png').convert(mode='HSV')
1706+
pixels = [(add_noise(h), s, v) for h, s, v in img.getdata()]
1707+
img.putdata(pixels)
1708+
img.convert(mode='RGB').save('test.png')
1709+
```
1710+
17011711
### Modes
17021712
* **`'1'` - 1-bit pixels, black and white, stored with one pixel per byte.**
17031713
* **`'L'` - 8-bit pixels, greyscale.**

0 commit comments

Comments
 (0)