Very simple and fast image segmentation code using statistical region merging.
function [Ix, Iy] = srm_imgGrad(I)
% This function outputs the x-derivative and y-derivative of the
% input I. If I is 3D, then derivatives of each channel are
% available in xd and yd.