HighPass & LowPass Guassian Filter
Show older comments
Hello,
Are there built-in functions that allow me to create a high pass and low pass Guassian filters?
If not, how to implement these two filters in easy way?
Thanks.
7 Comments
Wayne King
on 6 Feb 2013
Can you please say more about your application. Is this for filtering in the image domain, or for a 1-D signal?
jagannath mishra
on 2 Mar 2013
i also have the same problem and yes this is in the 2-D image processing area.kindly help me. thanks in advance
Yang Jingling
on 11 Dec 2013
Hello, I saw this question which I am also interested. I want to use a low pass Guassian filter for cut-off frequency. Who gets the matlab codes? Please help me! I have no way to get through it.
Image Analyst
on 11 Dec 2013
Did you see my answer below? I guess not, or maybe you did but still didn't know how to do it so I made another answer with an actual demo in it, that perhaps Osaid will officially "Accept" this time.
Yang Jingling
on 13 Dec 2013
Thank you for your reply! I got your codes now. However I want to use the gaussian low-pass filter for a 1-D velocity data, not an image. And I want use the gaussian smoothing function w(t) which is defined by myself. Sorry, my English is poor. I don't know whether I have made myself clear to you.So I list my problems below. First of all, I don't know how to use gaussian filter for the 1-D velocity data.If you have some demos about this, I appreciate for it. Secondly, is it possible to define the smoothing function by users? I want to process the velocity to get a better result, so I want to try to define the smoothing function by myself.
Thank you in advance!
Image Analyst
on 13 Dec 2013
You can use the same code. A 1D array (single line or row of values) is still an image and all the image processing functions will still work on it. You can use a uitable() to have your users enter in some weights.
Yang Jingling
on 26 Dec 2013
Sorry to disturb you. Really hope you could get my message. I still stuck by the 1D gaussian filter, even though I looked for the website you showed.
My codes are below: format long
load 'vel.mat'; %% u v w
N=length(u); %% the length of the data;in my case N=3840; fs=64; %% sampling frequency fn=fs/6; sigma=(log(0.5^0.5)/(-2*pi^2*fn^2))^0.5; %% The function I have to define like this
mask=zeros(1,N); t=0:N/2; mask(1:N/2+1)=(2*pi*sigma^2)^(-0.5).*exp(-t.^2./(2*sigma^2)); %%the smoothing function mask(N:-1:N/2+2)=mask(2:N/2);
ux=fft(u);uft=ux.*mask;uf=ifft(uft); vx=fft(v);vft=vx.*mask;vf=ifft(vft); wx=fft(w);wft=wx.*mask;wf=ifft(wft); figure(1) plot(wf); title('Low-pass filtered signal'); %%%%%-------------------end-of-codes-----------------------------%%
I got only zeros. hope you could help me! Thanks in advance.
Answers (2)
Image Analyst
on 11 Dec 2013
Try this demo for a low pass filter. To get a high pass filter, subtract two kernels of different Gaussian widths (same window size, just different sigmas).
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');
if button == 1
baseFileName = 'cameraman.tif';
elseif button == 2
baseFileName = 'moon.tif';
elseif button == 3
baseFileName = 'eight.tif';
elseif button == 4
baseFileName = 'coins.png';
else
baseFileName = 'pout.tif';
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Create a blurring kernel.
kernel = fspecial('Gaussian', 32, 8);
subplot(2, 2, 2);
imshow(kernel, []);
axis on;
title('Blurring Kernel', 'FontSize', fontSize);
% Blur the image.
blurred = imfilter(grayImage, kernel, 'replicate');
subplot(2, 2, 3);
imshow(blurred);
axis on;
title('Blurred Image', 'FontSize', fontSize);
Image Analyst
on 6 Feb 2013
0 votes
Yes. You can use fspecial() in the Image Processing Toolbox. To get a high pass gaussian, you'd need to subtract two regular Gaussians, each with a different width. This is called a DOG filter or LOG filter, for Difference or Laplacian of Gaussians. Then once you have the filter kernel, you can use imfilter() or conv2() to implement it and create the output image.
1 Comment
yasser
on 19 Jan 2019
Can you simplify your comment with example?
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!