TPCCLIB
Loading...
Searching...
No Matches
imagecomp.c File Reference

Comparison of IMG structure data. More...

#include "tpcclibConfig.h"
#include "tpcimage.h"

Go to the source code of this file.

Functions

int imgCompareMatrixSize (IMG *d1, IMG *d2)
int imgCompareUnit (IMG *d1, IMG *d2, TPCSTATUS *status)
int imgCompareConc (IMG *d1, IMG *d2, const float test_abs, const float test_rel, TPCSTATUS *status)
int imgCompareTimes (IMG *d1, IMG *d2, const float test_abs, const float test_rel, TPCSTATUS *status)

Detailed Description

Comparison of IMG structure data.

Author
Vesa Oikonen

Definition in file imagecomp.c.

Function Documentation

◆ imgCompareConc()

int imgCompareConc ( IMG * d1,
IMG * d2,
const float test_abs,
const float test_rel,
TPCSTATUS * status )

Check whether IMG pixel concentrations are the same. Note that units are ignored here.

If either absolute or relative difference is below the limit, the test is reported as passed.

See also
tacCompareConc, imgCompareUnit, imgCompareTimes.
Returns
0 in case of match, and >0 if no match or error.
Author
Vesa Oikonen
Parameters
d1Pointer to IMG structure.
d2Pointer to IMG structure.
test_absLimit for accepted absolute difference; obligatory.
test_relOptional limit for accepted relative difference |2*(x1-x2)/(x1+x2)| ; set to negative value to not test this; in case of zero mean, this test is assumed to fail, but test for absolute difference may still pass.
statusPointer to status data; enter NULL if not needed.

Definition at line 79 of file imagecomp.c.

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}
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
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
Definition statusmsg.c:142
unsigned short int dimx
Definition tpcimage.h:112
float **** m
Definition tpcimage.h:161
unsigned short int dimt
Definition tpcimage.h:110
unsigned short int dimz
Definition tpcimage.h:116
unsigned short int dimy
Definition tpcimage.h:114
int verbose
Verbose level, used by statusPrint() etc.
@ TPCERROR_OK
No error.
@ TPCERROR_NO_DATA
File contains no data.

◆ imgCompareMatrixSize()

int imgCompareMatrixSize ( IMG * d1,
IMG * d2 )

Check whether two IMG data have the same matrix (x,y,z) size.

Returns
0 in case of match, 1 otherwise.
See also
imgCompareConc, imgCompareTimes
Author
Vesa Oikonen
Parameters
d1Pointer to IMG structure.
d2Pointer to IMG structure.

Definition at line 18 of file imagecomp.c.

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}

◆ imgCompareTimes()

int imgCompareTimes ( IMG * d1,
IMG * d2,
const float test_abs,
const float test_rel,
TPCSTATUS * status )

Check whether IMG frame times (x values) are the same. Note that units are ignored here.

If either absolute or relative difference is below the limit, the test is reported as passed.

See also
tacCompareTimes, imgCompareConc, imgCompareUnit, tacimgXMatch.
Returns
0 in case of match, and >0 if no match or error.
Author
Vesa Oikonen
Parameters
d1Pointer to IMG structure.
d2Pointer to IMG structure.
test_absLimit for accepted absolute difference.
test_relOptional limit for accepted relative difference |2*(x1-x2)/(x1+x2)| ; set to negative value to not test this; in case of zero mean, this test is assumed to fail, but test for absolute difference may still pass.
statusPointer to status data; enter NULL if not needed.

Definition at line 144 of file imagecomp.c.

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}
float * x1
Definition tpcimage.h:180
float * x2
Definition tpcimage.h:182
float * x
Definition tpcimage.h:184

◆ imgCompareUnit()

int imgCompareUnit ( IMG * d1,
IMG * d2,
TPCSTATUS * status )

Check whether time and concentration units are the same in two IMG data.

Returns
0 in case of match, 1 if y (concentration) unit is not matching, 2 if x (time) unit is not matching, and 3 if neither is matching.
See also
tacCompareUnit, imgCompareConc, imgCompareTimes
Author
Vesa Oikonen
Parameters
d1Pointer to IMG structure.
d2Pointer to IMG structure.
statusPointer to status data; enter NULL if not needed

Definition at line 39 of file imagecomp.c.

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}
unit cunit
Definition tpcimage.h:203
unit tunit
Definition tpcimage.h:205
char * unitName(int unit_code)
Definition units.c:143