Is there any built-in function for doing convolution only for a subset of pixels on the image?
Basically, I know the coordinates of these points and I want to get the results of applying convolution kernel centered at these points.
I want to use it in my implementation of Hessian-Laplace feature detector. I don't want to build the whole scale space cube, I want to apply Laplacian only to interest points found by Hessian detector.
Thank you.
Edit:
I am searching for a function that will have the following signature:
function [ results ] = selected_conv( input_matrix, ...
coords, kernel, border_treatment_mode )
Example of usage:
% define the kernel and the input image
h = [1 2 3;
0 0 0;
6 5 4];
I = [1 5 2 3;
8 7 3 6;
3 3 9 1]
% Points coordinates in original image to convolve.
points_coords_to_convolve = [[2, 2]; [2, 3]];
% The third parameter is a parameter like for padarray(): 'zeros', 'replicate', 'symmetric'.
result = selected_conv(I, h, 'zeros')
Output:
[65, 76]
Break-down of the above code:
Kernel matrix is always of uneven size. Rotate our kernel matrix 180 degrees. (How it is usually done with convolution). Result for our code:
h = [4 5 6; 0 0 0; 3 2 1];We check if for all specified points the kernel fits into the matrix. Otherwise, we pad our matrix with one of possible padding techniques: 'zeros', 'replicate', 'symmetric'. The process of padding is identical to
padarray()function in matlab.- Center the rotated kernel on each of the specified points of the original image and compute the response. Proceed the same way for all the specified points. In our example
[[2, 2]; [2, 3]]. The first number of each row is a row number, and the second one is the column number. In our case it will be numbers7and3or the original matrix. - The response for the first number is
4 + 5*5 + 6*2 + 3*3 + 2*3 + 9 = 65.
My code for nlfileter():
function [ results ] = selected_nlfilter( input_matrix, coords, ...
func_handler, sliding_window_size, border_treatment_mode )
Kernel_x = sliding_window_size(1);
Kernel_y = sliding_window_size(2);
pad_row = floor(Kernel_x/2);
pad_col = floor(Kernel_y/2);
padded_matrix = pad_matrix(input_matrix, pad_row, pad_col, border_treatment_mode);
results = zeros(size(coords, 1), 1, 'double');
amount_of_coords = size(coords, 1);
for coord_count = 1:amount_of_coords
row = coords(coord_count, 1);
col = coords(coord_count, 2);
frame = padded_matrix(row:row+(2*pad_row),col:col+(2*pad_col));
sliding_window_size;
results(coord_count) = func_handler(frame);
end
end
I've just applied it with already rotated kernel matrix.