ROPO
Loading...
Searching...
No Matches
fmi_image_restore.c
1
22#include "fmi_image_restore.h"
23#include "fmi_image_filter.h"
24#include "fmi_image_histogram.h"
25
26
27void mark_image(FmiImage *target,FmiImage *prob,Byte threshold,Byte marker){
28 register int i;
29 check_image_properties(target,prob);
30
31 for (i=0;i<prob->volume;i++)
32 if (prob->array[i]>=threshold)
33 target->array[i]=marker;
34}
35
36
37/* simple */
38void restore_image(FmiImage *source, FmiImage *target, FmiImage *prob, Byte threshold){
39 register int i;
40 canonize_image(source,prob);
41 canonize_image(source,target);
42
43 for (i=0;i<prob->volume;i++) {
44 if (prob->array[i ]>= threshold) {
45 target->array[i] = 0;
46 target->original[i] = target->original_undetect;
47 } else {
48 target->array[i]=source->array[i];
49 target->original[i] = source->original[i];
50 }
51 }
52}
53
54void restore_image_neg(FmiImage *source,FmiImage *target,FmiImage *prob,Byte threshold){
55 register int i;
56 canonize_image(source,prob);
57 canonize_image(source,target);
58
59 for (i=0;i<prob->volume;i++)
60 if (prob->array[i]<threshold)
61 target->array[i]=0;
62 else
63 target->array[i]=source->array[i];
64}
65
66static double calculate_original_mean(FmiImage* source, int x, int y, int hrad, int vrad)
67{
68 int h,v;
69 double sum = 0.0;
70 int nhits = 0;
71 for (h = x - hrad; h <= x + hrad; h++) {
72 for (v = y - vrad; v <= y + vrad; v++) {
73 if (h >= 0 && h < source->width && v >= 0 && v < source->height) {
74 double val = get_pixel_orig(source, h, v, 0);
75 if (val != source->original_undetect) {
76 sum += val;
77 nhits++;
78 }
79 }
80 }
81 }
82 if (nhits > 0) {
83 return (double)(sum / (double)nhits);
84 }
85 return source->original_undetect;
86}
87
88static void process_original_mean(FmiImage* source, FmiImage* target, int hrad, int vrad)
89{
90 int x, y;
91 for (x = 0; x < source->width; x++) {
92 for (y = 0; y < source->height; y++) {
93 put_pixel_orig(target, x, y, 0, calculate_original_mean(source, x, y, hrad, vrad));
94 }
95 }
96}
97
98/* other */
99void restore_image2(FmiImage *source,FmiImage *target,FmiImage *prob,Byte threshold){
100 register int i;
101 FmiImage median;
102 FmiImage original_mean;
103 init_new_image(&median);
104 init_new_image(&original_mean);
105
106 canonize_image(source,prob);
107 canonize_image(source,target);
108 canonize_image(source,&median);
109 canonize_image(source,&original_mean);
110
111 /* ERASE ANOMALIES (to black) */
112 for (i=0; i < prob->volume; i++) {
113 if (prob->array[i] >= threshold) {
114 target->array[i] = 0;
115 target->original[i] = target->original_undetect;
116 } else {
117 target->array[i] = source->array[i];
118 target->original[i] = source->original[i];
119 }
120 }
121
122 /* CALCULATE ME(DI)AN OF NONZERO PIXELS */
123 pipeline_process(target, &median, 2, 2, histogram_mean_nonzero); /* Affects the 8-bit version */
124
125 process_original_mean(target, &original_mean, 2, 2); /* And the original data */
126
127 /* REPLACE ANOMALOUS PIXELS WITH THAT NEIGHBORHOOD ME(DI)AN */
128 for (i = 0; i < prob->volume; i++){
129 if (prob->array[i] >= threshold) {
130 target->array[i] = median.array[i];
131 target->original[i] = original_mean.original[i];
132 }
133 }
134
135 reset_image(&median);
136 reset_image(&original_mean);
137}
138
double * original
Definition fmi_image.h:154