Apostolos Fanakis
6 years ago
5 changed files with 76 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||
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 |
@ -0,0 +1,36 @@ |
|||
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 |
|||
|
|||
imageWidth = size(imIn, 2); |
|||
imageHeight = size(imIn, 1); |
|||
imageChannels = size(imIn, 3); |
|||
|
|||
%myAffinityMat = 1 / exp(norm(imIn(:, :))); |
|||
myAffinityMat = zeros(imageWidth * imageHeight, imageWidth * imageHeight); |
|||
|
|||
for row = 1:imageHeight |
|||
for column = 1:imageWidth |
|||
diff = imIn - imIn(row, column, :); |
|||
%diffT = permute(diff, [2 1 3]); |
|||
|
|||
dist = sum(diff .^ 2, 3) .^ 0.5; |
|||
|
|||
% dist = zeros(imageWidth, imageHeight); |
|||
% for channel = 1:imageChannels |
|||
% dist = dist + sqrt(sum (diff(:, :, channel) * diffT(:, :, channel))); |
|||
% dist = dist + sqrt(diff(:, :, channel) * diffT(:, :, channel)); |
|||
% end |
|||
|
|||
som = 1 ./ exp(dist); |
|||
som2 = reshape(som, 1, []); |
|||
som2 = reshape(som.', 1, []); |
|||
|
|||
myAffinityMat((row - 1) * imageWidth + column, :) = reshape((1 ./ exp(dist), 1, []); |
|||
end |
|||
end |
|||
end |
@ -0,0 +1,7 @@ |
|||
# Second deliverable |
|||
|
|||
In the second deliverable we were tasked to implement a number of functions that: |
|||
- produce a graph representation of an image |
|||
- do image segmentation using spectral clustering |
|||
- do image segmentation using the normalized cuts (N-cuts) method, in both an imperative and recursive way |
|||
- execute a series of experiments to test the results of our code |
After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
Loading…
Reference in new issue