In [10]:
import numpy as np
import matplotlib.pyplot as plt
import cv2
plt.rcParams['figure.figsize'] = [10, 10]
In [11]:
# Question 2
h1 = np.zeros((512,512))
h1[100:350,200:300] = 1
plt.imshow(h1,cmap='gray')
plt.show()
In [12]:
#  Question 3

def ImTranslate(h,tau):
    M, N = h.shape
    v = np.zeros((M,N))
    a, b = tau
    v[a:M,b:N] = h[0:(M-a),0:(N-b)]
    v[0:a,b:N] = h[(M-a):M,0:(N-b)]
    v[0:a,0:b] = h[(M-a):M,(N-b):N]
    v[a:M,0:b] = h[0:(M-a),(N-b):N]
    return v

v = ImTranslate(h1,[300,300])
plt.imshow(v,cmap='gray')
plt.show()
In [13]:
#  Question 4

def DSN(h,n):
    M, N = h.shape
    H = np.zeros((M,N))
    for i in range(n):
        Ti = [np.random.randint(M),np.random.randint(N)]
        H += ImTranslate(h,Ti)
    return H

for n in [10,100,1000]:
    u = DSN(h1,n)
    plt.imshow(u,cmap='gray')
    plt.show()
In [14]:
h2 = plt.imread('coeur.bmp')
h2 = np.mean(h2,axis=2)
plt.imshow(h2, cmap='gray')
plt.show()

for n in [10,100,1000,10000]:
    u = DSN(h2,n)
    plt.imshow(u,cmap='gray')
    plt.show()