Question: Question is the following steps: (1) Generate a bigger matrix of zeros (For the 340x508 image and the 5x5 kernel/mask that we used on Jan

Question is the following steps:

(1) Generate a bigger matrix of zeros (For the 340x508 image and the 5x5 kernel/mask that we used on Jan 27, it will be 350x518 matrix of zeros)

(2) Copy the original smaller image into the center of this bigger. Do not stretch any image!

(3) Now do the SPATIAL filtering again.

Source code is the following:

# Allow access to your Google Drive

from google.colab import drive

drive.mount('/content/drive')

import matplotlib.pyplot as plt

import numpy as np

from imageio import imread

#plt.rcParams['figure.dpi'] = 200 # Bigger size plots (optional)

filename = '/content/drive/My Drive/Colab Notebooks/ImageProcessing/human.jpg'

img = imread(filename)

img = np.array(img, dtype=np.float) # convert from uint8 to float

img = img / 255 # normalize as 0 to 1

plt.imshow(img)

M0=img[:,:,0] # red values

M1=img[:,:,1] # green values

M2=img[:,:,2] # blue values

#plt.subplot(1, 3, 1)

plt.imshow(M0, cmap='gray', vmin=0, vmax=1)

plt.title('Red val.')

#plt.subplot(1, 3, 2)

#plt.imshow(M1, cmap='gray', vmin=0, vmax=1)

#plt.title('Green val.')

#plt.subplot(1, 3, 3)

#plt.imshow(M2, cmap='gray', vmin=0, vmax=1)

#plt.title('Blue val.')

MX=np.random.random(M0.shape)

plt.imshow(MX, cmap='gray', vmin=0, vmax=1)

# SPATIAL FILTERING

#h0=[[ 1, 1, 1],

# [ 1, 1, 1],

# [ 1, 1, 1]]

h0=np.ones((5,5))

#h1=[[ 0,-1, 0],

# [-1, 4,-1],

# [ 0,-1, 0]]

#

#h1=np.array(h1)/4 # why we do that ?

# which image ?

I = 0.85*M0+0.15*MX

# which filter ?

h = h0

m, n= I.shape

mh, nh = h.shape

F=np.zeros((m,n))

for r in range(m-mh):

for c in range(n-nh):

F[r,c]=np.sum(I[r:r+mh, c:c+nh]*h)

#F = np.abs(F) # no negative values !

F = F / np.max(F) # normalize again !

plt.subplot(1,2,1)

plt.imshow(I, cmap='gray')

plt.subplot(1,2,2)

plt.imshow(F, cmap='gray')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!