-
Notifications
You must be signed in to change notification settings - Fork 11
/
imgp_contour.c
31 lines (27 loc) · 818 Bytes
/
imgp_contour.c
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
// clang -Os -o imgp_contour imgp_contour.c -lm
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include "imgp.h"
int main(int argc, char* argv[])
{
char *name = argv[1];
uint8_t *pixels;
int w, h, bpp;
pixels = stbi_load(name, &w, &h, &bpp, 3);
assert(pixels);
uint8_t *gray = malloc(w*h*4);
uint8_t *dilated = gray+w*h;
uint8_t *diff = gray+w*h*2;
uint8_t *contour = gray+w*h*3;
imgp_gray(pixels, w, h, w, gray, w);
imgp_dilate(gray, w, h, 1, dilated);
stbi_write_jpg("dilated.jpg", w, h, 1, dilated, 0);
imgp_absdiff(gray, dilated, w, h, diff);
stbi_write_jpg("diff.jpg", w, h, 1, diff, 0);
imgp_reverse(diff, w, h, contour);
stbi_write_jpg("contour.jpg", w, h, 1, contour, 0);
free(gray);
stbi_image_free(pixels);
}