HighPass & LowPass Guassian Filter
17 views (last 30 days)
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
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);
0 Comments
Image Analyst
on 6 Feb 2013
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!