Created
December 29, 2015 08:57
-
-
Save tony01111299/ee48651b0c0b168a5549 to your computer and use it in GitHub Desktop.
Gaussian sharpen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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