Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created March 14, 2015 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lettergram/63cff51e8502d7c9ebf6 to your computer and use it in GitHub Desktop.
Save lettergram/63cff51e8502d7c9ebf6 to your computer and use it in GitHub Desktop.
Lab gradient filter
% Convert an image to the Lab color space
colorTransform = makecform('srgb2lab');
img = applycform(rgbImg, colorTransform);
% Make it double to improve representation
img = double(img);
% Find x and y derivative of a 9x9 gaussian
[hx, hy] = gradient(fspecial('gaussian',[9 9],sigma));
% Apply filters
gx = double(imfilter(img,hx,'replicate'));
gy = double(imfilter(img,hy,'replicate'));
% Find absolute value
gSquared = sqrt(gx .* gx) + (gy .* gy);
% Apply non-maxima suppression (find best points for edges)
[mag, ] = max(gSquared, [], 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment