Skip to content

Instantly share code, notes, and snippets.

@tony01111299
Created December 29, 2015 08:57
Show Gist options
  • Save tony01111299/ee48651b0c0b168a5549 to your computer and use it in GitHub Desktop.
Save tony01111299/ee48651b0c0b168a5549 to your computer and use it in GitHub Desktop.
Gaussian sharpen
function h = fgaussian(S, sigma, normalize)
N = S(1);
if size(S, 2) == 2
M = S(2);
else
M = N;
end
if nargin < 3
normalize = 1;
end
Xind = -floor(M/2) : M-floor(M/2)-1;
Yind = -floor(N/2) : N-floor(N/2)-1;
[X, Y] = meshgrid(Xind, Yind);
%// Create Gaussian Mask
h = exp(-(X.^2 + Y.^2) / (2*sigma*sigma));
%// Normalize so that total area (sum of all weights) is 1
if normalize
h = h / sum(h(:));
end
end
function [O, invFG] = GaussianSharpen(M, sigma, lambda)
F = fft2(M);
G = fgaussian(size(M), sigma);
FG = fft2(G);
invFG = FG./(lambda + FG.^2);
% invFG = invFG/max(max(abs(invFG)));
F2 = F.*invFG;
O = fftshift(ifft2(F2));
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment