mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Add access functions for ImagingEffectNoise with a test
This commit is contained in:
parent
8b2e7ee48a
commit
860e67e1c4
16
PIL/Image.py
16
PIL/Image.py
|
@ -2419,3 +2419,19 @@ def _show(image, **options):
|
|||
def _showxv(image, title=None, **options):
|
||||
from PIL import ImageShow
|
||||
ImageShow.show(image, title, **options)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Effects
|
||||
|
||||
def effect_noise(size, sigma):
|
||||
"""
|
||||
Generate Gaussian noise centered around 128
|
||||
|
||||
:param size: The requested size in pixels, as a 2-tuple:
|
||||
(width, height).
|
||||
:param sigma: Standard deviation of noise.
|
||||
"""
|
||||
return Image()._new(core.effect_noise(size, sigma))
|
||||
|
||||
# End of file
|
||||
|
|
|
@ -140,6 +140,19 @@ class TestImage(PillowTestCase):
|
|||
img_colors = sorted(img.getcolors())
|
||||
self.assertEqual(img_colors, expected_colors)
|
||||
|
||||
def test_noise(self):
|
||||
# Arrange
|
||||
size = (100, 100)
|
||||
sigma = 128
|
||||
|
||||
# Act
|
||||
im = Image.effect_noise(size, sigma)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(im.size, (100, 100))
|
||||
self.assertEqual(im.getpixel((0, 0)), 60)
|
||||
self.assertEqual(im.getpixel((0, 1)), 28)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -74,7 +74,7 @@ ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality)
|
|||
Imaging
|
||||
ImagingEffectNoise(int xsize, int ysize, float sigma)
|
||||
{
|
||||
/* Generate gaussian noise centered around 128 */
|
||||
/* Generate Gaussian noise centered around 128 */
|
||||
|
||||
Imaging imOut;
|
||||
int x, y;
|
||||
|
@ -83,19 +83,19 @@ ImagingEffectNoise(int xsize, int ysize, float sigma)
|
|||
|
||||
imOut = ImagingNew("L", xsize, ysize);
|
||||
if (!imOut)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
next = 0.0;
|
||||
nextok = 0;
|
||||
|
||||
for (y = 0; y < imOut->ysize; y++) {
|
||||
UINT8* out = imOut->image8[y];
|
||||
for (x = 0; x < imOut->xsize; x++) {
|
||||
for (x = 0; x < imOut->xsize; x++) {
|
||||
if (nextok) {
|
||||
this = next;
|
||||
nextok = 0;
|
||||
} else {
|
||||
/* after numerical recepies */
|
||||
/* after numerical recipes */
|
||||
double v1, v2, radius, factor;
|
||||
do {
|
||||
v1 = rand()*(2.0/32767.0) - 1.0;
|
||||
|
|
Loading…
Reference in New Issue
Block a user