Function

void impr_flip_values (u8 * dest, u8 * src, int size)

Arguments

dest
destination image
src
source image
size
image size in pixels

Description

Flips around image values, so min becomes max and vice-versa. dest == src is ok.

Function

void impr_add_scalar_wrap (u8 * dest, u8 * src, int size, int value)

Arguments

dest
destination image
src
source image
size
image size in pixels
value
value to add to all pixels

Description

Add value to each pixel. Assumes it will wrap around after U8_MAX. dest == src is ok.

Function

void impr_add_scalar (u8 * dest, u8 * src, int size, int value)

Arguments

dest
destination image
src
source image
size
image size in pixels
value
value to add to all pixels

Description

Add value to each pixel. Values > U8_MAX will be clapmed to U8_MAX. dest == src is ok.

Function

void impr_add (u8 * dest, u8 * src1, u8 * src2, int size)

Arguments

dest
destination image
src1
1st source image
src2
2nd source image
size
image size in pixels

Description

Add pixels at same positions. Values > U8_MAX will be clapmed to U8_MAX. dest == src1 or src2 is ok.

Function

void impr_div_scalar (u8 * dest, u8 * src, int size, int value)

Arguments

dest
destination image
src
source image
size
image size in pixels
value
value to divide by

Description

Divide each pixel by value. This will effectively produce a darker image. dest == src is ok.

Function

void impr_div (u8 * dest, u8 * src1, u8 * src2, int size)

Arguments

dest
destination image
src1
1st source image
src2
2nd source image
size
image size in pixels

Description

Divide pixels at same positions. (dest[x] = src1[x] * 255 / src2[x]). This will produce a lighter image on average. > U8_MAX values are clamped. dest == src1 or src2 is ok.

Function

void impr_bin2grey (u8 * dest, b8 * src, int size)

Arguments

dest
destination image
src
binary source image
size
image size in pixels

Description

0->0, 1->U8_MAX for each pixel (usable to show binary images). This code abuses integer underflow. Will that work everywhere? dest == src is ok.

Function

void impr_movelr (u8_or_b8p _dest, u8_or_b8p _src, int w, int h, int off)

Arguments

_dest
destination image
_src
source image
w
image width
h
image height
off
offset to move to (y*w+x)

Description

Moves a binary or grey image by offset off. dest == src is ok.

Function

void cs_rgb2hsv (struct hsv * hsv, const struct rgb * rgb, int size)

Arguments

hsv
destination image in hsv colorspace
rgb
source image in rgb colorspace
size
image size

Description

Converts image from RGB to HSV colorspace.

Function

void cs_hsv2rgb (struct rgb * rgb, const struct hsv * hsv, int size)

Arguments

rgb
destination image in rgb colorspace
hsv
source image in hsv colorspace
size
image size

Description

Converts image from HSV to RGB colorspace.

Function

void cs_chan2rgb (struct rgb * rgb, const u8 * chan, int size)

Arguments

rgb
destination image in rgb colorspace
chan
source image - grey channel
size
image size

Description

Converts grey image to RGB colorspace.

Function

void cs_rgb2argb_buf (u32 * buf, const struct rgb * rgb, int size)

Arguments

buf
destination buffer
rgb
source image
size
image size

Description

Pack RGB image into argb buffer. Same format used by ie. imlib2

Function

void cs_argb_buf2rgb (struct rgb * rgb, const u32 * buf, int size)

Arguments

rgb
destination image
buf
source buffer
size
image size

Description

Unpacks argb buffer into RGB image. Same format used by ie. imlib2

Function

void cs_rgb2abgr_buf (u32 * buf, const struct rgb * rgb, int size)

Arguments

buf
destination buffer
rgb
source image
size
image size

Description

Pack RGB image into abgr buffer. Same format used by ie. gdk-pixbuf

Function

void cs_abgr_buf2rgb (struct rgb * rgb, const u32 * buf, int size)

Arguments

rgb
destination image
buf
source buffer
size
image size

Description

Unpacks abgr buffer into RGB image. Same format used by ie. gdk-pixbuf

Function

void cs_rgb2yrg (struct yrg * yrg, const struct rgb * rgb, int size)

Arguments

yrg
destination image in hsv colorspace
rgb
source image in rgb colorspace
size
image size

Description

Converts image from RGB to normalized YRG colorspace. r = R / (R+G+B) g = G / (R+G+B) r+g+b = 1 (can be calculated now)

Note

could be optimized with division tables.

Function

void cs_yrg2rgb (struct rgb * rgb, const struct yrg * yrg, int size)

Arguments

rgb
destination image in rgb colorspace
yrg
source image in hsv colorspace
size
image size

Description

Converts image normalized YRG to RGB colorspace.

Function

void impr_manhattan_distance (u8 * dest, b8 * src, int w, int h)

Arguments

dest
destination image
src
source image
w
image width
h
image height

Description

Fill matrix with manhattan distances to closest on-pixel (1).

Manhattan distance is defined as

D = |x2-x1| + |y2-y1| Image edges are ignored for speed. dest == src is ok.

Function

void impr_chessboard_distance (u8 * dest, b8 * src, int w, int h)

Arguments

dest
destination image
src
source image
w
image width
h
image height

Description

Fill matrix with chessboard distances to closest on-pixel (1).

Chessboard distance is defined as

D = max(|x2-x1|, |y2-y1|) Image edges are ignored for speed. dest == src is ok.

Function

void filter_roberts_thresh (b8 * dest, u8 * src, int w, int h, int thresh)

Arguments

dest
destination binarized image
src
source grey image
w
image width
h
image height
thresh
threshold above (or equal to) which the value is considered one

