27 if(img1==NULL || img2==NULL)
return(1);
31 ret=
imgMatchMatrix(img1, img2, (
double)accuracy);
if(ret!=0)
return(400+ret);
59 for(pi=0; pi<img1->
dimz; pi++)
for(yi=0; yi<img1->
dimy; yi++)
60 for(xi=0; xi<img1->
dimx; xi++)
for(fi=0; fi<img1->
dimt; fi++) {
61 s=fabs(img1->
m[pi][yi][xi][fi]+img2->
m[pi][yi][xi][fi])/2.0;
62 if(accuracy==0.0 || s==0.0) {
63 if(img1->
m[pi][yi][xi][fi]!=img2->
m[pi][yi][xi][fi]){
64 fprintf(stderr,
"Mismatch in image matrix.\n");
68 if(fabs(img1->
m[pi][yi][xi][fi]-img2->
m[pi][yi][xi][fi])/s > (1.0-accuracy)) {
69 fprintf(stderr,
"Mismatch in image matrix.\n");
70 printf(
"img[%d][%d][%d][%d]: %g vs %g\n", pi, yi, xi, fi,
71 img1->
m[pi][yi][xi][fi], img2->
m[pi][yi][xi][fi]);
95 fprintf(stderr,
"In the header: Mismatching qform.\n");
99 fprintf(stderr,
"In the header: Mismatching sform.\n");
103 for(i=0; i<18; i++) {
105 if(fabs(f)>1.0E-05) {
106 fprintf(stderr,
"In the header: Mismatching transformation parameter.\n");
111 for(i=0; i<12; i++) {
112 f=img1->
mt[i]-img2->
mt[i];
113 if(fabs(f)>1.0E-05) {
114 fprintf(stderr,
"In the header: Mismatching matrix transformation.\n");
136 fprintf(stderr,
"In the header: Mismatching unit.\n");
144 fprintf(stderr,
"In the header: Mismatching calibration factor.\n");
149 fprintf(stderr,
"In the header: Mismatching zoom.\n");
153 fprintf(stderr,
"In the header: Mismatching radiopharmaceutical.\n");
157 fprintf(stderr,
"In the header: Mismatching isotope halflife.\n");
161 fprintf(stderr,
"In the header: One of the images is not corrected for decay.\n");
165 fprintf(stderr,
"In the header: Mismatching branching ratio.\n");
169 fprintf(stderr,
"In the header: Mismatching scan start times.\n");
174 fprintf(stderr,
"In the header: Mismatching orientation.\n");
178 fprintf(stderr,
"In the header: Mismatching axial FOV.\n");
182 fprintf(stderr,
"In the header: Mismatching transaxial FOV.\n");
186 fprintf(stderr,
"In the header: Mismatching sample distance.\n");
191 fprintf(stderr,
"In the header: Mismatching study number.\n");
195 fprintf(stderr,
"In the header: Mismatching user process code.\n");
199 fprintf(stderr,
"In the header: Mismatching study description.\n");
203 fprintf(stderr,
"In the header: Mismatching patient name.\n");
207 fprintf(stderr,
"In the header: Mismatching patient ID.\n");
214 fprintf(stderr,
"In the header: Mismatching image type.\n");
219 fprintf(stderr,
"In the header: Mismatching size (x-axis).\n");
223 fprintf(stderr,
"In the header: Mismatching size (y-axis).\n");
227 fprintf(stderr,
"In the header: Mismatching size (z-axis).\n");
231 fprintf(stderr,
"In the header: Mismatching x gap.\n");
235 fprintf(stderr,
"In the header: Mismatching y gap.\n");
239 fprintf(stderr,
"In the header: Mismatching z gap.\n");
244 fprintf(stderr,
"In the header: Mismatching resolution (x-axis).\n");
248 fprintf(stderr,
"In the header: Mismatching resolution (y-axis).\n");
252 fprintf(stderr,
"In the header: Mismatching resolution (z-axis).\n");
257 fprintf(stderr,
"In the header: Mismatching scanner.\n");
261 fprintf(stderr,
"In the header: Mismatching modality.\n");
265 fprintf(stderr,
"In the header: Mismatching data type.\n");
269 fprintf(stderr,
"In the header: Mismatching file format.\n");
273 fprintf(stderr,
"In the header: Mismatching in weights.\n");
292 if(img1->
dimt!=img2->
dimt)
return(1);
293 for(
int fi=0; fi<img1->
dimt; fi++) {
294 if(fabs(img1->
start[fi]-img2->
start[fi])>0.001)
return(11);
295 if(fabs(img1->
end[fi]-img2->
end[fi])>0.001)
return(12);
296 if(fabs(img1->
mid[fi]-img2->
mid[fi])>0.001)
return(13);
313 if(img1->
dimz!=img2->
dimz)
return(1);
314 for(
int zi=0; zi<img1->
dimz; zi++) {
346 float s, v, absmax=0.0, relmax=0.0;
349 if(absdiff!=NULL) absdiff->
x=absdiff->
y=absdiff->
z=absdiff->
t=0;
350 if(abs_max!=NULL) *abs_max=0;
351 if(reldiff!=NULL) reldiff->
x=reldiff->
y=reldiff->
z=reldiff->
t=0;
352 if(rel_max!=NULL) *rel_max=0;
355 if(img1==NULL || img2==NULL)
return 1;
356 if(img1->
dimx!=img2->
dimx)
return 2;
357 if(img1->
dimy!=img2->
dimy)
return 3;
358 if(img1->
dimz!=img2->
dimz)
return 4;
359 if(img1->
dimt!=img2->
dimt)
return 5;
363 for(zi=0; zi<img1->
dimz; zi++)
for(yi=0; yi<img1->
dimy; yi++)
364 for(xi=0; xi<img1->
dimx; xi++)
for(ti=0; ti<img1->
dimt; ti++) {
365 s=fabs(img1->
m[zi][yi][xi][ti]-img2->
m[zi][yi][xi][ti]);
368 if(absdiff!=NULL) {absdiff->
x=xi+1; absdiff->
y=yi+1; absdiff->
z=zi+1; absdiff->
t=ti+1;}
372 if(abs_max!=NULL) *abs_max=absmax;
379 float local_absmax=0.0;
380 for(zi=0; zi<img1->
dimz; zi++)
for(yi=0; yi<img1->
dimy; yi++)
381 for(xi=0; xi<img1->
dimx; xi++)
for(ti=0; ti<img1->
dimt; ti++) {
382 s=fabs(img1->
m[zi][yi][xi][ti]-img2->
m[zi][yi][xi][ti]);
383 v=0.5*fabs(img1->
m[zi][yi][xi][ti]+img2->
m[zi][yi][xi][ti]);
386 if(s>relmax && local_absmax==0.0) {
388 if(reldiff!=NULL) {reldiff->
x=xi+1; reldiff->
y=yi+1; reldiff->
z=zi+1; reldiff->
t=ti+1;}
393 if(reldiff!=NULL) {reldiff->
x=xi+1; reldiff->
y=yi+1; reldiff->
z=zi+1; reldiff->
t=ti+1;}
397 if(local_absmax>0.0) relmax=FLT_MAX;
399 if(rel_max!=NULL) *rel_max=relmax;
402 if(absmax>0.0 || relmax>0.0)
return 0;
else return -1;
420 if(ss!=NULL) *ss=0.0;
421 if(img1==NULL || img2==NULL)
return(1);
422 if(img1->
dimz!=img2->
dimz)
return(2);
423 if(img1->
dimy!=img2->
dimy)
return(3);
424 if(img1->
dimx!=img2->
dimx)
return(4);
425 if(img1->
dimt!=img2->
dimt)
return(5);
428 for(
int z=0; z<img1->
dimz; z++)
429 for(
int y=0; y<img1->
dimy; y++)
430 for(
int x=0; x<img1->
dimx; x++)
431 for(
int i=0; i<img1->
dimt; i++) {
432 double d=img1->
m[z][y][x][i]-img2->
m[z][y][x][i];
435 if(ss!=NULL) *ss=sumsqr;
453 if(d1==NULL || d2==NULL)
return(1);
int imgMatchPlanes(IMG *img1, IMG *img2)
int imgSS(IMG *img1, IMG *img2, double *ss)
int imgMatchMatrix(IMG *img1, IMG *img2, double accuracy)
int imgMatchHeader(IMG *img1, IMG *img2)
int imgMatchTransform(IMG *img1, IMG *img2)
int imgMaxDifference(IMG *img1, IMG *img2, VOXEL_4D *absdiff, float *abs_max, VOXEL_4D *reldiff, float *rel_max)
int imgMatchFrames(IMG *img1, IMG *img2)
int imgMatch(IMG *img1, IMG *img2, float accuracy)
int imgMatchMatrixSize(IMG *d1, IMG *d2)
Header file for libtpcimgio.
char studyDescription[32]
char radiopharmaceutical[32]
char studyNr[MAX_STUDYNR_LEN+1]