Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
841 B
4
Indexable
Never
import cv2 
import numpy as np 
from scipy import ndimage
import matplotlib.pyplot as plt


roberts_cross_v = np.array( [[1, 0 ], 
							[0,-1 ]] ) 

roberts_cross_h = np.array( [[ 0, 1 ], 
							[ -1, 0 ]] ) 

img = cv2.imread("/content/Characters Test Pattern 688x688.tif",0).astype('float64') 
img/=255.0
vertical = ndimage.convolve( img, roberts_cross_v ) 
horizontal = ndimage.convolve( img, roberts_cross_h ) 

edged_img = np.sqrt( np.square(horizontal) + np.square(vertical)) 
edged_img*=255
# plt.imshow(edged_img, cmap='gray')
# plt.axis('off')


plt.figure(figsize=(12, 4))

plt.subplot(1, 2, 1)
plt.imshow(img, cmap = 'gray')
plt.title('Original Image')
plt.axis('off')

plt.subplot(1, 2, 2)
plt.imshow(edged_img, cmap='gray')
plt.title('Robertis Filtered Image')
plt.axis('off')

plt.show()
Leave a Comment