How can I make a filter with the Lorentzian peak to use in imfilter?
Mostra commenti meno recenti
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!
Risposta accettata
Più risposte (1)
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);
%% 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);
%% Lorentzian Mask Filter
%% Image Filtering with Lorentz
im = imread('coins.png');
imLoren = imfilter(double(im),maskLoren);
figure;imshow(uint8(imLoren));
1 Commento
Alicia
il 3 Nov 2022
Categorie
Scopri di più su Microscopy in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




