Browse Source

Image

pull/27/head
Jure Šorn 5 years ago
parent
commit
25cd360d21
1 changed files with 11 additions and 1 deletions
  1. 12
      README.md

12
README.md

@ -1692,12 +1692,22 @@ height = 100
size = width * height size = width * height
pixels = [255 * i/size for i in range(size)] pixels = [255 * i/size for i in range(size)]
img_hsv = Image.new('HSV', (width, height), 'white')
img_hsv = Image.new('HSV', (width, height))
img_hsv.putdata([(int(a), 255, 255) for a in pixels]) img_hsv.putdata([(int(a), 255, 255) for a in pixels])
img_rgb = img_hsv.convert(mode='RGB') img_rgb = img_hsv.convert(mode='RGB')
img_rgb.save('test.png') img_rgb.save('test.png')
``` ```
#### Adds noise to image:
```python
from random import randint
add_noise = lambda value: max(0, min(255, value + randint(-20, 20)))
img = Image.open('test.png').convert(mode='HSV')
pixels = [(add_noise(h), s, v) for h, s, v in img.getdata()]
img.putdata(pixels)
img.convert(mode='RGB').save('test.png')
```
### Modes ### Modes
* **`'1'` - 1-bit pixels, black and white, stored with one pixel per byte.** * **`'1'` - 1-bit pixels, black and white, stored with one pixel per byte.**
* **`'L'` - 8-bit pixels, greyscale.** * **`'L'` - 8-bit pixels, greyscale.**

Loading…
Cancel
Save