Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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