JWS C Library
C language utility library
edge.h File Reference

Declarations for an image edge detector. More...

#include <jwsc/config.h>
#include <stdlib.h>
#include <inttypes.h>
#include "jwsc/base/error.h"
#include "jwsc/image/image.h"
#include "jwsc/matrix/matrix.h"
Include dependency graph for edge.h:

Go to the source code of this file.

Data Structures

struct  Edge_point_f
 Edge point in an image or matrix (single-sampled image). More...
struct  Edge_set_f
 Set of edges composed of edge points. More...

Functions

detect_image_edge_set

Detects a set of edges in each sample of an image.

Errordetect_image_edge_set_f (Edge_set_f **edges_out, const Image_f *img, float sigma, float begin_thresh, float end_thresh, uint32_t padding)
 Detects a set of edges in each sample of a single precision image.
ErrorDEPRECATED_detect_image_edge_set_f (Edge_set_f **r_edges_out, Edge_set_f **g_edges_out, Edge_set_f **b_edges_out, const Image_f *img, float sigma, float begin_thresh, float end_thresh, uint32_t padding)
 Detects a set of edges in each sample of a single precision image.
detect_matrix_edge_set

Detects a set of edges in a matrix (single-sample image).

Errordetect_matrix_edge_set_f (Edge_set_f **edges_out, const Matrix_f *m, float sigma, float begin_thresh, float end_thresh, uint32_t padding)
 Detects a set of edges in a single precision matrix (single-sample image).
free_edge_set

Frees a set of edges.

void free_edge_set_f (Edge_set_f *edges)
 Frees a set of single precision edges.
remove_short_edges

Removes edges with a number of points less than a specified minimum.

void remove_short_edges_f (Edge_set_f *edges, uint32_t min_len)
 Removes single precision edges with a number of points less than a specified minimum.
break_edges_at_corners

Finds the edge point with the largest gradient difference on either side, breaks the edge, and recurses on the two newly created edges.

void break_edges_at_corners_f (Edge_set_f *edges, float thresh, uint32_t num_avg)
 Breaks apart single precision edges where the gradient direction changes significantly.
sample_edge_set

Randomly samples edge points from a set of them.

void sample_edge_set_f (Edge_set_f **edges_out, const Edge_set_f *edges_in, float p)
 Randomly samples single precision edge points from a set of them.
color_edge_set

Colors a set of edges in an image.

Errorcolor_edge_set_f (Image_f **img_out, const Image_f *img_in, const Edge_set_f *edges, const Pixel_f *pxl)
 Colors single precision set of edges in an image.
randomly_color_edge_set

Colors a set of edges in an image with randomly selected colors.

Errorrandomly_color_edge_set_f (Image_f **img_out, const Image_f *img_in, const Edge_set_f *edges)
 Colors single precision set of edges in an image with randomly selected colors.
color_edge_points

Colors edge points in an image.

Errorcolor_edge_points_f (Image_f **img_out, const Image_f *img_in, const Edge_point_f *pts, uint32_t num_pts, const Pixel_f *pxl)
 Colors single precision edge points in an image.
randomly_color_edge_points

Colors edge points in an image with a randomly selected color.

Errorrandomly_color_edge_points_f (Image_f **img_out, const Image_f *img_in, const Edge_point_f *pts, uint32_t num_pts)
read_edge_set

Reads a set of edges in ASCII format from a file.

Errorread_edge_set_f (Edge_set_f **edges_out, const char *fname)
 Reads a set of single precision edges in ASCII format from a file.
write_edge_set

Writes a set of edges in ASCII format to a file.

Errorwrite_edge_set_f (const Edge_set_f *edges, const char *fname)
 Writes a set of single precision edges in ASCII format to a file.

Detailed Description

Declarations for an image edge detector.

Author:
Joseph Schlecht
License:
Creative Commons BY-NC-SA 3.0

The edge detection algorithm is a variation of the standard Canny algorithm: the image is convolved with the gradiant of Gaussian, then non-maximal suppression and hysterisis are applied to the resulting gradient map.

Definition in file edge.h.


Function Documentation

Error* detect_image_edge_set_f ( Edge_set_f **  edges_out,
const Image_f img,
float  sigma,
float  begin_thresh,
float  end_thresh,
uint32_t  padding 
)

Detects a set of edges in each sample of a single precision image.

Smoothed partial derivative kernels, non-maximal suppression, and hysteresis are used to trace out the edge points from the input image.

