In [25]:
#Import all libraries we will use
from matplotlib import pyplot as plt, rcParams, rc
from scipy import ndimage
import random
import numpy as np
import cv2
from skimage import color, data, restoration

N = 6

img = np.zeros((N,N),np.uint8)

for x in range(N):
    for y in range(N):
        #We use "0" for black color (do nothing) and "1" for white color (change pixel value to [255,255,255])
        if (x == 2 or x == 3) and (y == 2 or y == 3):
            img[x,y] = 1

cv2.imwrite("img.png",img)
plt.figure()
plt.imshow(img)

M = 4
sensor = np.zeros((M,M), np.uint8)

for x in range(M):
    for y in range(M):
        sensor[x,y] = 1
        
        
plt.figure()
plt.imshow(sensor)        
cv2.imwrite("sensor.png",sensor)

measurement = ndimage.convolve(img, sensor, mode='reflect', cval=0.0)
plt.figure();
plt.imshow(measurement)
cv2.imwrite("measurement.png",measurement)


deconvolved_measurement = restoration.richardson_lucy(output, sensor, iterations=30)
plt.figure();
plt.imshow(deconvolved_measurement)
cv2.imwrite("deconvolved_measurement.png",deconvolved_measurement)


Out[25]:
True

In [3]:
print(img)


[[[0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]]

 [[0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]]]

In [ ]: