create a colormap for distance between CC

9 visualizaciones (últimos 30 días)
Noy Danino
Noy Danino el 15 de Ag. de 2017
Editada: Noy Danino el 20 de Ag. de 2017
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 comentarios
Baptiste Ottino
Baptiste Ottino el 15 de Ag. de 2017
Mazbe this is a silly question, but what do you mean by "CC"?
Noy Danino
Noy Danino el 15 de Ag. de 2017
Connected components, i labeled the objects in the image

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 15 de Ag. de 2017
Editada: Image Analyst el 15 de Ag. de 2017
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);
  1 comentario
Noy Danino
Noy Danino el 20 de Ag. de 2017
Editada: Noy Danino el 20 de Ag. de 2017
I used the histogram to see if the distances are homogenous, but I also want to display it in a color map to see where are the homogenous areas. I don't understand how can I build an image with the function scatteredInterpolant() . this is the code I have so far: (i used a simple image with fewer dots than the attached image in my first question)
%read image bw1 = imread('123.png'); %change form 3D to 2D image bw2 = rgb2gray(bw1); %finds connected components - every cc is a neurofilament cc = bwconncomp(bw2); %finds centroid(x,y) of every CC s=regionprops('table',cc,'Centroid'); %change the centroids from a table to a vector centroids = cat(1,s.Centroid);
%Display binary image with centroid locations superimposed. figure(01) imshow(bw2) hold on plot(centroids(:,1),centroids(:,2), 'b*') hold off
d2=pdist2(centroids,centroids); % calculate distance between every centroid to all other centroids d2(~d2) = nan; %delete zero from distance matrix. zero means distance between a cc to itself mindist=min(d2,[],2); %find the minimun distance between every centroid to all others mindistnorm=mindist.*(5/3); %changing the scale form pixles to nano-meters
F = scatteredInterpolant(centroids(:,1),centroids(:,2),mindistnorm);
the data: centroids =
48.5525 665.0433
85.5525 96.0433
160.5525 503.0433
187.5525 42.0433
648.5525 97.0433
708.5525 665.0433
mindistnorm =
328.2445
192.3538
328.2445
192.3538
773.7822
951.9337
how can I apply this data on the original image? instead of creating a new one

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by