Parameters:
edges_outResult parameter. If *r_edges_out is NULL, an array of edge points is allocated; otherwise its space is re-used.
imgImage to get the edge points of.
sigmaParameter for the Gaussian kernel used for smoothing and edge detection.
begin_threshUsed when scanning the image to look for gradient magnitudes to follow under non-maximal suppression.
end_threshOnce an edge is found under non-maximal suppression, it is followed (perpendicular to the gradient) until the gradient magnitude falls below this threshold.
paddingAmount of padding to use around the border of the image. The padding is created by extending the image.
Returns:
On success, NULL is returned. On error, an Error is returned and *[rgb]_edges_out are freed and set to NULL.

Definition at line 720 of file edge.c.

Error* DEPRECATED_detect_image_edge_set_f ( Edge_set_f **  r_edges_out,
Edge_set_f **  g_edges_out,
Edge_set_f **  b_edges_out,
const Image_f img,
float  sigma,
float  begin_thresh,
float  end_thresh,
uint32_t  padding 
)

Detects a set of edges in each sample of a single precision image.

Smoothed partial derivative kernels, non-maximal suppression, and hysteresis are used to trace out the edge points from the input image.

Parameters:
r_edges_outResult parameter. If *r_edges_out is NULL, an array of edge points is allocated; otherwise its space is re-used.
g_edges_outResult parameter. If *g_edges_out is NULL, an array of edge points is allocated; otherwise its space is re-used.
b_edges_outResult parameter. If *b_edges_out is NULL, an array of edge points is allocated; otherwise its space is re-used.
imgImage to get the edge points of.
sigmaParameter for the Gaussian kernel used for smoothing and edge detection.
begin_threshUsed when scanning the image to look for gradient magnitudes to follow under non-maximal suppression.
end_threshOnce an edge is found under non-maximal suppression, it is followed (perpendicular to the gradient) until the gradient magnitude falls below this threshold.
paddingAmount of padding to use around the border of the image. The padding is created by extending the image.
Returns:
On success, NULL is returned. On error, an Error is returned and *[rgb]_edges_out are freed and set to NULL.

Definition at line 775 of file edge.c.

Error* detect_matrix_edge_set_f ( Edge_set_f **  edges_out,
const Matrix_f m,
float  sigma,
float  begin_thresh,
float  end_thresh,
uint32_t  padding 
)

Detects a set of edges in a single precision matrix (single-sample image).

Smoothed partial derivative kernels, non-maximal suppression, and hysteresis are used to trace out the edge points from the input image.

Parameters:
edges_outResult parameter. If *edges_out is NULL, an array of edge points is allocated; otherwise its space is re-used.
mMatrix to get the edge points of.
sigmaParameter for the Gaussian kernel used for smoothing and edge detection.
begin_threshUsed when scanning the image to look for gradient magnitudes to follow under non-maximal suppression.
end_threshOnce an edge is found under non-maximal suppression, it is followed (perpendicular to the gradient) until the gradient magnitude falls below this threshold.
paddingAmount of padding to use around the border of the matrix. The padding is created by extending the matrix.
Returns:
On success, NULL is returned. On error, an Error is returned and *edges_out are freed and set to NULL.

Definition at line 852 of file edge.c.

void free_edge_set_f ( Edge_set_f edges)

Frees a set of single precision edges.

Parameters:
edgesSet of edges to free.

Definition at line 905 of file edge.c.

void remove_short_edges_f ( Edge_set_f edges,
uint32_t  min_len 
)

Removes single precision edges with a number of points less than a specified minimum.

Parameters:
edgesEdge set to remove short edges from.
min_lenMinimum number of points for an edge. Edges with fewer points are removed.

Definition at line 936 of file edge.c.

void break_edges_at_corners_f ( Edge_set_f edges,
float  thresh,
uint32_t  num_avg 
)

Breaks apart single precision edges where the gradient direction changes significantly.

Parameters:
edgesEdge set to break apart.
threshIf the dot product of the averaged vectors is less than this threshold, the edge is broken.
num_avgNumber of gradient vectors to average into one when computing the dot product.

Definition at line 1111 of file edge.c.

void sample_edge_set_f ( Edge_set_f **  edges_out,
const Edge_set_f edges_in,
float  p 
)

Randomly samples single precision edge points from a set of them.

