Browse Source

Init second assignment, Add Image2Graph

master
Apostolos Fanakis 6 years ago
parent
commit
dfeaaf255f
  1. 33
      Assignment_2/Image2Graph.m
  2. 36
      Assignment_2/Image2Graph.m~
  3. 7
      Assignment_2/README.md
  4. BIN
      Assignment_2/aff_d2a.png
  5. BIN
      Assignment_2/dip_hw_2.mat

33
Assignment_2/Image2Graph.m

@ -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

36
Assignment_2/Image2Graph.m~

@ -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

7
Assignment_2/README.md

@ -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

BIN
Assignment_2/aff_d2a.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
Assignment_2/dip_hw_2.mat

Binary file not shown.
Loading…
Cancel
Save