From eb02c9880c60af2f108da9da1ac379692d90f068 Mon Sep 17 00:00:00 2001 From: Jakub Nowosad Date: Thu, 28 Mar 2024 17:31:14 +0100 Subject: [PATCH] moves from integers to doubles for centers calculations --- src/create_connectivity.cpp | 4 ++-- src/private_functions.cpp | 12 ++++++------ src/slic.h | 6 +++--- src/writers.cpp | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/create_connectivity.cpp b/src/create_connectivity.cpp index be5ce4f..c7ff826 100644 --- a/src/create_connectivity.cpp +++ b/src/create_connectivity.cpp @@ -82,7 +82,7 @@ void Slic::create_connectivity(doubles_matrix<> vals, cpp11::function avg_fun_fu clusters = new_clusters; - vector > new_centers; + vector > new_centers; vector > new_centers_vals; vector new_center_counts(label); @@ -90,7 +90,7 @@ void Slic::create_connectivity(doubles_matrix<> vals, cpp11::function avg_fun_fu /* Clear the center _vals values. */ for (int m = 0; m < (int) label; m++) { - vector new_center(2); + vector new_center(2); new_center[0] = new_center[1] = 0; new_centers.push_back(new_center); diff --git a/src/private_functions.cpp b/src/private_functions.cpp index 73273c8..b090ba5 100644 --- a/src/private_functions.cpp +++ b/src/private_functions.cpp @@ -24,7 +24,7 @@ void Slic::create_centers(vector mat_dims, doubles_matrix<> vals, std::string& dist_name, cpp11::function dist_fun, double step) { for (int ncolcenter = step/2; ncolcenter < mat_dims[1]; ncolcenter += step){ for (int nrowcenter = step/2; nrowcenter < mat_dims[0]; nrowcenter += step){ - vector center; center.reserve(2); + vector center; center.reserve(2); int ncell = ncolcenter + (nrowcenter * mat_dims[1]); vector colour; colour.reserve(mat_dims[2]); for (int nval = 0; nval < mat_dims[2]; nval++){ @@ -32,7 +32,7 @@ void Slic::create_centers(vector mat_dims, doubles_matrix<> vals, colour.push_back(val); } - vector lm = find_local_minimum(vals, nrowcenter, ncolcenter, dist_name, dist_fun); + vector lm = find_local_minimum(vals, nrowcenter, ncolcenter, dist_name, dist_fun); /* Generate the center vector. */ center.push_back(lm[0]); @@ -53,7 +53,7 @@ void Slic::create_centers2(vector mat_dims, int ncell = 0; for (int i = 0; i < input_centers.nrow(); i++){ int nrowcenter = input_centers(i, 1); int ncolcenter = input_centers(i, 0); - vector center; center.reserve(2); + vector center; center.reserve(2); vector colour; colour.reserve(mat_dims[2]); for (int nval = 0; nval < mat_dims[2]; nval++){ double val = vals(ncell, nval); @@ -61,7 +61,7 @@ void Slic::create_centers2(vector mat_dims, } ncell++; - vector lm = find_local_minimum(vals, nrowcenter, ncolcenter, dist_name, dist_fun); + vector lm = find_local_minimum(vals, nrowcenter, ncolcenter, dist_name, dist_fun); /* Generate the center vector. */ center.push_back(lm[0]); @@ -120,11 +120,11 @@ double Slic::compute_dist(int& ci, int& y, int& x, vector& values, return sqrt((dist1 * dist1) + (dist2 * dist2)); } -vector Slic::find_local_minimum(doubles_matrix<> vals, int& y, int& x, +vector Slic::find_local_minimum(doubles_matrix<> vals, int& y, int& x, std::string& dist_name, cpp11::function dist_fun) { double min_grad = FLT_MAX; - vector loc_min(2); + vector loc_min(2); loc_min.at(0) = y; loc_min.at(1) = x; diff --git a/src/slic.h b/src/slic.h index a9b4a21..97fcfb8 100644 --- a/src/slic.h +++ b/src/slic.h @@ -30,7 +30,7 @@ class Slic { vector mat_dims; /* The values of the centers. */ - vector > centers; + vector > centers; vector > centers_vals; /* The number of occurrences of each center. */ @@ -59,7 +59,7 @@ class Slic { std::string& dist_name, cpp11::function dist_fun); /* Find the pixel with the lowest gradient in a 3x3 surrounding. */ - vector find_local_minimum(doubles_matrix<> vals, int& y, int& x, + vector find_local_minimum(doubles_matrix<> vals, int& y, int& x, std::string& dist_name, cpp11::function dist_fun); /* Remove and initialize the 2d vectors. */ @@ -86,7 +86,7 @@ class Slic { /* Writes the results to a format usable by R/cpp11. */ /* Returns final pixel assignments */ - writable::integers_matrix<> return_centers(); + writable::doubles_matrix<> return_centers(); /* Returns supercells centers*/ writable::integers_matrix<> return_clusters(); /* Returns supercells centers' values*/ diff --git a/src/writers.cpp b/src/writers.cpp index f5f06c7..963e9ed 100644 --- a/src/writers.cpp +++ b/src/writers.cpp @@ -14,8 +14,8 @@ writable::integers_matrix<> Slic::return_clusters(){ return result; } -writable::integers_matrix<> Slic::return_centers(){ - writable::integers_matrix<> result(centers.size(), 2); +writable::doubles_matrix<> Slic::return_centers(){ + writable::doubles_matrix<> result(centers.size(), 2); for (int i = 0; i < (int) centers.size(); i++){ result(i, 1) = centers[i][0]; /*y*/ result(i, 0) = centers[i][1]; /*x*/