aboutsummaryrefslogtreecommitdiff
path: root/include/lib/seg/util.h
blob: 4d6b6e4f40a790b240c5095c61d4d34177bbc69a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef INC_LIB_SEG_UTIL_H
#define INC_LIB_SEG_UTIL_H

#include <lib/bool.h>
#include <lib/png.h>
#include <lib/data/image_types.h>
#include <stdint.h>
#include <stddef.h>

// Convert x,y coords to linear coordinate
size_t xy_to_coord(size_t x, size_t y, uint32_t width, uint32_t height);

// Determine if coordinate is on a mask boundary
//  Assumes mask is (WxH)
bool_t is_on_mask_boundary(MaskData_t* mask, uint32_t width, uint32_t height, size_t x, size_t y);

// Dilate masks by one 4-connected pixel
void dilate(MaskData_t** mask, uint32_t width, uint32_t height);

// Erode masks by one 4-connected pixel
void erode(MaskData_t** mask, uint32_t width, uint32_t height);

// Close up masks by N-pixels
void closeup(MaskData_t** mask, uint32_t width, uint32_t height, size_t count);

// Combine Label Masks
// For all empty spaces in the destination, put the extra label if it exists
// Allocates an array if destination is unallocated
Mask* combine_masks(Mask *destination, Mask *extra_labels);

// Process Tif File to Labels
//  width, height will be overwritten with image dimensions
//  starting_label_p will be incremented for each label found in the image
Mask* tif_to_labels(char* tif_file_name, uint32_t *width, uint32_t *height, MaskData_t *starting_label_p);

// Convert mask to bitmap
Bitmap* image_mask_data_to_bitmap(MaskData_t* buffer, uint32_t width, uint32_t height);

// Reduce a mask to the contiguous regions
//  Automatically update pointer to contiguous mask
//  Freeing previous mask
void reduce_contiguous_regions(MaskData_t** masks_p, uint32_t width, uint32_t height, MaskData_t* total_labels);

#endif