Parameters:
edges_outResult parameter. If *edges_out is NULL, a set of edges is allocated; otherwise its space is re-used.
edges_inSet of edges to sample from.
pBernoulli parameter; probability of sampling an edge point.
Note:
If *edges_out == edges_in, then edges_in is overwritten.

Definition at line 1147 of file edge.c.

Error* color_edge_set_f ( Image_f **  img_out,
const Image_f img_in,
const Edge_set_f edges,
const Pixel_f pxl 
)

Colors single precision set of edges in an image.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
img_inImage to color the edge points on.
edgesEdge set to use.
pxlPixel to use for coloring the edge points.
Returns:
On success, NULL is returned. On error, an Error is returned and *img_out is freed and set to NULL.
  • Error_types::ERROR_INV_ARG Edge points indexed outside img_in. The file to read from is not formatted properly.

Definition at line 1278 of file edge.c.

Error* randomly_color_edge_set_f ( Image_f **  img_out,
const Image_f img_in,
const Edge_set_f edges 
)

Colors single precision set of edges in an image with randomly selected colors.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
img_inImage to color the edge points on.
edgesEdge set to use.
Returns:
On success, NULL is returned. On error, an Error is returned and *img_out is freed and set to NULL.
  • Error_types::ERROR_INV_ARG Edge points indexed outside img_in. The file to read from is not formatted properly.

Definition at line 1329 of file edge.c.

Error* color_edge_points_f ( Image_f **  img_out,
const Image_f img_in,
const Edge_point_f pts,
uint32_t  num_pts,
const Pixel_f pxl 
)

Colors single precision edge points in an image.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
img_inImage to color the edge points on.
ptsEdge points to use.
num_ptsNumber of elements in pts.
pxlPixel to use for coloring the edge points.
Returns:
On success, NULL is returned. On error, an Error is returned and *img_out is freed and set to NULL.
  • Error_types::ERROR_INV_ARG Edge points indexed outside img_in. The file to read from is not formatted properly.

Definition at line 1381 of file edge.c.

Error* randomly_color_edge_points_f ( Image_f **  img_out,
const Image_f img_in,
const Edge_point_f pts,
uint32_t  num_pts 
)

Colors single precision edge points in an image with a randomly selected color.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
img_inImage to color the edge points on.
ptsEdge points to use.
num_ptsNumber of elements in pts.
Returns:
On success, NULL is returned. On error, an Error is returned and *img_out is freed and set to NULL.
  • Error_types::ERROR_INV_ARG Edge points indexed outside img_in. The file to read from is not formatted properly.

Definition at line 1445 of file edge.c.

Error* read_edge_set_f ( Edge_set_f **  edges_out,
const char *  fname 
)

Reads a set of single precision edges in ASCII format from a file.

The first line of the file must contains the number of edges, the second has the total number of edge points and the following lines have the number of points in each edge followed by the actual points. For example,

 num_rows=100
 num_cols=100
 num_edges=2
 total_num_points=5
 num_pts=3
 col=0 row=0 dcol=1 drow=1 mag=1
 col=9 row=8 dcol=4 drow=1 mag=1
 col=1 row=2 dcol=2 drow=1 mag=1
 num_pts=2
 col=9 row=8 dcol=4 drow=1 mag=1
 col=1 row=2 dcol=2 drow=1 mag=1
Parameters:
edges_outResult parameter. If *edges_out is NULL, an edge set is allocated; otherwise its space is re-used.
fnameName of the file to read from.
Returns:
On success, NULL is returned. On error, an Error is returned and *edges_out is freed and set to NULL.

Definition at line 1504 of file edge.c.

Error* write_edge_set_f ( const Edge_set_f edges,
const char *  fname 
)

Writes a set of single precision edges in ASCII format to a file.

The first line of the file contains the number of edges, the second has the total number of edge points and the following lines have the number of points in each edge followed by the actual points. For example,

 num_rows=100
 num_cols=100
 num_edges=2
 total_num_points=5
 num_pts=3
 col=0 row=0 dcol=1 drow=1 mag=1
 col=9 row=8 dcol=4 drow=1 mag=1
 col=1 row=2 dcol=2 drow=1 mag=1
 num_pts=2
 col=9 row=8 dcol=4 drow=1 mag=1
 col=1 row=2 dcol=2 drow=1 mag=1
Parameters:
edgesEdge set to write.
fnameName of the file to write to.
Returns:
On success, NULL is returned. On error, an Error is returned.

Definition at line 1624 of file edge.c.