create a colormap for distance between CC
조회 수: 9 (최근 30일)
이전 댓글 표시
Hey, I have a BW image. the image is with white background and a lot of black objects. I wrote an algorithm that finds the nearest neighbor for every object. it works like that: find all CC, then find a centroid for everyone, measure distance between centroids and find the minimum distance for everyone. now I want to create a colormap to see where in my image are the smallest distances and to find out if the distances are homogenous. I want to define a range of distance in pixels for every color and then create a map. I have no idea how to create this kind of map. when I find the nearest neighbors I lose the location of them, all I have is the measure of distance between pixels and the number of the CC that was found to be the closest.
any ideas? attached my original image and an example of a colormap.
댓글 수: 2
답변 (1개)
Image Analyst
2017년 8월 15일
편집: Image Analyst
2017년 8월 15일
Use scatteredInterpolant() to build up a complete image, then apply your colormap. Attach your data (list of x,y,distance data) if you still need help.
To find out if the distances are homogenous, you can take the histogram. The narrower the histogram is, the more homogenous it is, the wider it is, the less homogenous it is. You can also construct a fry plot. See the bible on spatial statistics by Adrian Beddeley http://umaine.edu/computingcoursesonline/files/2011/07/SpatstatmodelingWorkshop.pdf
Here's a snippet from my attached simulation code (attached above) that constructs a Fry plot. It might need some editing
% Construct Fry Plot
[rows, columns] = size(binaryImage);
fryPlot = zeros(2 * rows, 2 * columns);
[yPoints, xPoints] = find(binaryImage);
radialProfile = zeros(1, round(2 * sqrt(rows^2 + columns^2)));
sumOfRadii = 0;
numPoints = length(yPoints); % Number of points in the binary image.
for p1 = 1 : numPoints
for p2 = 1 : numPoints
if p2 == p1
continue;
end
deltaRow = yPoints(p2) - yPoints(p1) + rows;
deltaCol = xPoints(p2) - xPoints(p1) + columns;
fryPlot(deltaRow, deltaCol) = fryPlot(deltaRow, deltaCol) + 1;
radius = sqrt((deltaRow - rows)^2 + (deltaCol - columns)^2);
% Add it into the mean profile, but need to round radius to the nearest integer greater than 0.
index = round(radius)+1;
radialProfile(index) = radialProfile(index) + 1;
% Sum up the radius so we can get the mean radius.
sumOfRadii = sumOfRadii + radius;
end
end
% Get the average radius
meanRadius = sumOfRadii / (numPoints * (numPoints-1));
% axes(handles.axes2);
figure;
subplot(2, 2, 1);
% Central point is so huge because every point is zero distance from itself.
% But the ring 1 pixel away is zero because we said there could be no pixels adjacent to other pixels.
fryPlot(rows, columns) = 0; % Zero out the origin because it will have the most because every point is zero distance from itself.
% Now get mean values in a line above the center.
neighboringMean = mean(fryPlot(rows-2, columns-1:columns+1));
fryPlot(rows-1:rows+1, columns-1:columns+1) = neighboringMean; % Zero out the origin because it will have the most because every point is zero distance from itself.
imshow(fryPlot, []);
title('Fry Plot', 'FontSize', fontSize);
% Show the mean radius as a circle over the fry plot
hold on;
viscircles([columns, rows], meanRadius);
% Display histogram of radii
subplot(2, 2, 2);
histogram(fryPlot(fryPlot>0));
grid on;
title('Histogram of Radii in Fry Plot', 'FontSize', fontSize);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!