DTC Introduction to Programming
Extension Problem for Multidimensional Array Structures
- Write a function in Python that will take this image as input and apply the convolution edge detection filter that I mentioned in the lecture. You will have to:
- Write a subroutine that calculates the convolution between a matrix and a convolution kernel. You will find numpy matrices very helpful.
- Calculate matrices G_{x} and G_{y} using your convolution operator.
- Finally, calculate G from G_{x} and G_{y}. Note that the square and square root calculations in this step are element-wise. The functions you want are numpy.power(matrix,2) and numpy.sqrt(matrix).
Put the processed image back together in .pgm format. Do the results seem sensible?
- Convolution (and therefore, edge detection) can be generalised to higher dimensions. For example, you may wish to perform edge detection in three dimensions to detect the contours of bone in an MRI image. Write down the convolution kernel matrices for three dimensional edge detection. Optional: implement three dimensional edge detection in the language of your choice, on the image of your choice.
CC-BY-3.0