Description

Applies roberts filter to grey image, and binarizes to values >= thresh. Resulting image is shifted by 0.5 pixel to left and up. dest == src is ok.

Function

void filter_smooth_2 (u8 * dest, u8 * src, int w, int h)

Arguments

dest
destination image
src
source image
w
image width
h
image height

Description

Apply a 2x2 smoothening filter. p[y][x] = avg(p[y..y+1][x..x+1]) dest == src is ok.

Function

void impr_strip_border (u8_or_b8p _chan, int w, int h)

Arguments

_chan
binary image in which to fill the holes
w
image width
h
image height

Description

Sets image borders to 0..

Function

void impr_flood (u8 * chan, int w, int h, int x, int y, u8 newv)

Arguments

chan
image in which to flood an object
w
image width
h
image height
x
x coordinate of flooded object
y
y coordinate of flooded object
newv
pixel value to be flooded with

Description

Floods an object in an image.

Function

void impr_fill_holes (b8 * chan, int w, int h)

Arguments

chan
binary image in which to fill the holes
w
image width
h
image height

Description

Fills holes in a binary image. This function strips borders of the image.

Function

void impr_negate (b8 * dest, b8 * src, int size)

Arguments

dest
destination image
src
source image
size
image size

Description

Invert image values. dest == src is ok.

Function

void impr_dilaten (b8 * dest, b8 * src, int w, int h, int conn, int times)

Arguments

dest
destination image
src
source image
w
image width
h
image height
conn
connectedness (4 or 8)
times
dilate how many times

Description

4 or 8 connected dilation applied times times. dest == src is ok.

Function

void impr_eroden (b8 * dest, b8 * src, int w, int h, int conn, int times)

Arguments

dest
destination image
src
source image
w
image width
h
image height
conn
connectedness (4 or 8)
times
erode how many times

Description

4 or 8 connected erosion applied times times. dest == src is ok.

Function

void impr_close (b8 * dest, b8 * src, int w, int h)

Arguments

dest
destination image
src
source image
w
image width
h
image height

Description

"Close" image. dest == src is ok.

Function

void impr_open (b8 * dest, b8 * src, int w, int h)

Arguments

dest
destination image
src
source image
w
image width
h
image height

Description

"Open" image. dest == src is ok.

Function

void impr_and (b8 * dest, b8 * src1, b8 * src2, int size)

Arguments

dest
destination image
src1
1st source image
src2
2nd source image
size
image size

Description

Binary AND on each pixel pair of images. dest == src1 or src2 is ok.

Function

void impr_or (b8 * dest, b8 * src1, b8 * src2, int size)

Arguments

dest
destination image
src1
1st source image
src2
2nd source image
size
image size

Description

Binary OR on each pixel pair of images. dest == src1 or src2 is ok.

Function

void impr_downscale (u8 * dest, u8 * src, int w, int h, int factor)

Arguments

dest
destination, smaller image
src
original image
w
image width
h
image height
factor
shrink image by this integer factor

Description

Shrinks image by integer factor. w and h have to be multiples of factor.

Function

void impr_downscale2 (u8 * dest, u8 * src, int w, int h, int factorx, int factory)

Arguments

dest
destination, smaller image
src
original image
w
image width
h
image height
factorx
shrink image in x dimension by this integer factor
factory
shrink image in y dimension by this integer factor

Description

Shrinks image by integers factorx and factory. w and h have to be multiples of factorx and factory respectively.

Function

void impr_upscale (u8 * dest, u8 * src, int wd, int hd, int factor)

Arguments

dest
destination, larger
src
original image
wd
source image width
hd
source image height
factor
widen image by this integer factor

Description

Increases image size with linear interpolation. dw and dh have to be multiples of factor.

Note

with 2**x factors, we could use shifting, which could be faster.

Function

void impr_upscale2 (u8 * dest, u8 * src, int wd, int hd, int factorx, int factory)

Arguments

dest
destination, larger
src
original image
wd
source image width
hd
source image height
factorx
widen image in x dimension by this integer factor
factory
widen image in y dimension by this integer factor

Description

Increases image size with linear interpolation. dw and dh have to be multiples of factorx and factory respectively.

Function

int segmentize_8 (u16 * region_mask, b8 * chan, int w, int h)

Arguments

region_mask
returned regions, [x]=0 for border, numbers enumerate regions
chan
segmentize this; [x]=0 are considered borders, 1 region parts
w
image width
h
image height

Description

Performs 8-connected region segmentation. Returns number of regions, with 0 to that number in region_mask.

Function

int segmentize_4 (u16 * region_mask, b8 * chan, int w, int h)

Arguments

region_mask
returned regions, [x]=0 for border, numbers enumerate regions
chan
segmentize this; [x]=0 are considered borders, 1 region parts
w
image width
h
image height

Description

Performs 4-connected region segmentation. Returns number of regions, with 0 to that number in region_mask.

Function

void impr_subimage (u8_or_b8p _dest, int dw, int dh, u8_or_b8p _src, int w, int x, int y)

Arguments

_dest
destination (smaller image)
dw
subimage width
dh
subimage height
_src
source (bigger image)
w
image width
x
left border of the subimage
y
upper border of the subimage

Description

Extracts a square part of _dest. _dest == _src is ok.

Function

void impr_putimage (u8_or_b8p _dest, int w, u8_or_b8p _src, int dw, int dh, int x, int y)

Arguments

_dest
destination (bigger image)
w
image width
_src
source (smaller image)
dw
subimage width
dh
subimage height
x
x coordinate of subimage destination
y
y coordinate of subimage destination

Description

Puts _src onto bigger _dest image.