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

Declarations for an image and associated functions. More...

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

Go to the source code of this file.

Data Structures

struct  Pixel_f
 A 3-sample single precision floating point picture element. More...
struct  Image_f
 An image of Pixel_f. More...

Typedefs

typedef struct Pixel_f Pixel_f
 A 3-sample single precision floating point picture element.
typedef struct Image_f Image_f
 An image of Pixel_f.

Functions

create_image

Creates an image.

void create_image_f (Image_f **img_out, uint32_t num_rows, uint32_t num_cols)
 Creates a single precision floating point image.
create_init_image

Creates and initializes an image.

void create_init_image_f (Image_f **img_out, uint32_t num_rows, uint32_t num_cols, Pixel_f val)
 Creates and initializes a single precision floating point image.
create_zero_image

Creates an image and initializes it with zeros.

void create_zero_image_f (Image_f **img_out, uint32_t num_rows, uint32_t num_cols)
 Creates a single precision floating point image and initializes it with zeros.
create_random_image

Creates an image and initializes it with random values.

void create_random_image_f (Image_f **img_out, uint32_t num_rows, uint32_t num_cols, Pixel_f min, Pixel_f max)
 Creates a single precision floating point image and initializes it with random values.
create_image_from_matrices

Creates an image from a three matrices.

Errorcreate_image_from_matrices_f (Image_f **img_out, const Matrix_f *m_r, const Matrix_f *m_g, const Matrix_f *m_b)
 Creates a single precision floating point image from three matrices.
create_image_from_matrix

Creates a grayscale image from a matrix.

void create_image_from_matrix_f (Image_f **img_out, const Matrix_f *m)
 Creates a single precision floating point grayscale image from a matrix.
create_matrices_from_image

Creates three matrices from an image.

void create_matrices_from_image_f (Matrix_f **m_r_out, Matrix_f **m_g_out, Matrix_f **m_b_out, const Image_f *img)
 Creates three single precision floating point matrices from an image.
create_matrix_from_image

Creates an averaged matrix from an image.

void create_matrix_from_image_f (Matrix_f **m_out, const Image_f *img, float r_weight, float g_weight, float b_weight)
 Creates an averaged single precision floating point matrix from an image.
copy_image

Copies an image.

void copy_image_f (Image_f **img_out, const Image_f *img_in)
 Copies a single precision floating point image.
free_image

Frees an image.

void free_image_f (Image_f *img)
 Frees a single precision floatin point image.

Detailed Description

Declarations for an image and associated functions.

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

The image holds single precision floating point pixel elements.

Although the image is indexed by row and column, the pixels are allocated as a 1D array in row-major order. So iterating over the pixels can be done inside a single loop.

Definition in file image.h.


Typedef Documentation

typedef struct Pixel_f Pixel_f

A 3-sample single precision floating point picture element.

Sample values range [0,1].

typedef struct Image_f Image_f

An image of Pixel_f.


Function Documentation

void create_image_f ( Image_f **  img_out,
uint32_t  num_rows,
uint32_t  num_cols 
)

Creates a single precision floating point image.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
num_rowsNumber of rows in the image.
num_colsNumber of columns in the image.
Note:
Dimensions must be > 0.

Definition at line 84 of file image.c.

void create_init_image_f ( Image_f **  img_out,
uint32_t  num_rows,
uint32_t  num_cols,
Pixel_f  val 
)

Creates and initializes a single precision floating point image.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
num_rowsNumber of rows in the image.
num_colsNumber of columns in the image.
valPixel value to initialize all pixels of the image with.
Note:
Dimensions must be > 0.

Definition at line 145 of file image.c.

void create_zero_image_f ( Image_f **  img_out,
uint32_t  num_rows,
uint32_t  num_cols 
)

Creates a single precision floating point image and initializes it with zeros.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
num_rowsNumber of rows in the image.
num_colsNumber of columns in the image.
Note:
Dimensions must be > 0.

Definition at line 187 of file image.c.

void create_random_image_f ( Image_f **  img_out,
uint32_t  num_rows,
uint32_t  num_cols,
Pixel_f  min,
Pixel_f  max 
)

Creates a single precision floating point image and initializes it with random values.

Calls rand() to generate the random numbers.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
num_rowsNumber of rows in the image.
num_colsNumber of columns in the image.
minMinimum random value.
maxMaximum random value.
Note:
Dimensions must be > 0.
Since Pixel_f samples range [0,1], min and max should be in that range as well so a meaningful image is created.
Warning:
Does not check min and max to see if they would cause overflow.

Definition at line 229 of file image.c.

Error* create_image_from_matrices_f ( Image_f **  img_out,
const Matrix_f m_r,
const Matrix_f m_g,
const Matrix_f m_b 
)

Creates a single precision floating point image from three matrices.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
m_rMatrix to copy into the red samples of the image.
m_gMatrix to copy into the green samples of the image.
m_bMatrix to copy into the blue samples of the image.
Returns:
On success, NULL is returned. On error, an Error is returned and *img_out is freed and set to NULL.

Definition at line 282 of file image.c.

void create_image_from_matrix_f ( Image_f **  img_out,
const Matrix_f m 
)

Creates a single precision floating point grayscale image from a matrix.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
mMatrix to copy into the red, green and blue samples of the image.

Definition at line 341 of file image.c.

void create_matrices_from_image_f ( Matrix_f **  m_r_out,
Matrix_f **  m_g_out,
Matrix_f **  m_b_out,
const Image_f img 
)

Creates three single precision floating point matrices from an image.

Parameters:
m_r_outResult parameter. Red sample matrix. If *m_r_out is NULL, an image is allocated; otherwise its space is re-used.
m_g_outResult parameter. Green sample matrix. If *m_g_out is NULL, an image is allocated; otherwise its space is re-used.
m_b_outResult parameter. Blue sample matrix. If *m_b_out is NULL, an image is allocated; otherwise its space is re-used.
imgImage to copy into the matrices.

Definition at line 374 of file image.c.

void create_matrix_from_image_f ( Matrix_f **  m_out,
const Image_f img,
float  r_weight,
float  g_weight,
float  b_weight 
)

Creates an averaged single precision floating point matrix from an image.

The weights are normalized to sum to one.

The best weights for a human visible grayscale conversion are

   r=0.3   g=0.59   b=0.11
Parameters:
m_outResult parameter. If *m_out is NULL, a matrix is allocated; otherwise its space is re-used.
imgImage to copy into the matrix.
r_weightWeight of the red sample.
g_weightWeight of the green sample.
b_weightWeight of the blue sample.
Note:
Weights must be non-negative.

Definition at line 438 of file image.c.

void copy_image_f ( Image_f **  img_out,
const Image_f img_in 
)

Copies a single precision floating point image.

Parameters:
img_outResult parameter. If *img_out is NULL, an image is allocated; otherwise its space is re-used.
img_inImage to copy.

Definition at line 493 of file image.c.

void free_image_f ( Image_f img)

Frees a single precision floatin point image.

Parameters:
imgImage to free.

Definition at line 526 of file image.c.