I want to add some fine-grained noise to a raster in an automated python process (i.e. I do not want to use Photoshop or GIMP). I looked at PIL, but unless I'm mistaken, it doesn't seem to have any modules for adding noise. So, I'm thinking of using NumPy to create an array of Gaussian values in the three bands (RGB) and then add that to the raster (imported as an array to NumPy).
However, I'm sure somebody on the forum has done this sort of thing before and I imagine there could be better ways of going about it.
Does anybody have a recipe for adding noise to a raster using python (possibly with GDAL/Numpy/PIL/or something else).
Many thanks
EDIT:
Following Aragon's suggestion, I had a look at the noise module, but I need to use Python 3.2 and this module is quite old (2009) and is for Python 2.x. So I decided to have a go at porting to 3 using the '2to3.py' tool. All goes well until I run setup.py, where I get the following error:
running install
running build
running build_py
creating build
creating build\lib.win32-3.2
creating build\lib.win32-3.2\noise
copying perlin.py -> build\lib.win32-3.2\noise
copying shader.py -> build\lib.win32-3.2\noise
copying shader_noise.py -> build\lib.win32-3.2\noise
copying __init__.py -> build\lib.win32-3.2\noise
running build_ext
building 'noise._simplex' extension
creating build\temp.win32-3.2
creating build\temp.win32-3.2\Release
c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W
3 /GS- /DNDEBUG -Ic:\python32\include -Ic:\python32\PC /Tc_simplex.c /Fobuild\te
mp.win32-3.2\Release\_simplex.obj
_simplex.c
_simplex.c(224) : warning C4013: 'Py_InitModule3' undefined; assuming extern ret
urning int
_simplex.c(225) : warning C4047: '=' : 'PyObject *' differs in levels of indirec
tion from 'int'
c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCRE
MENTAL:NO /LIBPATH:c:\python32\libs /LIBPATH:c:\python32\PCbuild /EXPORT:PyInit_
_simplex build\temp.win32-3.2\Release\_simplex.obj /OUT:build\lib.win32-3.2\nois
e\_simplex.pyd /IMPLIB:build\temp.win32-3.2\Release\_simplex.lib /MANIFESTFILE:b
uild\temp.win32-3.2\Release\_simplex.pyd.manifest
LINK : error LNK2001: unresolved external symbol PyInit__simplex
build\temp.win32-3.2\Release\_simplex.lib : fatal error LNK1120: 1 unresolved ex
ternals
error: command '"c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe"'
failed with exit status 1120
Any suggestions (either for an alternative library to try or how to port this one from 2 to 3)? Should I take this to the main site as we're drifting away from GIS now
Thanks
Answer
you can use Perlin noise for Python tool. from wiki:
Perlin noise is a procedural texture primitive, a type of gradient noise used by visual effects artists to increase the appearance of realism in computer graphics. The function has a pseudo-random appearance, yet all of its visual details are the same size (see image). This property allows it to be readily controllable; multiple scaled copies of Perlin noise can be inserted into mathematical expressions to create a great variety of procedural textures. Synthetic textures using Perlin noise are often used in CGI to make computer-generated visual elements - such as fire, smoke, or clouds - appear more natural, by imitating the controlled random appearance of textures of nature. It is also frequently used to generate textures when memory is extremely limited, such as in demos, and is increasingly finding use in Graphics Processing Units for real-time graphics in computer games.
installation:
pip install noise
example:
other examples:
i hope it helps you...
No comments:
Post a Comment