Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
image.h File Reference

Image helper functions like resizing, color filter, converters... More...

#include "std.h"
#include <sys/time.h>
+ Include dependency graph for image.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  image_t
 
struct  point_t
 
struct  flow_t
 
struct  img_size_t
 
struct  crop_t
 

Enumerations

enum  image_type { IMAGE_YUV422, IMAGE_GRAYSCALE, IMAGE_JPEG, IMAGE_GRADIENT }
 

Functions

void image_add_border (struct image_t *input, struct image_t *output, uint8_t border_size)
 This function adds padding to input image by mirroring the edge image elements. More...
 
void image_create (struct image_t *img, uint16_t width, uint16_t height, enum image_type type)
 Create a new image. More...
 
void image_free (struct image_t *img)
 Free the image. More...
 
void image_copy (struct image_t *input, struct image_t *output)
 Copy an image from inut to output This will only work if the formats are the same. More...
 
void image_switch (struct image_t *a, struct image_t *b)
 This will switch image *a and *b This is faster as image_copy because it doesn't copy the whole image buffer. More...
 
void image_to_grayscale (struct image_t *input, struct image_t *output)
 Convert an image to grayscale. More...
 
uint16_t image_yuv422_colorfilt (struct image_t *input, struct image_t *output, uint8_t y_m, uint8_t y_M, uint8_t u_m, uint8_t u_M, uint8_t v_m, uint8_t v_M)
 Filter colors in an YUV422 image. More...
 
void image_yuv422_downsample (struct image_t *input, struct image_t *output, uint16_t downsample)
 Simplified high-speed low CPU downsample function without averaging downsample factor must be 1, 2, 4, 8 ... More...
 
void image_subpixel_window (struct image_t *input, struct image_t *output, struct point_t *center, uint32_t subpixel_factor, uint8_t border_size)
 This outputs a subpixel window image in grayscale Currently only works with Grayscale images as input but could be upgraded to also support YUV422 images. More...
 
void image_gradients (struct image_t *input, struct image_t *dx, struct image_t *dy)
 Calculate the gradients using the following matrix: [0 -1 0; -1 0 1; 0 1 0]. More...
 
void image_calculate_g (struct image_t *dx, struct image_t *dy, int32_t *g)
 Calculate the G vector of an image gradient This is used for optical flow calculation. More...
 
uint32_t image_difference (struct image_t *img_a, struct image_t *img_b, struct image_t *diff)
 Calculate the difference between two images and return the error This will only work with grayscale images. More...
 
int32_t image_multiply (struct image_t *img_a, struct image_t *img_b, struct image_t *mult)
 Calculate the multiplication between two images and return the error This will only work with image gradients. More...
 
void image_show_points (struct image_t *img, struct point_t *points, uint16_t points_cnt)
 Show points in an image by coloring them through giving the pixels the maximum value. More...
 
void image_show_flow (struct image_t *img, struct flow_t *vectors, uint16_t points_cnt, uint8_t subpixel_factor)
 Shows the flow from a specific point to a new point This works on YUV422 and Grayscale images. More...
 
void image_draw_line (struct image_t *img, struct point_t *from, struct point_t *to)
 Draw a line on the image. More...
 
void pyramid_next_level (struct image_t *input, struct image_t *output, uint8_t border_size)
 This function takes previous padded pyramid level and outputs next level of pyramid without padding. More...
 
void pyramid_build (struct image_t *input, struct image_t *output_array, uint8_t pyr_level, uint8_t border_size)
 This function populates given array of image_t structs with wanted number of padded pyramids based on given input. More...
 

Detailed Description

Image helper functions like resizing, color filter, converters...

Definition in file image.h.


Data Structure Documentation

struct image_t

Definition at line 42 of file image.h.

+ Collaboration diagram for image_t:
Data Fields
void * buf Image buffer (depending on the image_type)
uint8_t buf_idx Buffer index for V4L2 freeing.
uint32_t buf_size The buffer size.
uint16_t h Image height.
uint32_t pprz_ts The timestamp in us since system startup.
struct timeval ts The timestamp of creation.
enum image_type type The image type.
uint16_t w Image width.
struct point_t

Definition at line 55 of file image.h.

Data Fields
uint32_t x The x coordinate of the point.
uint32_t y The y coordinate of the point.
struct flow_t

