You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
function myAffinityMat = Image2Graph (imIn)
|
|
%Image2Graph produces a graph, in the form of a matrix, from an image
|
|
% Usage myAffinityMat = Image2Graph (imIn), where:
|
|
% Inputs
|
|
% - imIn is the input image
|
|
% Output
|
|
% - myAffinityMat is the graph produced
|
|
|
|
% Initializes helper variables
|
|
imageWidth = size(imIn, 2);
|
|
imageHeight = size(imIn, 1);
|
|
|
|
% Initializes output matrix
|
|
% myAffinityMat = zeros(imageWidth * imageHeight, imageWidth * ...
|
|
% imageHeight);
|
|
|
|
% for row = 1:imageHeight
|
|
% for column = 1:imageWidth
|
|
% % Calculates distance matrix for the current element
|
|
% diff = imIn - imIn(row, column, :);
|
|
% dist = sum(diff .^ 2, 3) .^ 0.5;
|
|
%
|
|
% % Calculates affinity matrix
|
|
% myAffinityMat((row - 1) * imageWidth + column, :) = ...
|
|
% reshape((1 ./ exp(dist)).', 1, []);
|
|
% end
|
|
% end
|
|
|
|
som = reshape(imIn, 1, [], 3);
|
|
diff = repmat(som, imageWidth * imageHeight, 1, 1) - permute(som, [2 1 3]);
|
|
dist = sum(diff .^ 2, 3) .^ 0.5;
|
|
myAffinityMat = 1 ./ exp(dist);
|
|
end
|
|
|