Reputation: 763
In order to convolve a kernel with an image, I am using:
output = cv2.filter2D(image,-1,kernel)
This is returning the convolution image that i'm looking for, however I need to trim the height and width both by 2. For example, it is currently returning output.shape = (157, 298)
and I need it to return (155,296)
.
I cannot alter the image or the kernel.
Is there a way to perhaps begin at image[1,1]
(instead of [0,0]
) and end at [-1,-1]
in order to trim 2 from both axes?
Upvotes: 1
Views: 664
Reputation: 46530
You don't have to "alter" the image, you can just slice it. Either before or after, which may have subtly different effects at the edge:
output = cv2.filter2D(image, -1, kernel)[1:-1, 1:-1]
or
output = cv2.filter2D(image[1:-1, 1:-1], -1, kernel)
Upvotes: 2