问题遇到的现象和发生背景
Practical task 1: Developing a correlation filter.
Developing a correlation filter.
It is necessary to develop a function - a filter based on correlation. without using ready-made implementations and using only numpy library functions.
It is necessary to use the following types of kernels for filters with normalization:
1 1 1 1 1 2) -1 -1 -1 -1 -1 3) -1 -1 -1 -1 -1
1 1 1 1 1 0 0 0 0 0 0 0 1 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
For test Image please use picture boat1_resize.jpg.
Plese, Save your Result as the processed image and code to the report file and subscribe it to answer of this task
问题相关代码,请勿粘贴截图
import numpy as np
import cv2 as cv
img=cv.imread("D:/boat1_resize.jpg",0)
cv.imshow("1",img)
cv.waitKey(0)
kernel1=np.array([[1,1,1],
[0,0,0],
[-1,-1,-1]])
img=cv.copyMakeBorder(img,1,1,2,2,cv.BORDER_REPLICATE)
img2=img.copy()
for i in range(0,321,1):
for j in range(0,492,1):
a=np.abs(np.sum(np.multiply(img[i:i+3,j:j+3],kernel1)))
img2[i+1,j+2]=a
img=img[1:323,2:495]
cv.imshow("1",img2)
cv.waitKey(0)
cv.destroyAllWindows()