ROPO
Loading...
Searching...
No Matches
fmi_image_filter_morpho.c
1
22#include "fmi_util.h"
23#include "fmi_image.h"
24#include "fmi_image_filter.h"
25#include "fmi_image_histogram.h"
26
27void morph_closing(FmiImage *source,FmiImage *target,int w,int h){
28 FmiImage temp;
29 init_new_image(&temp);
30 canonize_image(source,&temp);
31 canonize_image(source,target);
32 pipeline_process(source,&temp,w,h,histogram_max);
33 pipeline_process(&temp,target,w,h,histogram_min);
34 if (FMI_DEBUG(4)) write_image("debug_morph_closing",target,PGM_RAW);
35 reset_image(&temp);
36}
37
38void morph_opening(FmiImage *source,FmiImage *target,int w,int h){
39 FmiImage temp;
40 init_new_image(&temp);
41 canonize_image(source,&temp);
42 canonize_image(source,target);
43 pipeline_process(source,&temp,w,h,histogram_min);
44 pipeline_process(&temp,target,w,h,histogram_max);
45 reset_image(&temp);
46}
47
48void distance_transform(FmiImage *source, FmiImage *target)
49{
50 register int i, j, k, s, t;
51 if (source != target)
52 copy_image(source, target);
53
54 for (j = 0; j < target->height; j++) {
55 for (i = 0; i < target->width; i++) {
56 for (k = 0; k < target->channels; k++) {
57 t = get_pixel(target, i, j, k);
58 s = get_pixel(target, i - 1, j, k);
59 if (s > 0)
60 s--;
61 if (s > t) {
62 put_pixel(target, i, j, k, s);
63 t = s;
64 }
65 s = get_pixel(target, i, j - 1, k);
66 if (s > 0)
67 s--;
68 if (s > t)
69 put_pixel(target, i, j, k, s);
70 }
71 }
72 }
73
74 for (j = target->height - 1; j >= 0; j--) {
75 for (i = target->width - 1; i > 0; i--) {
76 for (k = 0; k < target->channels; k++) {
77 t = get_pixel(target, i, j, k);
78 s = get_pixel(target, i + 1, j, k);
79 if (s > 0)
80 s--;
81 if (s > t) {
82 put_pixel(target, i, j, k, s);
83 t = s;
84 }
85 s = get_pixel(target, i, j + 1, k);
86 if (s > 0)
87 s--;
88 if (s > t)
89 put_pixel(target, i, j, k, s);
90 }
91 }
92 }
93}