34#ifndef _vpImageMorphology_h_
35#define _vpImageMorphology_h_
42#include <visp3/core/vpImage.h>
43#include <visp3/core/vpImageException.h>
44#include <visp3/core/vpMatrix.h>
90 static void imageOperation(
vpImage<T> &I,
const T &null_value,
const T &(*operation)(
const T &,
const T &),
const vpConnexityType &connexity = CONNEXITY_4);
94 static void erosion(
vpImage<Type> &I, Type value, Type value_out, vpConnexityType connexity = CONNEXITY_4);
97 static void dilatation(
vpImage<Type> &I, Type value, Type value_out, vpConnexityType connexity = CONNEXITY_4);
100 static void erosion(
vpImage<T> &I,
const vpConnexityType &connexity = CONNEXITY_4);
102 template <
typename T>
103 static void dilatation(
vpImage<T> &I,
const vpConnexityType &connexity = CONNEXITY_4);
105#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
166 if (I.getSize() == 0) {
167 std::cerr <<
"Input image is empty!" << std::endl;
173 for (
unsigned int i = 0; i < J.
getHeight(); i++) {
175 for (
unsigned int j = 0; j < J.
getWidth(); j++) {
181 memcpy(J[i] + 1, I[i - 1],
sizeof(
unsigned char) * I.
getWidth());
187 for (
unsigned int i = 0; i < I.getHeight(); i++) {
188 for (
unsigned int j = 0; j < I.getWidth(); j++) {
189 if (J[i + 1][j + 1] == value) {
191 if ((J[i][j + 1] == value_out) ||
192 (J[i + 2][j + 1] == value_out) ||
193 (J[i + 1][j] == value_out) ||
194 (J[i + 1][j + 2] == value_out)) {
202 for (
unsigned int i = 0; i < I.getHeight(); i++) {
203 for (
unsigned int j = 0; j < I.getWidth(); j++) {
204 if (J[i + 1][j + 1] == value) {
206 if ((J[i][j] == value_out) || (J[i][j + 1] == value_out) || (J[i][j + 2] == value_out) ||
207 (J[i + 1][j] == value_out) || (J[i + 1][j + 2] == value_out) || (J[i + 2][j] == value_out) ||
208 (J[i + 2][j + 1] == value_out) || (J[i + 2][j + 2] == value_out))
236 if (I.getSize() == 0) {
237 std::cerr <<
"Input image is empty!" << std::endl;
243 for (
unsigned int i = 0; i < J.
getHeight(); i++) {
245 for (
unsigned int j = 0; j < J.
getWidth(); j++) {
251 memcpy(J[i] + 1, I[i - 1],
sizeof(
unsigned char) * I.
getWidth());
257 for (
unsigned int i = 0; i < I.getHeight(); i++) {
258 for (
unsigned int j = 0; j < I.getWidth(); j++) {
259 if (J[i + 1][j + 1] == value_out) {
261 if ((J[i][j + 1] == value) ||
262 (J[i + 2][j + 1] == value) ||
263 (J[i + 1][j] == value) ||
264 (J[i + 1][j + 2] == value)) {
272 for (
unsigned int i = 0; i < I.getHeight(); i++) {
273 for (
unsigned int j = 0; j < I.getWidth(); j++) {
274 if (J[i + 1][j + 1] == value_out) {
276 if ((J[i][j] == value) || (J[i][j + 1] == value) || (J[i][j + 2] == value) || (J[i + 1][j] == value) ||
277 (J[i + 1][j + 2] == value) || (J[i + 2][j] == value) || (J[i + 2][j + 1] == value) ||
278 (J[i + 2][j + 2] == value)) {
288void vpImageMorphology::imageOperation(
vpImage<T> &I,
const T &null_value,
const T &(*operation)(
const T &,
const T &),
const vpConnexityType &connexity)
290 const int width_in = I.getWidth();
291 const int height_in = I.getHeight();
292 const int width_dilat = width_in + 2;
293 const int height_dilat = height_in + 2;
294 vpImage<T> J(height_dilat, width_dilat, null_value);
300 const int nbOffset = 5;
301 int offset_x[nbOffset] = { 0, -1, 0, 1, 0 };
302 int offset_y[nbOffset] = { -1, 0, 0, 0, 1 };
304 for (
int i = 0; i < height_in; i++) {
305 for (
int j = 0; j < width_in; j++) {
306 T value = null_value;
307 for (
int k = 0; k < nbOffset; k++) {
308 value = operation(value, J[i + 1 + offset_y[k]][j + 1 + offset_x[k]]);
316 const int nbOffset = 9;
317 int offset_x[nbOffset] = { -1, 0, 1,-1, 0, 1,-1, 0, 1 };
318 int offset_y[nbOffset] = { -1,-1,-1, 0, 0, 0, 1, 1, 1 };
320 for (
int i = 0; i < height_in; i++) {
321 for (
int j = 0; j < width_in; j++) {
322 T value = null_value;
323 for (
int k = 0; k < nbOffset; k++) {
324 value = operation(value, J[i + 1 + offset_y[k]][j + 1 + offset_x[k]]);
359 const T &(*operation)(
const T & a,
const T & b) = std::min;
360 vpImageMorphology::imageOperation(I, std::numeric_limits<T>::max(), operation, connexity);
389 const T &(*operation)(
const T & a,
const T & b) = std::max;
390 vpImageMorphology::imageOperation(I, std::numeric_limits<T>::min(), operation, connexity);
Various mathematical morphology tools, erosion, dilatation...
static void dilatation(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)
static vp_deprecated void erosion(vpImage< unsigned char > &I, const vpConnexityType &connexity=CONNEXITY_4)
An erosion is performed with a flat structuring element . The erosion using such a structuring elemen...
static void erosion(vpImage< Type > &I, Type value, Type value_out, vpConnexityType connexity=CONNEXITY_4)
static vp_deprecated void dilatation(vpImage< unsigned char > &I, const vpConnexityType &connexity=CONNEXITY_4)
A dilatation is performed with a flat structuring element . The erosion using such a structuring elem...
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
unsigned int getWidth() const
unsigned int getHeight() const