A = randi([0 1], [10 10]); B = mat2gray(A); % To consider the horizontal or vertical connectivity set connectivity parameter = 4. cc = bwconncomp(B, 4); % Calculate area of individual connected component. Area = regionprops(cc,'Area');