#include <cpl.h>
Go to the source code of this file.
|
cpl_error_code | clipm_priv_image_compute_gradients (const cpl_image *input, const cpl_size window_xxyy[4], cpl_image **out_magnitudes, cpl_image **out_angles) |
| Compute image gradients. More...
|
|
cpl_image * | clipm_priv_image_conv_sobel_x (const cpl_image *input, const cpl_size window_xxyy[4]) |
| Convolve image with horizontal Sobel operator. More...
|
|
cpl_image * | clipm_priv_image_conv_sobel_y (const cpl_image *input, const cpl_size window_xxyy[4]) |
| Convolve image with vertical Sobel operator. More...
|
|
cpl_image * | clipm_priv_image_compute_angles (const cpl_image *grad_x, const cpl_image *grad_y) |
| Calculate the angles of a gradient field. More...
|
|
cpl_image * | clipm_priv_image_compute_pythagoras (const cpl_image *input1, const cpl_image *input2) |
| Calculate the Pythagoras of two images. More...
|
|
double | clipm_priv_image_compute_mean_angle (const cpl_image *magnitudes, const cpl_image *angles, const cpl_size window_xxyy[4], double periodic_factor, double *out_norm) |
| Compute the mean of an angle-field inside a window. More...
|
|
cpl_error_code | clipm_priv_image_compute_mean_gradients (const cpl_image *magnitudes, const cpl_image *angles, const cpl_size window_xxyy[4], double periodic_factor, double radius_sigma, cpl_image **mean_magnitudes, cpl_image **mean_angles) |
| Lowpass gradients after applying a periodic factor. More...
|
|
cpl_image * | clipm_priv_image_compute_angular_uniformity (const cpl_image *magnitudes, const cpl_image *angle, const cpl_size window_xxyy[4], double radius_sigma, double periodic_factor) |
| Compute an indicator for a uniform pointing direction of gradients. More...
|
|
cpl_image* clipm_priv_image_compute_angles |
( |
const cpl_image * |
grad_x, |
|
|
const cpl_image * |
grad_y |
|
) |
| |
Calculate the angles of a gradient field.
- Parameters
-
grad_x | Image representing the horizontal gradients |
grad_y | Image representing the vertical gradients |
- Returns
- Image containing the angle field in the range
, NULL in the case of error
- Constraints:
- The input images must be of the same cpl_type and size.
- The cpl_type of the input images must be one of CPL_TYPE_FLOAT or CPL_TYPE_DOUBLE.
- The created output image is of the same type as the input images.
- Bad Pixel Handling:
- Bad pixels in any input image will produce bad pixels in the output.
- Error Handling
- The following error codes can be set:
- CPL_ERROR_NULL_INPUT: grad_x or grad_y is NULL
- CPL_ERROR_TYPE_MISMATCH: grad_x and grad_y are not of the same type
- CPL_ERROR_INVALID_TYPE: grad_x and grad_y are neither of type CPL_TYPE_FLOAT nor of type CPL_TYPE_DOUBLE
- CPL_ERROR_INCOMPATIBLE_INPUT: grad_x and grad_y don't have the same size
cpl_image* clipm_priv_image_compute_angular_uniformity |
( |
const cpl_image * |
magnitudes, |
|
|
const cpl_image * |
angles, |
|
|
const cpl_size |
window_xxyy[4], |
|
|
double |
radius_sigma, |
|
|
double |
periodic_factor |
|
) |
| |
Compute an indicator for a uniform pointing direction of gradients.
- Parameters
-
magnitudes | Image containing gradient magnitude values |
angles | Image containing gradient angle values |
window_xxyy | Coordinate buffer of the form {xa, xb, ya, yb}, can be NULL, minimum/maximum order is irrelevant |
radius_sigma | Sigma of the gaussian region used for the lowpass |
periodic_factor | Divisor for the periodicity of |
- Returns
- Image containing measurements in the range 0...1, NULL in the case of error
- Principle:
- Within a certain influence radius, abs(mean(vi)) / mean(abs(vi)) is computed, where vi are the individual vectors.
- The radius is not a sharp limit, but the influence decreases with a Gaussian shape.
- Constraints:
- magnitudes and angles must be either of type CPL_TYPE_FLOAT or type CPL_TYPE_DOUBLE.
- Bad Pixel Handling:
- Pixels which are bad in either magnitudes or angles are skipped during computation.
- Error Handling:
- The following error codes can be set:
- CPL_ERROR_NULL_INPUT: magnitudes or angles is NULL
- CPL_ERROR_TYPE_MISMATCH: magnitudes and angles are not of the same type
- CPL_ERROR_ACCESS_OUT_OF_RANGE: window coordinates are outside the images
- CPL_ERROR_INVALID_TYPE: magnitudes and angles are neither of type CPL_TYPE_FLOAT nor of type CPL_TYPE_DOUBLE
- CPL_ERROR_INCOMPATIBLE_INPUT: magnitudes and angles don't have the same size
- CPL_ERROR_ILLEGAL_INPUT:
- if periodic_factor <= 0, or
- radius_sigma <= 0
cpl_error_code clipm_priv_image_compute_gradients |
( |
const cpl_image * |
input, |
|
|
const cpl_size |
window_xxyy[4], |
|
|
cpl_image ** |
out_magnitudes, |
|
|
cpl_image ** |
out_angles |
|
) |
| |
Compute image gradients.
- Parameters
-
input | Input image |
window_xxyy | Coordinate buffer of the form {xa, xb, ya, yb}, can be NULL, minimum/maximum order is irrelevant |
out_magnitudes | Pointer to ouput image for absolute gradient |
out_angles | Pointer to ouput image for gradient angles in the range |
- Returns
- The cpl error code if any occurred
- Introduction:
- This function computes the absolute gradient field of the input image, and the corresponding orientation field. There are the following constraints:
- The pointers to the output image pointers must not be NULL.
- The input can be integer, float or double.
- If the input is of type integer, then values of type double will be produced as output, otherwise the created output images are of the same type as the input image.
- On failure, NULL pointers are returned.
- Error Handling
- The following error codes can be set and returned:
- CPL_ERROR_NULL_INPUT: any of the input or output pointers is NULL
- CPL_ERROR_INVALID_TYPE: input is neither of type CPL_TYPE_INT, CPL_TYPE_FLOAT, nor of type CPL_TYPE_DOUBLE
- Example (omitting error handling):
*#include <cpl.h>
*#include <clipm.h>
*
* cpl_image *in_img,
* *out_absgrad,
* *out_angles;
* cpl_propertylist
* *img_header;
* const char infilename[] = "example.fits";
*
* in_img = cpl_image_load(infilename,
* CPL_TYPE_DOUBLE,
* 0,
* 0);
* img_header = cpl_propertylist_load(infilename, 0);
*
* in_img,
* &out_absgrad,
* &out_angles);
*
* cpl_image_save( out_absgrad,
* "abs_gradients.fits",
* CPL_BPP_IEEE_DOUBLE,
* image_header,
* CPL_IO_DEFAULT);
* cpl_image_save( ` out_angles,
* "grad_angles.fits",
* CPL_BPP_IEEE_DOUBLE,
* image_header,
* CPL_IO_DEFAULT);
* return 0;
*}
*
- Todo:
- Implement care for bad pixels map
double clipm_priv_image_compute_mean_angle |
( |
const cpl_image * |
magnitudes, |
|
|
const cpl_image * |
angles, |
|
|
const cpl_size |
window_xxyy[4], |
|
|
double |
periodic_factor, |
|
|
double * |
out_norm |
|
) |
| |
Compute the mean of an angle-field inside a window.
- Parameters
-
magnitudes | Image containing gradient magnitude values (FITS convention) |
angles | Image containing local angle values (FITS convention) |
window_xxyy | Coordinate buffer of the form {xa, xb, ya, yb}, can be NULL, minimum/maximum order is irrelevant |
periodic_factor | Divisor for the periodicity of |
out_norm | (Optional output) the gradient's norm |
- Returns
- Mean angle inside range of
, -1 in the case of error
- Principle:
- Consider a local angle
, a local weight
and a periodic factor
. Then the mean angle
is determined by:
It does not always make sense to compute a mean angle in the range
, for example a line crossing an image has an orientation but the orientation has no sign. In this case, only angles in the range
are interesting. Therefore, the periodic factor is adjustable. For example, a periodic factor of
causes opposite angles to fall together in the complex plane before summing, and thus to be considered the same. The final division by
scales the angle back to the range
. The following values for periodic_factor are of specific interest:
periodic_factor | Example Purpose |
1 | Uni-directional (e.g. global) gradients |
2 | Lines and rectangular apertures |
3 | Equilateral triangles |
4 | Square apertures, crossing spikes of secondary mirror
holder |
6 | Honeycombs |
- Constraints:
- The input images must be of the same cpl_type and size.
- The cpl_type of the input images must be one of CPL_TYPE_FLOAT or CPL_TYPE_DOUBLE.
- Bad Pixel Handling:
- Pixels which are bad in either magnitudes or angles are ignored during computation.
- Error Handling:
- The following error codes can be set:
- CPL_ERROR_NULL_INPUT: magnitudes or angles is NULL
- CPL_ERROR_TYPE_MISMATCH: magnitudes and angles are not of the same type
- CPL_ERROR_ACCESS_OUT_OF_RANGE: window coordinates are outside the images
- CPL_ERROR_INVALID_TYPE: magnitudes and angles are neither of type CPL_TYPE_FLOAT nor of type CPL_TYPE_DOUBLE
- CPL_ERROR_INCOMPATIBLE_INPUT: magnitudes and angles don't have the same size
- CPL_ERROR_ILLEGAL_INPUT: periodic_factor <= 0
- CPL_ERROR_DATA_NOT_FOUND: all pixels are bad
- Example (omitting error handling):
*#include <cpl.h>
*#include <clipm.h>
*#include <stdio.h>
*
* cpl_image *in_img,
* *grad_field,
* *angle_field;
* double periodic_f,
* mean_angle,
* norm;
* const char infilename[] = "example.fits";
*
* in_img = cpl_image_load(infilename,
* CPL_TYPE_DOUBLE,
* 0,
* 0);
*
*
* in_img,
* &grad_field,
* &angle_field);
*
*
* periodic_f = 2;
*
*
* grad_field,
* angle_field,
* NULL,
* periodic_f,
* &norm);
*
*
*
*
*
* printf( "Line orientation: %.2f degrees\n",
* cpl_image_delete(in_img);
* cpl_image_delete(grad_field);
* cpl_image_delete(angle_field);
* return 0;
*}
*
- Todo:
- adapt cpl_error handling
- ignore bad pixels: done
- return also
as measurement for the quality
cpl_error_code clipm_priv_image_compute_mean_gradients |
( |
const cpl_image * |
magnitudes, |
|
|
const cpl_image * |
angles, |
|
|
const cpl_size |
window_xxyy[4], |
|
|
double |
periodic_factor, |
|
|
double |
radius_sigma, |
|
|
cpl_image ** |
mean_magnitudes, |
|
|
cpl_image ** |
mean_angles |
|
) |
| |
Lowpass gradients after applying a periodic factor.
- Parameters
-
magnitudes | Image containing gradient magnitude values (FITS convention) |
angles | Image containing gradient angle values (FITS convention) |
window_xxyy | Coordinate buffer of the form {xa, xb, ya, yb}, can be NULL, minimum/maximum order is irrelevant |
periodic_factor | Divisor for the periodicity of |
radius_sigma | Sigma of the gaussian used for the lowpass |
mean_magnitudes | (Optional output) magnitudes of lowpassed gradients |
mean_angles | (Optional output) angles of lowpassed gradients |
- Returns
- CPL error code
- Principle:
- The formula to compute a mean gradient from a region of gradients from function clipm_priv_image_compute_mean_angle() is used, but with the extension that the input gradients are weighted with a Gaussian bell kurve with sigma radius_sigma.
- Constraints:
- The input images must be of the same cpl_type and size.
- The cpl_type of the input images must be one of CPL_TYPE_FLOAT or CPL_TYPE_DOUBLE.
- Bad Pixel Handling:
- Pixels which are bad in either magnitudes or angles are skipped during computation.
- Error Handling:
- The following error codes can be set:
- CPL_ERROR_NULL_INPUT: magnitudes or angles is NULL
- CPL_ERROR_TYPE_MISMATCH: magnitudes and angles are not of the same type
- CPL_ERROR_ACCESS_OUT_OF_RANGE: window coordinates are outside the images
- CPL_ERROR_INVALID_TYPE: magnitudes and angles are neither of type CPL_TYPE_FLOAT nor of type CPL_TYPE_DOUBLE
- CPL_ERROR_INCOMPATIBLE_INPUT: magnitudes and angles don't have the same size
- CPL_ERROR_ILLEGAL_INPUT: periodic_factor <= 0
cpl_image* clipm_priv_image_compute_pythagoras |
( |
const cpl_image * |
input1, |
|
|
const cpl_image * |
input2 |
|
) |
| |
Calculate the Pythagoras of two images.
- Parameters
-
input1 | First input image |
input2 | Second input image |
- Returns
- Output image, NULL in the case of error
- Constraints:
- The input images must be of the same cpl_type and size.
- The cpl_type of the input images must be one of CPL_TYPE_FLOAT or CPL_TYPE_DOUBLE.
- The created output image is of the same type as the input images.
- The pythagoras c of two values a and b is given by
.
- Bad Pixel Handling:
- Bad pixels in any input image will produce bad pixels in the output.
- Error Handling
- The following error codes can be set:
- CPL_ERROR_NULL_INPUT: grad_x or grad_y is NULL
- CPL_ERROR_TYPE_MISMATCH: grad_x and grad_y are not of the same type
- CPL_ERROR_INVALID_TYPE: grad_x and grad_y are neither of type CPL_TYPE_FLOAT nor of type CPL_TYPE_DOUBLE
- CPL_ERROR_INCOMPATIBLE_INPUT: grad_x and grad_y don't have the same size
cpl_image* clipm_priv_image_conv_sobel_x |
( |
const cpl_image * |
input, |
|
|
const cpl_size |
window_xxyy[4] |
|
) |
| |
Convolve image with horizontal Sobel operator.
- Parameters
-
input | Input image |
window_xxyy | Coordinate buffer of the form {xa, xb, ya, yb}, can be NULL, minimum/maximum order is irrelevant |
- Returns
- Horizontal gradient image, NULL in the case of error
- Principle:
- A sobel operator is an edge detecting convolution kernel, relatively insensitive to noise. The horizontal one is (here normed by one eighth):
- The input can be integer, float or double.
- If the input is of type integer, then values of type double will be produced as output.
- Bad Pixel Handling:
- Bad pixels in the input image will contaminate their neighbours.
- Specifying no window, or a window touching the image border, will result in bad pixels at the output border.
- Error Handling:
- The following error codes can be set:
- CPL_ERROR_NULL_INPUT: if input is NULL
- CPL_ERROR_ACCESS_OUT_OF_RANGE: a window coordinate exceeds the image range
- CPL_ERROR_INVALID_TYPE: input is neither of type CPL_TYPE_INT, CPL_TYPE_FLOAT nor CPL_TYPE_DOUBLE
- Note
- In the worst case, a sobel operator without a pre-factor can produce a value 8 times higher than the maximum, and can by this way cause a range violation (resulting in an infinite number). For this reason the pre-factor is used here. But be aware, that this pre-factor causes an increased quantization error when applied to integer numbers.
- See Also
-
cpl_image* clipm_priv_image_conv_sobel_y |
( |
const cpl_image * |
input, |
|
|
const cpl_size |
window_xxyy[4] |
|
) |
| |
Convolve image with vertical Sobel operator.
- Parameters
-
input | Input image |
window_xxyy | Coordinate buffer of the form {xa, xb, ya, yb}, can be NULL, minimum/maximum order is irrelevant |
- Returns
- Vertical gradient image, NULL in the case of error
- Principle:
- A sobel operator is an edge detecting convolution kernel, relatively insensitive to noise. The vertical one is (here normed by one eighth):
- The input can be integer, float or double.
- If the input is of type integer, then values of type double will be produced as output.
- Bad Pixel Handling:
- Bad pixels in the input image will contaminate their neighbours.
- Specifying no window, or a window touching the image border, will result in bad pixels at the output border.
- Error Handling
- The following error codes can be set:
- CPL_ERROR_NULL_INPUT: if input is NULL
- CPL_ERROR_ACCESS_OUT_OF_RANGE: a window coordinate exceeds the image range
- CPL_ERROR_INVALID_TYPE: input is neither of type CPL_TYPE_INT, CPL_TYPE_FLOAT nor CPL_TYPE_DOUBLE
- Note
- In the worst case, a sobel operator without a pre-factor can produce a value 8 times higher than the maximum, and can by this way cause a range violation (resulting in an infinite number). For this reason the pre-factor is used here. But be aware, that this pre-factor causes an increased quantization error when applied to integer numbers.
- See Also
-