From de4654c1d781749d63b9daf07fef4ac2ba09da49 Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Tue, 1 Nov 2016 14:24:07 +0100 Subject: [PATCH] [BV] Assignment2 3-5 finished Signed-off-by: Jim Martens --- bv/hist_dist_Euclidean.m | 18 ++++++++++++++++++ bv/hist_dist_Manhattan.m | 14 ++++++++++++++ bv/hist_dist_intersection.m | 15 +++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 bv/hist_dist_Euclidean.m create mode 100644 bv/hist_dist_Manhattan.m create mode 100644 bv/hist_dist_intersection.m diff --git a/bv/hist_dist_Euclidean.m b/bv/hist_dist_Euclidean.m new file mode 100644 index 0000000..c3fe042 --- /dev/null +++ b/bv/hist_dist_Euclidean.m @@ -0,0 +1,18 @@ +function [ distance ] = hist_dist_Euclidean( h1, h2 ) +%HIST_DIST_EUCLIDEAN Calculates euclidean distance between histograms + + sum_of_differences = 0; + s = size(h1); + if s(1) > 1 + n = s(1); + else + n = s(2); + end + for i = 1:n + sum_of_differences = sum_of_differences + (h1(i) - h2(i))^2; + end + + distance = sqrt(sum_of_differences); + +end + diff --git a/bv/hist_dist_Manhattan.m b/bv/hist_dist_Manhattan.m new file mode 100644 index 0000000..f3c50fa --- /dev/null +++ b/bv/hist_dist_Manhattan.m @@ -0,0 +1,14 @@ +function [ distance ] = hist_dist_Manhattan( h1, h2 ) +%HIST_DIST_MANHATTAN Calculates the Manhattan distance between 2 histograms + distance = 0; + s = size(h1); + if s(1) > 1 + n = s(1); + else + n = s(2); + end + for i = 1:n + distance = distance + abs(h1(i) - h2(i)); + end +end + diff --git a/bv/hist_dist_intersection.m b/bv/hist_dist_intersection.m new file mode 100644 index 0000000..40a9dbc --- /dev/null +++ b/bv/hist_dist_intersection.m @@ -0,0 +1,15 @@ +function [ intersection ] = hist_dist_intersection( h1, h2 ) +%HIST_DIST_INTERSECTION Calculates intersection between 2 histograms + + intersection = 0; + s = size(h1); + if s(1) > 1 + n = s(1); + else + n = s(2); + end + for i = 1:n + intersection = intersection + min(h1(i), h2(i)); + end +end +