I_orig = imread('cusp_micro.jpg');
I = rgb2gray(I_orig);
BW_peaks = im2bw(I);
distFromPeaks = bwdist(BW_peaks);
maxDistsMask = imregionalmax(distFromPeaks);
[trI,trJ] = find(maxDistsMask);
trVals = I(maxDistsMask);
tr2pkDists = distFromPeaks(maxDistsMask);
pkInds = find(BW_peaks);
[pkI,pkJ] = ind2sub(size(BW_peaks),pkInds);
trPartnerPkVals = zeros(size(trI));
for i = 1:length(trI)
tr2allPkDists = sqrt((pkI-trI(i)).^2 + (pkJ-trJ(i)).^2);
withinRangeMask = tr2allPkDists < (tr2pkDists(i) + 5);
trPartnerPkVals(i) = max(I(pkInds(withinRangeMask)));
end
I_norm = double(I)/double(max(I(:)));
figure, imshow(cat(3,I_norm,max(BW_peaks, I_norm),I_norm)), hold on
plot(trJ,trI,'m.')
figure, plot(sort(tr2pkDists)), title 'Distribution of cusp spacing'
figure, plot(sort(trPartnerPkVals - double(I(maxDistsMask))))
title 'Distribution of roughness'
Best Answer