clustered image output?
2 views (last 30 days)
Show older comments
Heloooo........ Iam working on pothole images. The foremost step is to apply spectral clustering algorithm on original pothole images. I have given input as to segment it in to two number of clusters i.e., K = 2. The below is the output of clustering image i have attached, it seems to be binary image but the values are (200x200 double), the background values are covering the values 1's and the pothole area(object) as 2's. Could any plz help me in understanding what type of image is it i.e., wheather it is gray scale..?.Below is the code for spectral clustering.
clc;
clear all;
close all;
FileName = 'C:\Users\Admin\Desktop\pothol.jpg';
k = 2; % Number of Clusters
Neighbors = 10; % Number of Neighbors
roundColors = 0; % Round color values for less strict uniqueness
roundDigits = 2; % Precision for Uniqueness
saveData = 0; % Save Dataset
markEdges = 0; % Outline edges
% =============
FileName = fullfile(FileName);
I = imread(FileName);
imageSize = [200 200];
Img = imresize(I,imageSize);
figure,imshow(Img);
[m, n, d] = size(Img);
% convert into list of data points
Data = reshape(Img, 1, m * n, []);
if d >= 2
Data = (squeeze(Data))';
end
% convert to double and normalize to [0,1]
Data = double(Data);
Data = normalizeData(Data);
if isequal(saveData, 1)
[savePath, saveFile, ~] = fileparts(FileName);
csvwrite(fullfile(relativepath(savePath), ...
[saveFile '.nld']), Data');
end
% Find unique colors
if isequal(roundColors, 1)
fac = 10^roundDigits;
rData = round(Data * fac) / fac;
else
rData = Data;
end
[~, ind, order] = unique(rData', 'rows', 'R2012a');
% crop data
Data = Data(:, ind);
% now for the clustering
fprintf('Creating Similarity Graph...\n');
SimGraph = SimGraph_NearestNeighbors(Data, Neighbors, 1);
try
comps = graphconncomp(SimGraph, 'Directed', false);
fprintf('- %d connected components found\n', comps);
end
fprintf('Clustering Data...\n');
C = SpectralClustering(SimGraph, k, 2);
% convert and restore full size
D = convertClusterVector(C);
D = D(order);
% reshape indicator vector into m-by-n
S = reshape(D, m, n);
% choose colormap
if k == 2
map = [0 0 0; 1 1 1];
else
map = zeros(3, k);
for ii = 1:k
ind = find(D == ii, 1);
map(:, ii) = rData(:, ind);
end
map = map';
end
% plot image
set(gca, 'Position', [0 0 1 1], 'Units', 'Normalized');
if isequal(markEdges, 1)
imshow(Img, 'Border', 'tight');
lS = label2rgb(S);
BW = im2bw(lS, graythresh(lS));
[B, L] = bwboundaries(BW, 'holes');
hold on;
for k = 1:length(B)
boundary = B{k};
plot(boundary(:, 2), boundary(:, 1), 'r', 'LineWidth', 2)
end
hold off;
else
imshow(S, map, 'Border', 'tight');
end
0 Comments
Answers (0)
See Also
Categories
Find more on Import, Export, and Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!