TPCCLIB
Loading...
Searching...
No Matches
imagecomp.c
Go to the documentation of this file.
1
6/*****************************************************************************/
7#include "tpcclibConfig.h"
8/*****************************************************************************/
9#include "tpcimage.h"
10/*****************************************************************************/
11
12/*****************************************************************************/
20 IMG *d1,
22 IMG *d2
23) {
24 if(d1==NULL || d2==NULL) return(1);
25 if(d1->dimz!=d2->dimz) return(1);
26 if(d1->dimy!=d2->dimy) return(1);
27 if(d1->dimx!=d2->dimx) return(1);
28 return(0);
29}
30/*****************************************************************************/
31
32/*****************************************************************************/
41 IMG *d1,
43 IMG *d2,
45 TPCSTATUS *status
46) {
47 int verbose=0; if(status!=NULL) verbose=status->verbose;
48 if(verbose>1) printf("%s()\n", __func__);
49
50 /* Check that required data exists */
51 if(d1==NULL || d2==NULL) {
52 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
53 return(3);
54 }
55
56 int ret=0;
57 if(d1->cunit!=d2->cunit) ret+=1;
58 if(d1->tunit!=d2->tunit) ret+=2;
59 if(ret>0 && verbose>0) {
60 printf("img1.cunit := %s\n", unitName(d1->cunit));
61 printf("img2.cunit := %s\n", unitName(d2->cunit));
62 printf("img1.tunit := %s\n", unitName(d1->tunit));
63 printf("img2.tunit := %s\n", unitName(d2->tunit));
64 }
65 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
66 return(ret);
67}
68/*****************************************************************************/
69
70/*****************************************************************************/
81 IMG *d1,
83 IMG *d2,
85 const float test_abs,
89 const float test_rel,
91 TPCSTATUS *status
92) {
93 int verbose=0; if(status!=NULL) verbose=status->verbose;
94 if(verbose>1) printf("%s()\n", __func__);
95
96 /* Check that required data exists */
97 if(d1==NULL || d2==NULL || d1->dimz<1 || d2->dimz<1 || d1->dimy<1 || d2->dimy<1
98 || d1->dimx<1 || d2->dimx<1 || d1->dimt<1 || d2->dimt<1) {
99 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
100 return 1;
101 }
102
103 /* Dimensions must match */
104 if(d1->dimz!=d2->dimz || d1->dimy!=d2->dimy || d1->dimx!=d2->dimx || d1->dimt!=d2->dimt) {
105 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
106 if(verbose>0) printf("different IMG dimension.\n");
107 return(2);
108 }
109
110 /* Compare */
111 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
112 for(int zi=0; zi<d1->dimz; zi++)
113 for(int yi=0; yi<d1->dimy; yi++)
114 for(int xi=0; xi<d1->dimx; xi++)
115 for(int ti=0; ti<d1->dimt; ti++) {
116 if(floatMatch(d1->m[zi][yi][xi][ti], d2->m[zi][yi][xi][ti], test_abs)==1)
117 continue;
118 if(test_rel>0.0 && floatMatchRel(d1->m[zi][yi][xi][ti], d2->m[zi][yi][xi][ti], test_rel)==1)
119 continue;
120 if(verbose>0) {
121 float s;
122 s=fabsf(d1->m[zi][yi][xi][ti] - d2->m[zi][yi][xi][ti]);
123 printf("img1.m[%d][%d][%d][%d] := %g\n", zi, yi, xi, ti, d1->m[zi][yi][xi][ti]);
124 printf("img2.m[%d][%d][%d][%d] := %g\n", zi, yi, xi, ti, d2->m[zi][yi][xi][ti]);
125 printf("|diff| := %g\n", s);
126 printf("diff_limit := %g\n", test_abs);
127 if(test_rel>0.0) printf("rel_diff_limit := %g\n", test_rel);
128 }
129 return(10);
130 }
131 return(0);
132}
133/*****************************************************************************/
134
135/*****************************************************************************/
146 IMG *d1,
148 IMG *d2,
150 const float test_abs,
154 const float test_rel,
156 TPCSTATUS *status
157) {
158 int verbose=0; if(status!=NULL) verbose=status->verbose;
159 if(verbose>1) printf("%s()\n", __func__);
160
161 /* Check that required data exists */
162 if(d1==NULL || d2==NULL || d1->dimt<1 || d2->dimt<1) {
163 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_NO_DATA);
164 return 1;
165 }
166
167 /* Frame nr must match */
168 if(d1->dimt!=d2->dimt) {
169 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
170 if(verbose>0) printf("different frame nr.\n");
171 return(3);
172 }
173
174 /* Compare */
175 statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OK);
176 for(int fi=0; fi<d1->dimt; fi++) {
177 if(floatMatch(d1->x[fi], d2->x[fi], test_abs)==1)
178 continue;
179 if(floatMatch(d1->x1[fi], d2->x1[fi], test_abs)==1)
180 continue;
181 if(floatMatch(d1->x2[fi], d2->x2[fi], test_abs)==1)
182 continue;
183 if(test_rel>0.0 &&
184 floatMatchRel(d1->x[fi], d2->x[fi], test_rel)==1 &&
185 floatMatchRel(d1->x1[fi], d2->x1[fi], test_rel)==1 &&
186 floatMatchRel(d1->x2[fi], d2->x2[fi], test_rel)==1)
187 continue;
188 if(verbose>0) {
189 printf("img1.x1[%d] := %g\n", fi, d1->x1[fi]);
190 printf("img2.x1[%d] := %g\n", fi, d2->x1[fi]);
191 printf("|diff| := %g\n", fabsf(d1->x1[fi]-d2->x1[fi]));
192 printf("img1.x2[%d] := %g\n", fi, d1->x2[fi]);
193 printf("img2.x2[%d] := %g\n", fi, d2->x2[fi]);
194 printf("|diff| := %g\n", fabsf(d1->x2[fi]-d2->x2[fi]));
195 printf("img1.x[%d] := %g\n", fi, d1->x[fi]);
196 printf("img2.x[%d] := %g\n", fi, d2->x[fi]);
197 printf("|diff| := %g\n", fabsf(d1->x[fi]-d2->x[fi]));
198 printf("diff_limit := %g\n", test_abs);
199 if(test_rel>0.0) printf("rel_diff_limit := %g\n", test_rel);
200 }
201 return(11);
202 }
203 return(0);
204}
205/*****************************************************************************/
206
207/*****************************************************************************/
int floatMatch(const float v1, const float v2, const float lim)
Definition floatutil.c:27
int floatMatchRel(const float v1, const float v2, const float lim)
Definition floatutil.c:54
int imgCompareMatrixSize(IMG *d1, IMG *d2)
Definition imagecomp.c:18
int imgCompareTimes(IMG *d1, IMG *d2, const float test_abs, const float test_rel, TPCSTATUS *status)
Definition imagecomp.c:144
int imgCompareUnit(IMG *d1, IMG *d2, TPCSTATUS *status)
Definition imagecomp.c:39
int imgCompareConc(IMG *d1, IMG *d2, const float test_abs, const float test_rel, TPCSTATUS *status)
Definition imagecomp.c:79
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
Definition tpcimage.h:82
unsigned short int dimx
Definition tpcimage.h:112
float * x1
Definition tpcimage.h:180
unit cunit
Definition tpcimage.h:203
float **** m
Definition tpcimage.h:161
float * x2
Definition tpcimage.h:182
unsigned short int dimt
Definition tpcimage.h:110
unsigned short int dimz
Definition tpcimage.h:116
unsigned short int dimy
Definition tpcimage.h:114
float * x
Definition tpcimage.h:184
unit tunit
Definition tpcimage.h:205
int verbose
Verbose level, used by statusPrint() etc.
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.
char * unitName(int unit_code)
Definition units.c:143
Header file for libtpcimage.