/usr/include/mia-2.4/mia/template/similarity_profile.cxx is in libmia-2.4-dev 2.4.3-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | /* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2016 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include <cassert>
#include <stdexcept>
#include <mia/template/similarity_profile.hh>
NS_MIA_BEGIN
template <int dim>
TSimilarityProfile<dim>::TSimilarityProfile(PFullCost cost,
const ImageSeries& images,
size_t _reference, size_t max_delta):
m_peak_freq(-1),
m_peak_freq_valid(false),
m_reference(_reference),
m_max_delta(max_delta > 0 ? max_delta : images.size())
{
// +-2 makes sure that the implementation of get_periodic_subset works
assert(m_reference < images.size() - 2 && m_reference >= 2);
auto ref = images[m_reference];
save_image("ref.@", ref);
for(auto i = images.begin(); i != images.end(); ++i) {
save_image("src.@", *i);
cost->reinit();
cost->set_size((*i)->get_size());
m_cost_values.push_back( cost->cost_value());
}
}
template <int dim>
float TSimilarityProfile<dim>::get_peak_frequency() const
{
if (!m_peak_freq_valid) {
CFFT1D_R2C fft(m_cost_values.size());
cvdebug() << "costs:" << m_cost_values << "\n";
auto freq = fft.forward(m_cost_values);
for (auto i = freq.begin() + 1; i != freq.end(); ++i) {
const float n = std::norm<float>(*i);
float snorm = sqrt(n);
if (snorm > m_peak_freq)
m_peak_freq = snorm;
}
m_peak_freq_valid = true;
}
return m_peak_freq;
}
template <int dim>
std::vector<size_t> TSimilarityProfile<dim>::get_periodic_subset() const
{
std::vector<size_t> result;
result.push_back(m_reference);
size_t i = m_reference - 1;
cvinfo() << "Similarity profile["<< m_reference <<"]:"
<< m_cost_values << "\n";
unsigned delta = 0;
while (i > 2) {
if ((m_cost_values[i] <= m_cost_values[i + 1] &&
m_cost_values[i] <= m_cost_values[i + 2] &&
m_cost_values[i] <= m_cost_values[i - 1] &&
m_cost_values[i] <= m_cost_values[i - 2]) || (delta > m_max_delta)) {
result.push_back(i);
i -= 3;
delta = 0;
}else {
++delta;
--i;
}
}
result.push_back(0);
delta = 0;
i = m_reference + 1;
while (i < m_cost_values.size() - 2) {
if ((m_cost_values[i] <= m_cost_values[i + 1] &&
m_cost_values[i] <= m_cost_values[i + 2] &&
m_cost_values[i] <= m_cost_values[i - 1] &&
m_cost_values[i] <= m_cost_values[i - 2]) || (delta > m_max_delta)) {
result.push_back(i);
i += 3;
delta = 0;
}else {
++delta;
++i;
}
}
// append the one before the last if better then last
// a the the end of the series the changes in intesnity should
// not be so big
while (i < m_cost_values.size() - 1) {
if (m_cost_values[i] < m_cost_values[i + 1]
&& m_cost_values[i] < m_cost_values[i - 1]
&& m_cost_values[i] < m_cost_values[i - 2]) {
result.push_back(i);
i += 3;
}
else
++i;
}
// not yet past the end, therefore, we may want to add the last image
while (i < m_cost_values.size()) {
if (m_cost_values[i] < m_cost_values[i - 1]
&& m_cost_values[i] < m_cost_values[i - 2]) {
result.push_back(i);
i += 3;
}
else
++i;
}
sort(result.begin(), result.end());
return result;
}
NS_MIA_END
|