Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python : 2d convolution by using numpy I used this dog picture and coded it using only numpy. However, in the im_fillter function part, error

python : 2d convolution by using numpy

I used this dog picture and coded it using only numpy. However, in the im_fillter function part, error : the phrase 6 appears. Please tell me how to modify it.

The code is as follows

image text in transcribed

image text in transcribed

In [1]: import numpy as np from matplot lib import pyplot as p import cv2 In [2] : def my_imfilter( image, kernel): filtered_image = np.zeros( image. shape) image_padded = np.zeros(( image. shape[0] + 2, image. shape[1] + 2,)) image_padded[1:-1, 1:-1] = image for x in rangel image. shape[1]): for y in range( image. shape[0]): filtered_image[y, x]=(kernel + image_padded[y: yu3, X: X+3] ). sum() print('my_imfilter function in student.py needs to be implemented') return filtered_image In [3] : img = cv2. imread("dog.jpg") image = cv2.cvt Color (img, cv2.COLOR_BGR2RGB) In [4] : kernel = np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]]) In [5]: filtered_img = my_imfilter( image, kernel) ValueError Traceback (most recent call last) in ----> 1 filtered_img = my_imfilter( image, kernel) in my_imfilter(image, kernel) 4 5 image_padded = np.zeros(( image. shape[O] + 2, image. shape[1] + 2,)) ----> 6 image_padded[1:-1, 1:-1] = image 7 8 for x in rangel image. shape[1]): ValueError: could not broadcast input array from shape (174, 290, 3) into shape (174,290)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions

Question

305 mg of C6H12O6 in 55.2 mL of solution whats the molarity

Answered: 1 week ago