Definition at line 61 of file image.h.

+ Collaboration diagram for flow_t:
Data Fields
int16_t flow_x The x direction flow in subpixels.
int16_t flow_y The y direction flow in subpixels.
struct point_t pos The original position the flow comes from.
struct img_size_t

Definition at line 68 of file image.h.

Data Fields
uint16_t h The height.
uint16_t w The width.
struct crop_t

Definition at line 74 of file image.h.

Data Fields
uint16_t h height of the cropped area
uint16_t w Width of the cropped area.
uint16_t x Start position x (horizontal)
uint16_t y Start position y (vertical)

Enumeration Type Documentation

enum image_type
Enumerator
IMAGE_YUV422 

UYVY format (uint16 per pixel)

IMAGE_GRAYSCALE 

Grayscale image with only the Y part (uint8 per pixel)

IMAGE_JPEG 

An JPEG encoded image (not per pixel encoded)

IMAGE_GRADIENT 

An image gradient (int16 per pixel)

Definition at line 34 of file image.h.

Function Documentation

void image_add_border ( struct image_t input,
struct image_t output,
uint8_t  border_size 
)

This function adds padding to input image by mirroring the edge image elements.

Parameters
[in]*input- input image (grayscale only)
[out]*output- the output image
[in]border_size- amount of padding around image. Padding is made by reflecting image elements at the edge Example: f e d c b a | a b c d e f | f e d c b a

Definition at line 245 of file image.c.

References image_t::buf, image_t::h, image_create(), image_t::type, and image_t::w.

Referenced by pyramid_build().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void image_calculate_g ( struct image_t dx,
struct image_t dy,
int32_t g 
)

Calculate the G vector of an image gradient This is used for optical flow calculation.

Parameters
[in]*dxThe gradient in the X direction
[in]*dyThe gradient in the Y direction
[out]*gThe G[4] vector devided by 255 to keep in range

Definition at line 445 of file image.c.

References image_t::buf, image_t::h, and image_t::w.

Referenced by opticFlowLK(), and opticFlowLK_flat().

+ Here is the caller graph for this function:

void image_copy ( struct image_t input,
struct image_t output 
)

Copy an image from inut to output This will only work if the formats are the same.

Parameters
[in]*inputThe input image to copy from
[out]*outputThe out image to copy to

Definition at line 77 of file image.c.

References image_t::buf, image_t::buf_size, image_t::h, image_t::ts, image_t::type, and image_t::w.

Referenced by calc_fast9_lukas_kanade(), and cv_async_function().

+ Here is the caller graph for this function:

void image_create ( struct image_t img,
uint16_t  width,
uint16_t  height,
enum image_type  type 
)

Create a new image.

Parameters
[out]*imgThe output image
[in]widthThe width of the image
[in]heightThe height of the image
[in]typeThe type of image (YUV422 or grayscale)

Definition at line 38 of file image.c.

References image_t::buf, image_t::buf_size, image_t::h, IMAGE_GRADIENT, IMAGE_JPEG, IMAGE_YUV422, image_t::type, and image_t::w.

Referenced by bebop_front_camera_thread(), cv_async_function(), cv_blob_locator_func(), cv_window_func(), detect_window(), image_add_border(), log_image(), opticflow_calc_init(), opticFlowLK(), opticFlowLK_flat(), pyramid_next_level(), qrscan(), video_capture_save(), video_thread_function(), video_thread_periodic(), and viewvideo_function().

+ Here is the caller graph for this function:

uint32_t image_difference ( struct image_t img_a,
struct image_t img_b,
struct image_t diff 
)

Calculate the difference between two images and return the error This will only work with grayscale images.

Parameters
[in]*img_aThe image to substract from
[in]*img_bThe image to substract from img_a
[out]*diffThe image difference (if not needed can be NULL)
Returns
The squared difference summed

Definition at line 477 of file image.c.

References image_t::buf, image_t::h, and image_t::w.

Referenced by opticFlowLK(), and opticFlowLK_flat().

+ Here is the caller graph for this function:

void image_draw_line ( struct image_t img,
struct point_t from,
struct point_t to 
)

Draw a line on the image.

Parameters
[in,out]*imgThe image to show the line on
[in]*fromThe point to draw from
[in]*toThe point to draw to

