cluster analysis from edge detection
Ältere Kommentare anzeigen
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)
Akzeptierte Antwort
Weitere Antworten (1)
Anna Marshall
am 4 Mai 2020
0 Stimmen
6 Kommentare
Anna Marshall
am 4 Mai 2020
Image Analyst
am 4 Mai 2020
I think it should be
% 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(:, 1);
thisy = thisList(:, 2);
coefficients = polyfit(thisx, thisy, 1); % Fit to a line
angles(k) = atand(coefficients(1));
end
Anna Marshall
am 4 Mai 2020
Image Analyst
am 4 Mai 2020
Anna, this code works but it looks like you're still missing quite a few edges with that filter.
% Initialization steps. Brute force cleanup of everything currently existing to start with a clean slate.
% Just for the demo. If you put this into your own function you'll want to get rid of the close and clear commands.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
rgbImage = imread('DJI_0022.jpg'); %inputs image
hFig = figure;
subplot(2, 2, 1);
imshow(rgbImage)
axis('on', 'image');
impixelinfo;
title('Original RGB Image', 'FontSize', 20);
grayImage = rgb2gray(rgbImage); %convers to grayscale
subplot(2, 2, 2);
imshow(grayImage)
axis('on', 'image');
impixelinfo;
title('Gray Scale Image', 'FontSize', 20);
edgeImage = edge(grayImage, 'Canny', 0.6);
subplot(2, 2, 3);
imshow(edgeImage)
axis('on', 'image');
title('Canny Edge Image', 'FontSize', 20);
hFig.WindowState = 'maximized';
drawnow;
% Get coordinates and plot a line over them.
imshow(grayImage)
axis('on', 'image');
title('Line Grouping', 'FontSize', 20);
hFig.WindowState = 'maximized';
drawnow;
props = regionprops(edgeImage, 'PixelList', 'Centroid');
lineLength = 20; % Whatever you want.
hold on;
lineColorMap = jet(181); % One color for every 1 degrees.
angles = zeros(1, length(props));
for k = 1 : length(props)
thisList = props(k).PixelList;
fprintf('\nFor blob #%d of %d:\n ', k, length(props))
thisx = thisList(:, 1);
thisy = thisList(:, 2);
coefficients = polyfit(thisx, thisy, 1); % Fit to a line
angles(k) = atand(coefficients(1 ));
% Get the centroid
x = props(k).Centroid(1);
y = props(k).Centroid(2);
% Get the line endpoints.
x1 = x + lineLength * cosd(angles(k));
x2 = x - lineLength * cosd(angles(k));
y1 = y + lineLength * sind(angles(k));
y2 = y - lineLength * sind(angles(k));
thisColor = lineColorMap(round(angles(k) + 90) + 1, :);
fprintf('Drawing line from (%.1f to %.1f) to (%.1f, %.1f)\n', x1, y1, x2, y2); line([x1,x2], [y1,y2], 'Color', thisColor);
if mod(k, 100) == 0
drawnow;
end
end
% Plot the histogram of angles.
subplot(2, 2, 4)
histObject = histogram(angles);
grid on;
xlabel('Angle', 'FontSize', 20);
ylabel('Count', 'FontSize', 20);
title('Histogram of angles', 'FontSize', 20);
Anna Marshall
am 4 Mai 2020
Anna Marshall
am 14 Mai 2020
Kategorien
Mehr zu Object Analysis finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
