📄 plus_filt1d.m
字号:
function [data_out, kernel] = plus_filt1D(data_in, x, mu, sigma, sigma_width)
% function to calculate PLUS edge detector with with 1D kernel is
% the special case of normal 2D PLUS filter (see plus_filt2D.m)
% Depending on syntax, it uses either 1D gaussian kernel or a linear derivative
% kernel in form of [-1 N*0 1], where N is the odd number of zeros, or any other
% kernel supplied through the variable X. For linear case only one (DATA_IN) or two
% input variables (DATA_IN and X)are used and in this case X must be a vector.
% First and second derivative kernels are the same size
%
%INPUTS:
% DATA_IN - input vector or array
% X - vector in form of [-1 N*0 1] containing derivative kernel in linear
% case or number of points for Gaussian kernel. In case when only two input
% variables exist (DATA_IN and X) length of the X determines which kernel
% will be used - linear (X==vector) or Gaussian (X==scalar)
% MU - mean of the gaussian
% SIGMA - standard deviation of a gaussian function
% sigma_width- defines where to cut the Gaussian kernel tails (or width of
% the kernel in sigma). Bigger number- more of Gaussian included in the kernel.
% Defaul value= 3 or 98% of Gaussian
%
%OUTPUTS:
% DATA_OUT- filtered data output
% KERNEL - first derivative kernel used for filtering
%
%WARNING: Derivatives for some pixels may be zero. This produce an error "divideByZero"
% and such pixels gets value =NaN. It is recomended to check for NaNs after
% filtering and replacing it with value of convenience -> zero, global minimum, etc.
% To find all NaNs, Inf and -Inf and set them to zero you may use the following line:
% data_out(~isfinite(data_out)) = 0;
%
%EXAMPLES:
%X = imread('tire.tif'); imagesc(X); colormap gray;
%%This image can be found at \MATLAB704\toolbox\images\imdemos
%
%%Try one of the following:
%[dd, kernel] = plus_filt1D(X); dd = dd ./(max(dd(:)));
%figure; imagesc(dd> 0.01); colormap gray;
%[dd, kernel] = plus_filt1D(X, [-1 0 0 0 0 0 0 0 0 0 1]); dd = dd ./(max(dd(:)));
%figure; imagesc(dd> 0.01); colormap gray; colorbar
%
%%OR
%
%[dd, kernel1] = plus_filt1D(X, 11, 0, 1, 3); %1
%dd = dd ./(max(dd(:))); figure; imagesc(dd> 0.1); colormap gray;
%[dd, kernel2] = plus_filt1D(X, 15, 0, 1, 3); %2
%dd = dd ./(max(dd(:))); figure; imagesc(dd> 0.1); colormap gray;
%[dd, kernel3] = plus_filt1D(X, 21, 0, 1, 3); %2
%dd = dd ./(max(dd(:))); figure; imagesc(dd> 0.1); colormap gray;
%figure; plot(kernel1, 'r.-'); hold on;
%plot(kernel2, 'b.-'); plot(kernel3, 'k.-'); grid; axis tight
%
%REF:
%1 Marr D., Hildreth E.C. in 揟heory of edge Detection
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -