How can I make a filter with the Lorentzian peak to use in imfilter?

15 views (last 30 days)
Hi everyone,
I have been trying to blur images using different functions. Matlab seems to have several options to do this with the gaussian function (I've used Imgaussfilt and fspecial('gaussian'). However, I would now like to do the same for the Lorentzian function.
I know I can do this using Imfilter or simply doing a 2D convolution with conv2, but for both cases I need to make a filter/kernel with the values of my function in a matrix. I am a bit lost at this point, since I'm getting started with matlab, and would appreciate any guidance.
Thank you!

Accepted Answer

DGM
DGM on 3 Nov 2022
I'm not familiar with the distribution or its application here, but here's a start.
% parameters
gam = 7;
fkradius = 20;
% assuming that filter is centered and rotationally symmetric
x = -fkradius:fkradius;
r = sqrt(x.^2 + (x.').^2);
% generate the distribution
fk = 1/(pi*gam) * (gam^2./(r.^2 + gam^2));
% sum-normalize
fk = fk./sum(fk(:));
% just show it (rescaled for viewing)
subplot(1,2,1); imshow(fk,[])
subplot(1,2,2); plot(fk(fkradius+1,:))

More Answers (1)

Maik
Maik on 3 Nov 2022
Edited: Maik on 3 Nov 2022
You can try generating Lorentzian mask by fitting on random or Gaussian data and converting it to mask.
For more customization on the Lorentz fitting you can refer to this: https://in.mathworks.com/matlabcentral/fileexchange/13648-lorentzian-fit
%% Generate Lorentzian Fit for Random Data
rangeLoren = [0 1];
row = 49; col =1 ;
x = randi(rangeLoren, row, col);
vCoeff= [0 1 4 7];
y=vCoeff(1)+(2*vCoeff(2)/pi).*(vCoeff(3)./(4*(x-vCoeff(4)).^2+vCoeff(3).^2));
maskLoren = reshape(y,[7 7]);
disp(maskLoren);
0.0159 0.0120 0.0159 0.0120 0.0120 0.0159 0.0159 0.0120 0.0159 0.0120 0.0159 0.0159 0.0120 0.0120 0.0159 0.0159 0.0120 0.0120 0.0159 0.0159 0.0120 0.0120 0.0159 0.0159 0.0120 0.0159 0.0120 0.0159 0.0120 0.0159 0.0120 0.0159 0.0159 0.0120 0.0159 0.0159 0.0159 0.0120 0.0159 0.0120 0.0120 0.0120 0.0120 0.0120 0.0120 0.0159 0.0159 0.0159 0.0120
%% Lorentzian Mask Filter
%% Image Filtering with Lorentz
im = imread('coins.png');
imLoren = imfilter(double(im),maskLoren);
figure;imshow(uint8(imLoren));
%% Generate Lorentzian fit for Gaussian Data
sigmaLoren = 1.2;
x = fspecial('Gaussian',[row col],sigmaLoren);
figure;plot(x);
vCoeff= [0 2*max(x) 1 2]; % Can be varied or computed
y=vCoeff(1)+(2*vCoeff(2)/pi).*(vCoeff(3)./(4*(x-vCoeff(4)).^2+vCoeff(3).^2));
figure; plot(y);
maskLoren = reshape(y,[7 7]);
disp(maskLoren);
0.0249 0.0249 0.0249 0.0252 0.0249 0.0249 0.0249 0.0249 0.0249 0.0249 0.0270 0.0249 0.0249 0.0249 0.0249 0.0249 0.0249 0.0314 0.0249 0.0249 0.0249 0.0249 0.0249 0.0249 0.0349 0.0249 0.0249 0.0249 0.0249 0.0249 0.0249 0.0314 0.0249 0.0249 0.0249 0.0249 0.0249 0.0249 0.0270 0.0249 0.0249 0.0249 0.0249 0.0249 0.0249 0.0252 0.0249 0.0249 0.0249
%% Lorentzian Mask Filter
%% Image Filtering with Lorentz
im = imread('coins.png');
imLoren = imfilter(double(im),maskLoren);
figure;imshow(uint8(imLoren));

Categories

Find more on Biomedical Imaging in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!