Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Created September 12, 2014 18:38
Show Gist options
  • Select an option

  • Save tonyfast/11fd4ba182ade4f930e3 to your computer and use it in GitHub Desktop.

Select an option

Save tonyfast/11fd4ba182ade4f930e3 to your computer and use it in GitHub Desktop.
Edge Detection for Binary Images in Matlab
function edge = binary_edge( image )
% An approximate algorithm for finding edges in binary images.
%
% The algorithm shifts the images one voxel in each direction.
% It compares the difference betwee the original image and the shifted image.
% Nonzero values indicate edge values
DIMS = ndims(image);
shifts = vertcat( eye(DIMS), ...
-1*eye(DIMS));
edge = zeros( size( image ) );
for ii = 1 : size( shifts, 1 )
edge(:) = edge + ...
abs( image - circshift( image, shifts( ii, : ) ) );
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment