/usr/include/gamera/plugins/edgedetect.hpp is in python-gamera-dev 1:3.4.2+git20160808.1725654-2.
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | /*
*
* Copyright (C) 2002-2005 Michael Droettboom and Robert Ferguson
* 2009 Christoph Dalitz
*
* This program 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 2
* 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef lcninja_edgedetect
#define lcninja_edgedetect
#include "gamera.hpp"
#include "vigra/edgedetection.hxx"
#include "logical.hpp"
#include "morphology.hpp"
namespace Gamera {
template<class T>
typename ImageFactory<T>::view_type* difference_of_exponential_edge_image(const T& src, double scale, double gradient_threshold, unsigned int min_edge_length) {
if ((scale < 0) || (gradient_threshold < 0))
throw std::runtime_error("The scale and gradient_threshold must be greater than 0");
typename ImageFactory<T>::data_type* dest_data =
new typename ImageFactory<T>::data_type(src.size(), src.origin());
typename ImageFactory<T>::view_type* dest =
new typename ImageFactory<T>::view_type(*dest_data);
try {
vigra::differenceOfExponentialEdgeImage(src_image_range(src), dest_image(*dest), scale, gradient_threshold);
if (min_edge_length > 0)
vigra::removeShortEdges(dest_image_range(*dest), min_edge_length, NumericTraits<typename T::value_type>::one());
} catch (std::exception e) {
delete dest;
delete dest_data;
throw;
}
return dest;
}
template<class T>
typename ImageFactory<T>::view_type* difference_of_exponential_crack_edge_image(const T& src, double scale, double gradient_threshold, unsigned int min_edge_length, unsigned int close_gaps, unsigned int beautify) {
if ((scale < 0) || (gradient_threshold < 0))
throw std::runtime_error("The scale and gradient threshold must be greater than 0");
typename ImageFactory<T>::data_type* dest_data =
new typename ImageFactory<T>::data_type(Dim(src.ncols() * 2, src.nrows() * 2), src.origin());
typename ImageFactory<T>::view_type* dest =
new typename ImageFactory<T>::view_type(*dest_data);
try {
vigra::differenceOfExponentialCrackEdgeImage(src_image_range(src), dest_image(*dest), scale, gradient_threshold, NumericTraits<typename T::value_type>::one());
if (min_edge_length > 0)
vigra::removeShortEdges(dest_image_range(*dest), min_edge_length, NumericTraits<typename T::value_type>::one());
if (close_gaps)
vigra::closeGapsInCrackEdgeImage(dest_image_range(*dest), NumericTraits<typename T::value_type>::one());
if (beautify)
vigra::beautifyCrackEdgeImage(dest_image_range(*dest), NumericTraits<typename T::value_type>::one(), NumericTraits<typename T::value_type>::zero());
} catch (std::exception e) {
delete dest;
delete dest_data;
throw;
}
return dest;
}
template<class T>
typename ImageFactory<T>::view_type* canny_edge_image(const T& src, double scale, double gradient_threshold) {
if ((scale < 0) || (gradient_threshold < 0))
throw std::runtime_error("The scale and gradient threshold must be >= 0");
typename ImageFactory<T>::data_type* dest_data =
new typename ImageFactory<T>::data_type(src.size(), src.origin());
typename ImageFactory<T>::view_type* dest =
new typename ImageFactory<T>::view_type(*dest_data, src);
try {
vigra::cannyEdgeImage(src_image_range(src), dest_image(*dest), scale, gradient_threshold, NumericTraits<typename T::value_type>::one());
} catch (std::exception e) {
delete dest;
delete dest_data;
throw;
}
return dest;
}
template<class T>
Image* labeled_region_edges(const T& src, bool mark_both=false) {
OneBitImageData* edges_data = new OneBitImageData(src.size(), src.origin());
OneBitImageView* edges = new OneBitImageView(*edges_data);
size_t x,y,max_x,max_y;
max_x = src.ncols()-1;
max_y = src.nrows()-1;
// the following mask is sufficient: xx
// xx
// because we assume that no pixel is unlabeled
// check bulk of image
for (y=0; y<max_y; ++y) {
for (x=0; x<max_x; ++x) {
if (src.get(Point(x,y)) != src.get(Point(x+1,y))) {
edges->set(Point(x,y),1);
if (mark_both)
edges->set(Point(x+1,y),1);
}
if (src.get(Point(x,y)) != src.get(Point(x,y+1))) {
edges->set(Point(x,y),1);
if (mark_both)
edges->set(Point(x,y+1),1);
}
if (src.get(Point(x,y)) != src.get(Point(x+1,y+1))) {
edges->set(Point(x,y),1);
if (mark_both)
edges->set(Point(x+1,y+1),1);
}
}
}
// check last row
for (x=0; x<max_x; ++x) {
if (src.get(Point(x,max_y)) != src.get(Point(x+1,max_y))) {
edges->set(Point(x,max_y),1);
if (mark_both)
edges->set(Point(x+1,max_y),1);
}
}
// check last column
for (y=0; y<max_y; ++y) {
if (src.get(Point(max_x,y)) != src.get(Point(max_x,y+1))) {
edges->set(Point(max_x,y),1);
if (mark_both)
edges->set(Point(max_x,y+1),1);
}
}
return edges;
}
template<class T>
typename ImageFactory<T>::view_type* outline(const T& in, int which=0) {
//typedef typename ImageFactory<T>::data_type data_type;
typedef typename ImageFactory<T>::view_type view_type;
view_type* out = erode_dilate(in, 1, which, 0);
xor_image(*out, in);
return out;
}
}
#endif
|