Skip to content

Instantly share code, notes, and snippets.

@maheshmc2
Created February 19, 2011 04:43
Show Gist options
  • Save maheshmc2/834825 to your computer and use it in GitHub Desktop.
Save maheshmc2/834825 to your computer and use it in GitHub Desktop.
Distance Histogram...
function [Centroid, Area, Eccentricity, Perimeter, shape_histogram] = DAC(imgname)
%% Basic Processing
I = imgname;
I = rgb2gray(I);
threshold = graythresh(I);
BW = im2bw(I, threshold);
BW = ~BW;
%% Extract Required Areas. OR AREAS
[B,L] = bwboundaries(BW,'noholes');
%% Extract CENTROID ProperTY
statsCentroid =regionprops(L, 'Centroid');
statsArea = regionprops(L, 'Area');
statsEccentricity =regionprops(L, 'Eccentricity');
statsPerimeter = regionprops(L, 'Perimeter');
Centroid = [statsCentroid.Centroid];
Area = cell2mat({statsArea.Area});
Eccentricity = cell2mat({statsEccentricity.Eccentricity});
Perimeter = cell2mat({statsPerimeter.Perimeter});
%% Centroidal Distance Matrix
ind = 1;
boundary = B{ind};
distance_hist = zeros(size(boundary, 1),1);
centrx = Centroid(2*ind-1);
centry = Centroid(2*ind);
for i= 1:length(boundary)
xx = boundary(i, 1);
yy = boundary(i, 2);
distance_hist(i) = sum(([centrx, centry]- [xx, yy]).^2).^0.5;
end
%% Histogram Normalization
xmin = min(distance_hist(:));
xmax = max(distance_hist(:));
if xmin == xmax
shape_histogram = nan(size(distance_hist));
else
shape_histogram = (distance_hist-xmin)./(xmax-xmin);
end
%% RETURN NULL IF NOT PROPER DAC
if(size(B, 1) > 1)
Area = 0;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment