Skip to content
Snippets Groups Projects
Commit b809806f authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Add tutorial for creating patterns

parent 0e0ee5b1
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import matplotlib as mp
from navipy.arenatools.patterns import generate_1overf_noise
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
```
%% Output
/home/bolirev/.virtualenvs/toolbox-navigation/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
%% Cell type:markdown id: tags:
# Creating patterns
## Pink noise
Generating patterns with $1/f^\beta$ frequency distribution (pink noise) that mimic the statistics of natural images.
%% Cell type:code id: tags:
``` python
def norm_imgray(img):
if img.ndim!=2:
raise NameError('Not a gray image, ndim!=2')
face=img[...,np.newaxis]
face=face.repeat(3,axis=2)
face-=face.min()
if face.max()<=0:
face +=1
else:
face=face/face.max()
return face
def gray2red(img):
face=norm_imgray(img)
face=1-face
face[:,:,1]=1-face[:,:,0]
face[:,:,2]=1-face[:,:,0]
face[:,:,0]=1
face*=255
return face.astype(np.uint8)
def gray2purple(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
return face.astype(np.uint8)
def gray2orange(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
return face.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
```
......@@ -5,6 +5,7 @@ Tutorials
:maxdepth: 1
01-building-arena.ipynb
02-CreatingPatterns.ipynb
02-recording-animal-trajectory.ipynb
02a-orientation-background.ipynb
02b-orientation-3markers.ipynb
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment