Hello All,
I want to highpass filter gray scale images of size m x n (m~=n) for
my experiment. I use the follwing code. It seems to work fine except
that I see a grid of blotches at certain cutoff frequencies. Such
blotches don't appear when I use the highpass filtering function in
PhotoShop at the same cutoff frequencies. Your suggestions are
greatly appreciated!
Thanks
Mani
---------------------------------------------------------------------
function HP = highpass(imageMatrix,cutoffFreq)
%function HP = highpass(imageMatrix,cutoffFreq)
imageMatrix = double(imageMatrix);
s = size(imageMatrix);
fnyquist = min(s)/2;
if nargin < 2
cutoffFreq = 22;
end
fc = cutoffFreq/fnyquist;
imft = fftn(double(imageMatrix));
imftshift = fftshift(imft);
[f1 f2] = freqspace(size(imageMatrix),'meshgrid');
z = (f1.^2 + f2.^2) > fc^2;
SFT = imftshift.*z;
IMFT = ifftshift(SFT);
HP = ifftn(IMFT);
HP = rescale(HP);
HP = im2uint8(HP);
%--------------------------------------------------------------------
------
function HP = rescale(HP)
% rescaling the image
mi = min(min(HP));
ma = max(max(HP));
d = ma - mi;
inv_d = 1/d;
HP = HP - mi; % sets the lowest value to zero
HP = HP*inv_d;
I want to highpass filter gray scale images of size m x n (m~=n) for
my experiment. I use the follwing code. It seems to work fine except
that I see a grid of blotches at certain cutoff frequencies. Such
blotches don't appear when I use the highpass filtering function in
PhotoShop at the same cutoff frequencies. Your suggestions are
greatly appreciated!
Thanks
Mani
---------------------------------------------------------------------
function HP = highpass(imageMatrix,cutoffFreq)
%function HP = highpass(imageMatrix,cutoffFreq)
imageMatrix = double(imageMatrix);
s = size(imageMatrix);
fnyquist = min(s)/2;
if nargin < 2
cutoffFreq = 22;
end
fc = cutoffFreq/fnyquist;
imft = fftn(double(imageMatrix));
imftshift = fftshift(imft);
[f1 f2] = freqspace(size(imageMatrix),'meshgrid');
z = (f1.^2 + f2.^2) > fc^2;
SFT = imftshift.*z;
IMFT = ifftshift(SFT);
HP = ifftn(IMFT);
HP = rescale(HP);
HP = im2uint8(HP);
%--------------------------------------------------------------------
------
function HP = rescale(HP)
% rescaling the image
mi = min(min(HP));
ma = max(max(HP));
d = ma - mi;
inv_d = 1/d;
HP = HP - mi; % sets the lowest value to zero
HP = HP*inv_d;