Definition at line 599 of file image.c.

References image_t::buf, image_t::h, IMAGE_YUV422, image_t::type, image_t::w, point_t::x, and point_t::y.

Referenced by draw_edgeflow_img(), image_show_flow(), and qrscan().

+ Here is the caller graph for this function:

void image_free ( struct image_t img)

Free the image.

Parameters
[in]*imgThe image to free

Definition at line 63 of file image.c.

References image_t::buf.

Referenced by cv_blob_locator_func(), cv_window_func(), detect_window(), opticFlowLK(), opticFlowLK_flat(), pyramid_build(), video_capture_save(), video_thread_function(), video_thread_periodic(), and viewvideo_function().

+ Here is the caller graph for this function:

void image_gradients ( struct image_t input,
struct image_t dx,
struct image_t dy 
)

Calculate the gradients using the following matrix: [0 -1 0; -1 0 1; 0 1 0].

Parameters
[in]*inputInput grayscale image
[out]*dxOutput gradient in the X direction (dx->w = input->w-2, dx->h = input->h-2)
[out]*dyOutput gradient in the Y direction (dx->w = input->w-2, dx->h = input->h-2)

Definition at line 421 of file image.c.

References image_t::buf, image_t::h, and image_t::w.

Referenced by opticFlowLK(), and opticFlowLK_flat().

+ Here is the caller graph for this function:

int32_t image_multiply ( struct image_t img_a,
struct image_t img_b,
struct image_t mult 
)

Calculate the multiplication between two images and return the error This will only work with image gradients.

Parameters
[in]*img_aThe image to multiply
[in]*img_bThe image to multiply with
[out]*multThe image multiplication (if not needed can be NULL)
Returns
The sum of the multiplcation

Definition at line 515 of file image.c.

References image_t::buf, image_t::h, and image_t::w.

Referenced by opticFlowLK(), and opticFlowLK_flat().

+ Here is the caller graph for this function:

void image_show_flow ( struct image_t img,
struct flow_t vectors,
uint16_t  points_cnt,
uint8_t  subpixel_factor 
)

Shows the flow from a specific point to a new point This works on YUV422 and Grayscale images.

Parameters
[in,out]*imgThe image to show the flow on
[in]*vectorsThe flow vectors to show
[in]*points_cntThe amount of points and vectors to show

Definition at line 576 of file image.c.

References flow_t::flow_x, flow_t::flow_y, image_draw_line(), flow_t::pos, point_t::x, and point_t::y.

Referenced by calc_fast9_lukas_kanade().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void image_show_points ( struct image_t img,
struct point_t points,
uint16_t  points_cnt 
)

Show points in an image by coloring them through giving the pixels the maximum value.

This works with YUV422 and grayscale images

Parameters
[in,out]*imgThe image to place the points on
[in]*pointsThe points to sohw
[in]*points_cntThe amount of points to show

Definition at line 551 of file image.c.

References image_t::buf, idx, IMAGE_YUV422, image_t::type, image_t::w, point_t::x, and point_t::y.

Referenced by calc_fast9_lukas_kanade().

+ Here is the caller graph for this function:

void image_subpixel_window ( struct image_t input,
struct image_t output,
struct point_t center,
uint32_t  subpixel_factor,
uint8_t  border_size 
)

This outputs a subpixel window image in grayscale Currently only works with Grayscale images as input but could be upgraded to also support YUV422 images.

Parameters
[in]*inputInput image (grayscale only)
[out]*outputWindow output (width and height is used to calculate the window size)
[in]*centerCenter point in subpixel coordinates
[in]subpixel_factorThe subpixel factor per pixel
[in]border_size- amount of padding around image. Padding is made by reflecting image elements at the edge Example: f e d c b a | a b c d e f | f e d c b a

Definition at line 363 of file image.c.

References image_t::buf, image_t::h, image_t::w, point_t::x, and point_t::y.

Referenced by opticFlowLK(), and opticFlowLK_flat().

+ Here is the caller graph for this function:

void image_switch ( struct image_t a,
struct image_t b 
)

This will switch image *a and *b This is faster as image_copy because it doesn't copy the whole image buffer.

Parameters
[in,out]*aThe image to switch
[in,out]*bThe image to switch with

