【发布时间】:2015-03-08 15:24:19
【问题描述】:
是否有任何内置函数仅用于进行卷积 图像上的像素子集?
基本上,我知道这些点的坐标,我想得到以这些点为中心应用卷积核的结果。
我想在 Hessian-Laplace 特征检测器的实现中使用它。 我不想构建整个比例空间立方体,我只想将拉普拉斯算子应用于 Hessian 检测器找到的兴趣点。
谢谢。
编辑:
我正在寻找具有以下签名的函数:
function [ results ] = selected_conv( input_matrix, ...
coords, kernel, border_treatment_mode )
使用示例:
% 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')
输出:
[65, 76]
以上代码分解:
-
核矩阵的大小总是不均匀的。将我们的内核矩阵旋转 180 度。 (通常如何使用卷积完成)。我们的代码结果:
h = [4 5 6; 0 0 0; 3 2 1]; 我们检查所有指定点的内核是否适合矩阵。否则,我们使用一种可能的填充技术来填充矩阵:“零”、“复制”、“对称”。 padding的过程与matlab中的
padarray()函数相同。- 在原始图像的每个指定点上居中旋转内核并计算响应。对所有指定的点以相同的方式进行。在我们的示例中
[[2, 2]; [2, 3]]。每行的第一个数字是行号,第二个是列号。在我们的例子中,它将是数字7和3或原始矩阵。 - 第一个号码的响应是
4 + 5*5 + 6*2 + 3*3 + 2*3 + 9 = 65。
我的 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
我刚刚将它与已经旋转的内核矩阵一起应用。
【问题讨论】:
-
在几个点上展示您的代码如何使用?
-
@Divakar,您想要签名还是特定用例?
-
使用一些样本最小输入图像数据、点数组、样本内核并显示所需的输出。解释它必须如何在边界周围表现。很高兴看到问题中涵盖了这些内容。
-
@Divakar,我已经添加了它。实际上,这是我第二次不得不使用这样的功能。我之前已经实现了一个类似的功能,但它不会那么快。 nlfilter 仅适用于选定像素也足够了。但是我没有找到内置函数。
-
您能补充一下您是如何获得所需输出的吗?基本上,我们希望有一个最小的可重现代码,它接收输入数据(正如您已经在问题中添加的那样)并产生所需的输出,当然假设您已经尝试了一些东西。
标签: performance matlab image-processing filtering convolution