25#include "fmi_image_filter.h"
32 canonize_image(source, trace);
34 for (k = 0; k < source->channels; k++) {
35 for (j = 0; j < source->height; j++) {
38 for (i = 0; i < source->width; i++) {
39 g = (get_pixel(source, i, j_upper, k)
40 - get_pixel(source, i, j_lower, k)) / 2 + 128;
45 put_pixel(trace, i, j, k, g);
56 canonize_image(source, trace);
58 for (k = 0; k < source->channels; k++) {
59 for (i = 0; i < source->width; i++) {
62 for (j = 0; j < source->height; j++) {
63 g = (get_pixel(source, i_right, j, k) - get_pixel(source, i_left, j, k)) / 2 + 128;
68 put_pixel(trace, i, j, k, g);
77 Byte g,g_upper,g_lower,gmax;
78 canonize_image(source,trace);
81 for (k=0;k<source->channels;k++){
82 for (j=1;j<source->height-1;j++){
83 for (i=0;i<source->width;i++){
84 g = get_pixel(source,i,j,k);
85 g_upper = get_pixel(source,i,j-1,k);
86 g_lower = get_pixel(source,i,j+1,k);
87 gmax = MAX(g_upper,g_lower);
90 put_pixel(trace,i,j,k,(Byte)(g-gmax));
92 put_pixel(trace,i,j,k,0);
104 canonize_image(source, trace);
107 for (k = 0; k < source->channels; k++) {
108 for (j = 1; j < source->height - 1; j++) {
109 for (i = 0; i < source->width; i++) {
110 g = get_pixel(source, i, j, k);
115 g_sum = (get_pixel(source, i, j - 1, k)
116 + get_pixel(source, i, j + 1, k));
117 gt = (2 * g - g_sum) / (1 + g_sum);
120 put_pixel(trace, i, j, k, gt);
130 canonize_image(source, trace);
133 for (k = 0; k < source->channels; k++) {
134 for (j = 1; j < source->height - 1; j++) {
135 for (i = 0; i < source->width; i++) {
136 g = get_pixel(source, i, j, k) - get_pixel(source, i, j - 1, k);
137 g2 = get_pixel(source, i, j, k) - get_pixel(source, i, j + 1, k);
140 put_pixel(trace, i, j, k, g);
145 write_image(
"edges", trace, PGM_RAW);
151 unsigned char g, g_left, g_right, gmax, gt;
152 canonize_image(source, trace);
154 for (k = 0; k < source->channels; k++) {
155 for (i = 1; i < source->width - 1; i++) {
156 for (j = 0; j < source->height; j++) {
157 g = get_pixel(source, i, j, k);
158 g_left = get_pixel(source, i - 1, j, k);
159 g_right = get_pixel(source, i + 1, j, k);
160 gmax = MAX(g_left,g_right);
162 gt = get_pixel(trace, i, j, k);
163 put_pixel(trace, i, j, k, MAX(gt,g-gmax));
175 canonize_image(source,trace);
178 for (k=0;k<source->channels;k++){
179 for (i=1;i<source->width-1;i++){
180 for (j=0;j<source->height;j++){
181 g =get_pixel(source,i,j,k)-get_pixel(source,i-1,j,k);
182 g2=get_pixel(source,i,j,k)-get_pixel(source,i+1,j,k);
185 put_pixel(trace,i,j,k,g);}
188 if (FMI_DEBUG(5)) write_image(
"debug_edges",trace,PGM_RAW);
195 canonize_image(source, trace);
196 for (k = 0; k < source->channels; k++)
197 for (j = 0; j < source->height; j++) {
199 for (i = 0; i < source->width; i++) {
200 g = get_pixel(source, i, j, k);
202 put_pixel(trace, i, j, k, g);
203 g_old = g * promille / 1000;
207 write_image(
"debug_iir_right", trace, PGM_RAW);
214 canonize_image(source, trace);
215 for (k = 0; k < source->channels; k++)
216 for (j = 0; j < source->height; j++) {
218 for (i = source->width - 1; i >= 0; i--) {
219 g = get_pixel(source, i, j, k);
221 put_pixel(trace, i, j, k, g);
222 g_old = g * promille / 1000;
226 write_image(
"debug_iir_left", trace, PGM_RAW);
233 canonize_image(source, trace);
234 for (k = 0; k < source->channels; k++)
235 for (i = 0; i < source->width; i++) {
237 for (j = 0; j < source->height; j++) {
238 g = get_pixel(source, i, j, k);
240 put_pixel(trace, i, j, k, g);
241 g_old = g * promille / 1000;
245 write_image(
"debug_iir_up", trace, PGM_RAW);
252 canonize_image(source, trace);
253 for (k = 0; k < source->channels; k++)
254 for (i = 0; i < source->width; i++) {
256 for (j = source->height - 1; j >= 0; j--) {
257 g = get_pixel(source, i, j, k);
259 put_pixel(trace, i, j, k, g);
260 g_old = g * promille / 1000;
264 write_image(
"debug_iir_down", trace, PGM_RAW);
270 check_image_properties(source, mask);
274 for (i = 0; i < source->volume; i++)
275 if (mask->array[i] < threshold)
276 source->array[i] = c;
283 for (i=0;i<source->volume;i++){
285 target->array[i]=(c>threshold)?c:0;
291 for (i=0;i<source->volume;i++)
292 target->array[i]=(source->array[i]>c)?255:0;
297 signed char slope,
void(* put_func)(
FmiImage *,
int,
int,
int, Byte))
299 register int i, j, k;
302 check_image_properties(domain, target);
304 check_image_properties(domain, source);
305 for (k = 0; k < domain->channels; k++) {
306 for (j = 0; j < domain->height; j++) {
308 for (i = 0; i < domain->width; i++) {
311 if (((
int) get_pixel(domain, i, j, k)) > 0) {
314 if (source != NULL) {
315 c = (int) get_pixel(source, i, j, k);
330 put_func(target, i, j, k, (Byte) c);
337 signed char slope,
void(* put_func)(
FmiImage *,
int,
int,
int, Byte))
339 register int i, j, k;
342 for (k = 0; k < domain->channels; k++) {
343 for (j = 0; j < domain->height; j++) {
345 for (i = domain->width - 1; i >= 0; i--) {
347 if (((
int) get_pixel(domain, i, j, k)) > 0) {
350 if (source != NULL) {
351 c = (int) get_pixel(source, i, j, k);
369 put_func(target, i, j, k, (Byte) c);
376 signed char slope,
void(* put_func)(
FmiImage *,
int,
int,
int, Byte))
378 register int i, j, k;
381 for (k = 0; k < domain->channels; k++) {
382 for (i = 0; i < domain->width; i++) {
384 for (j = 0; j < domain->height; j++) {
385 if (get_pixel(domain, i, j, k) > 0) {
387 if (source != NULL) {
388 c = get_pixel(source, i, j, k);
403 put_func(target, i, j, k, (
unsigned char) c);
410 signed char slope,
void(* put_func)(
FmiImage *,
int,
int,
int, Byte))
412 register int i, j, k;
415 for (k = 0; k < domain->channels; k++) {
416 for (i = 0; i < domain->width; i++) {
418 for (j = domain->height - 1; j >= 0; j--) {
419 if (get_pixel(domain, i, j, k) > 0) {
421 if (source != NULL) {
422 c = get_pixel(source, i, j, k);
437 put_func(target, i, j, k, (
unsigned char) c);
447 propagate_right(NULL, source, target, 1, put_pixel);
449 write_image(
"debug_horz_seg_lengths_1", target, PGM_RAW);
450 propagate_left(target, source, target, 0, put_pixel);
452 write_image(
"debug_horz_seg_lengths", target, PGM_RAW);
457 propagate_up(NULL, source, target, 1, put_pixel);
459 write_image(
"debug_vert_seg_lengths_1", target, PGM_RAW);
460 propagate_down(target, source, target, 0, put_pixel);
462 write_image(
"debug_vert_seg_lengths", target, PGM_RAW);
465void row_statistics(
FmiImage *source, Byte *nonzero, Byte *avg, Byte *pow)
471 for (j = 0; j < source->height; j++) {
475 for (i = 0; i < source->width; i++) {
476 c = get_pixel(source, i, j, 0);
485 nonzero[j] = (255 * nz) / source->width;
487 avg[j] = s / source->width;
489 pow[j] = sqrt(s2 / source->width);
493void col_statistics(
FmiImage *source, Byte *nonzero, Byte *avg, Byte *pow)
499 for (i = 0; i < source->width; i++) {
503 for (j = 0; j < source->height; j++) {
504 c = get_pixel(source, i, j, 0);
510 nonzero[j] = 255 * nz / source->width;
512 avg[j] = s / source->width;
514 pow[j] = sqrt(s2 / source->width);