Definition at line 97 of file image.c.

Referenced by calc_fast9_lukas_kanade().

+ Here is the caller graph for this function:

void image_to_grayscale ( struct image_t input,
struct image_t output 
)

Convert an image to grayscale.

Depending on the output type the U/V bytes are removed

Parameters
[in]*inputThe input image (Needs to be YUV422)
[out]*outputThe output image

Definition at line 116 of file image.c.

References image_t::buf, dest, image_t::h, IMAGE_YUV422, image_t::ts, image_t::type, and image_t::w.

Referenced by calc_fast9_lukas_kanade(), cv_window_func(), and detect_window().

+ Here is the caller graph for this function:

uint16_t image_yuv422_colorfilt ( struct image_t input,
struct image_t output,
uint8_t  y_m,
uint8_t  y_M,
uint8_t  u_m,
uint8_t  u_M,
uint8_t  v_m,
uint8_t  v_M 
)

Filter colors in an YUV422 image.

Parameters
[in]*inputThe input image to filter
[out]*outputThe filtered output image
[in]y_mThe Y minimum value
[in]y_MThe Y maximum value
[in]u_mThe U minimum value
[in]u_MThe U maximum value
[in]v_mThe V minimum value
[in]v_MThe V maximum value
Returns
The amount of filtered pixels

Definition at line 149 of file image.c.

References image_t::buf, dest, image_t::h, image_t::ts, and image_t::w.

Referenced by colorfilter_func().

+ Here is the caller graph for this function:

void image_yuv422_downsample ( struct image_t input,
struct image_t output,
uint16_t  downsample 
)

Simplified high-speed low CPU downsample function without averaging downsample factor must be 1, 2, 4, 8 ...

2^X image of typ UYVY expected. Only one color UV per 2 pixels

we keep the UV color of the first pixel pair and sample the intensity evenly 1-3-5-7-... or 1-5-9-...

input: u1y1 v1y2 u3y3 v3y4 u5y5 v5y6 u7y7 v7y8 ... downsample=1 u1y1 v1y2 u3y3 v3y4 u5y5 v5y6 u7y7 v7y8 ... downsample=2 u1y1v1 (skip2) y3 (skip2) u5y5v5 (skip2 y7 (skip2) ... downsample=4 u1y1v1 (skip6) y5 (skip6) ...

Parameters
[in]*inputThe input YUV422 image
[out]*outputThe downscaled YUV422 image
[in]downsampleThe downsampel facter (must be downsample=2^X)

Definition at line 213 of file image.c.

References image_t::buf, dest, image_t::h, image_t::ts, and image_t::w.

Referenced by viewvideo_function().

+ Here is the caller graph for this function:

void pyramid_build ( struct image_t input,
struct image_t output_array,
uint8_t  pyr_level,
uint8_t  border_size 
)

This function populates given array of image_t structs with wanted number of padded pyramids based on given input.

Parameters
[in]*input- input image (grayscale only)
[out]*output- array of image_t structs containing image pyiramid levels. Level zero contains original image, followed by pyr_level of pyramid.
[in]pyr_level- number of pyramids to be built. If 0, original image is padded and outputed.
[in]border_size- amount of padding around image. Padding is made by reflecting image elements at the edge Example: f e d c b a | a b c d e f | f e d c b a

Definition at line 337 of file image.c.

References image_add_border(), image_free(), and pyramid_next_level().

Referenced by opticFlowLK().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void pyramid_next_level ( struct image_t input,
struct image_t output,
uint8_t  border_size 
)

This function takes previous padded pyramid level and outputs next level of pyramid without padding.

For calculating new pixel value 5x5 filter matrix suggested by Bouguet is used: [1/16 1/8 3/4 1/8 1/16]' x [1/16 1/8 3/4 1/8 1/16] To avoid decimal numbers, all coefficients are multiplied by 10000.

Parameters
[in]*input- input image (grayscale only)
[out]*output- the output image
[in]border_size- amount of padding around image. Padding is made by reflecting image elements at the edge Example: f e d c b a | a b c d e f | f e d c b a

Definition at line 290 of file image.c.

References image_t::buf, image_t::h, image_create(), image_t::type, and image_t::w.

Referenced by pyramid_build().

+ Here is the call graph for this function:

+ Here is the caller graph for this function: