seperatekernel.m
来自「This function seperates a 2D matrix into」· M 代码 · 共 29 行
M
29 行
%%
% This function seperates a 2D matrix into its X and Y components if by
% definition the kernel is seperable (rank==1).
% Sample Usage:
% G=fspecial('gaussian',3); % Create a 3x3 Gaussian kernel.
% [X Y]=SeperateKernel(G);
% I designed this algorithm to do automatic convolution. If the kernel is
% seperable one could easily use seperable convolution, while on the other
% hand if kernel cannot be seperated one could use FFT convolution.
function [X Y]=SeperateKernel(K)
% if rank is not 1, matrix is not seperable
if (rank(K)~=1)
error('Matrix is not seperable');
end
% Compute Singular Value Decomposition
[U,S,V] = svd(K);
% Extract X from first column of U
X = U(:,1) * sqrt(S(1,1));
% Extract Y from first column of V
Y = V(:,1)' * sqrt(S(1,1));
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?