"#### How to save the pattern, and convert for printing\n",
"\n",
"In python:\n",
"```python\n",
"mp.image.imsave('PathToImage.png', imgnoise)\n",
"```\n",
"\n",
"Within Ubuntu-terminal:\n",
"\n",
"The image have been generated with 1 pixel per milimeter, thus a density of 25.4 point per inch. To convert the images to pdf I used the following command:\n",
"\n",
"``` bash\n",
"for f in *.png; do echo ${f::-4}; convert $f -density 25.4 ${f::-4}.pdf; done\n",
Generating patterns with $1/f^\beta$ frequency distribution (pink noise) that mimic the statistics of natural images.
%% Cell type:code id: tags:
``` python
defnorm_imgray(img):
ifimg.ndim!=2:
raiseNameError('Not a gray image, ndim!=2')
face=img[...,np.newaxis]
face=face.repeat(3,axis=2)
face-=face.min()
ifface.max()<=0:
face+=1
else:
face=face/face.max()
returnface
defgray2red(img):
face=norm_imgray(img)
face=1-face
face[:,:,1]=1-face[:,:,0]
face[:,:,2]=1-face[:,:,0]
face[:,:,0]=1
face*=255
returnface.astype(np.uint8)
defgray2purple(img):
face=norm_imgray(img)
face=1-face
face[:,:,0]*=80/255
face[:,:,1]*=255/255
face[:,:,2]*=0/255
face=face.max()-face
face-=0.5
face=127+170*face
returnface.astype(np.uint8)
defgray2orange(img):
face=norm_imgray(img)
face=1-face
face[:,:,0]*=0/255
face[:,:,1]*=80/255
face[:,:,2]*=255/255
face=face.max()-face
face-=0.5
face=127+170*face
returnface.astype(np.uint8)
```
%% Cell type:markdown id: tags:
### Pink noise of different colours
#### Black-white
%% Cell type:code id: tags:
``` python
image_dim=(210,297)#in pixel
beta=1.7# a number usually between 1 and 2
# Gray image
imgnoise=generate_1overf_noise(image_dim,beta)
```
%% Cell type:markdown id: tags:
#### Red-white
Seen as black-white image by bees, and homogeneous background for near-IR cameras
%% Cell type:code id: tags:
``` python
imgnoise_red=gray2red(imgnoise.copy())
```
%% Cell type:markdown id: tags:
#### Orange-white and Purple-white
Useful for colour learning / direction association
%% Cell type:code id: tags:
``` python
imgnoise_orange=gray2orange(imgnoise.copy())
imgnoise_purple=gray2purple(imgnoise.copy())
```
%% Cell type:markdown id: tags:
#### An overview
%% Cell type:code id: tags:
``` python
fig,axarr=plt.subplots(2,2,figsize=(10,10))
axarr[0,0].imshow(imgnoise,'gray')
axarr[0,1].imshow(imgnoise_red)
axarr[1,0].imshow(imgnoise_orange)
axarr[1,1].imshow(imgnoise_purple)
```
%% Output
<matplotlib.image.AxesImage at 0x7f3e39f2c6d8>
%% Cell type:markdown id: tags:
#### How to save the pattern, and convert for printing
In python:
```python
mp.image.imsave('PathToImage.png',imgnoise)
```
Within Ubuntu-terminal:
The image have been generated with 1 pixel per milimeter, thus a density of 25.4 point per inch. To convert the images to pdf I used the following command:
``` bash
for f in*.png;do echo${f::-4}; convert $f-density 25.4 ${f::-4}.pdf;done