def harris_feature(im, region_size=<NUM_LIT:5>, to_return='<STR_LIT>', scale=<NUM_LIT>):
ndim = im.ndim<EOL>grads = [nd.sobel(im, axis=i) for i in range(ndim)]<EOL>matrix = np.zeros((ndim, ndim) + im.shape)<EOL>for a in range(ndim):<EOL><INDENT>for b in range(ndim):<EOL><INDENT>matrix[a,b] = nd.filters.gaussian_filter(grads[a]*grads[b],<EOL>region_size)<EOL><DEDENT><DEDENT>if to_return == '<STR_LIT>':<EOL><INDENT>return matrix<EOL><DEDENT>trc = np.trace(matrix, axis1=<NUM_LIT:0>, axis2=<NUM_LIT:1>)<EOL>det = np.linalg.det(matrix.T).T<EOL>if to_return == '<STR_LIT>':<EOL><INDENT>return trc, det<EOL><DEDENT>else:<EOL><INDENT>harris = det - scale*trc*trc<EOL>return harris<EOL><DEDENT>
Harris-motivated feature detection on a d-dimensional image.

Parameters
---------
    im
    region_size
    to_return : {'harris','matrix','trace-determinant'}