cluster analysis from edge detection

9 visualizaciones (últimos 30 días)
Anna Marshall
Anna Marshall el 3 de Mayo de 2020
Comentada: Anna Marshall el 14 de Mayo de 2020
Hello,
I am looking to perform a cluster analysis (K-means) for an image. I've converted the original image to a binary image and performed an edge detection, which should help with the clustering, but am stuck on how to implement a cluster analysis from the binary image. Any suggestions are greatly appreciated! The code for the binary edge detection is below and the image is attached. The end goal here is to identify patterns of wood orientation.
clear
RGB=imread('DJI_0022.jpg'); %inputs image
I=rgb2gray(RGB); %convers to grayscale
figure
imshow(I)
BW1 = edge(I,'Canny',0.6);
imshow(BW1)

Respuesta aceptada

Image Analyst
Image Analyst el 3 de Mayo de 2020
Assuming you have a bunch of blobs that are the tree edges, I'd call regionprops() and ask for 'Orientation'. This will give you the average angle of every blob. You can then histogram the angles if you want.
props = regionprops(edgeImage, 'Orientation');
allAngles = [props.Orientation];
histogram(allAngles);
grid on;
xlabel('Angle', 'FontSize', 20);
ylabel('Count', 'FontSize', 20);
  16 comentarios
Anna Marshall
Anna Marshall el 4 de Mayo de 2020
Interestingly, it does look like the Canny filter lines up well with the wood orientations in the image overlay. Looking back at the code, I'm wondering if the code to find the centroid angles before plotting those lines is what is creating a discrepancy in the colored lines?
Image Analyst
Image Analyst el 4 de Mayo de 2020
You might try getting the PixelList, like I already showed you in your other post, and then put those x,y values into polyfit to get the angle. Something like
% Get coordinates and fit to a line.
props = regionprops(edgeImage, 'PixelList', 'Centroid');
for k = 1 : length(props)
thisList = props(k).PixelList;
fprintf('\nGetting angle for blob #%d of %d.\n ', k, length(props))
thisx = thisList(k2, 1);
thisy = thisList(k2, 2);
coefficients = polyfit(thisx, thisy, 1); % Fit to a line
angles(k) = atand(coefficients(1));
end

Iniciar sesión para comentar.

Más respuestas (1)

Anna Marshall
Anna Marshall el 4 de Mayo de 2020
I'll give it a try! Thanks!
  6 comentarios
Anna Marshall
Anna Marshall el 4 de Mayo de 2020
Thank you!! That works great. I'm going to play around with different filtersm particularly the ridgeline-finding filters and see if there is one that might work a bit better than the canny filter. Thanks again for all the suggestions!!
Anna Marshall
Anna Marshall el 14 de Mayo de 2020
@Image Analyst- I have another question to throw your way! I've been playing around with this code and one thing that I'm looking to try and do is add borders that group together "clusters" of the same colors aka same angles. For example, something like the attached sketch. I've tried the boundary function, but can't get it to work quite right. Do you have any ideas on what might work?

Iniciar sesión para comentar.

Categorías

Más información sobre 3-D Volumetric Image Processing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by