1 #include "mrilib.h"
2
main(int argc,char * argv[])3 int main( int argc , char *argv[] )
4 {
5 MRI_IMAGE *aim, *bim ; MRI_IMARR *aar, *bar ;
6 int iopt=1, do_all=0, nima,nimb, ii ;
7
8 if( argc < 3 || strcasecmp(argv[1],"-help") == 0 ){
9 printf(
10 "Usage: images_equal [-all] fileA fileB\n"
11 "\n"
12 "* Simple program to test if 2 2D images are identical.\n"
13 "* Exit status is 1 if they are equal, and 0 if they are not.\n"
14 "* If either image cannot be read, then exit status also 0.\n"
15 "* If the '-all' option is used, then all the images in the files\n"
16 " are compared, and all must be equal for the exit status to be 1.\n"
17 "* If '-all' is NOT given, only the first image in each file is\n"
18 " compared.\n"
19 "* This program is meant for use in scripts that deal with DICOM\n"
20 " servers that sometimes deal out multiple copies of the same\n"
21 " image in different filenames :-(\n"
22 "* Also see program uniq_images, which works on multiple inputs.\n"
23 "* Author: Zhark the Comparator, October 2015.\n"
24 ) ;
25 exit(0) ;
26 }
27
28 mainENTRY("images_equal") ; machdep() ;
29
30 if( strcasecmp(argv[iopt],"-all") == 0 ){
31 do_all = 1 ; iopt++ ;
32 }
33
34 if( iopt+2 > argc ){
35 ERROR_message("images_equal: Need 2 filenames, but don't have them!") ;
36 exit(0) ;
37 }
38
39 if( strcmp(argv[iopt],argv[iopt+1]) == 0 ) return 1 ; /* equal strings! */
40
41 /* read input images */
42
43 aar = mri_read_file(argv[iopt++]) ; if( aar == NULL ) exit(0) ;
44 aim = IMARR_SUBIM(aar,0) ;
45
46 bar = mri_read_file(argv[iopt++]) ; if( bar == NULL ) exit(0) ;
47 bim = IMARR_SUBIM(bar,0) ;
48
49 nima = (do_all) ? IMARR_COUNT(aar) : 1 ;
50 nimb = (do_all) ? IMARR_COUNT(bar) : 1 ;
51
52 if( nima != nimb ) exit(0) ;
53
54 for( ii=0 ; ii < nima ; ii++ ){
55 if( mri_equal( IMARR_SUBIM(aar,ii) , IMARR_SUBIM(bar,ii) ) == 0 ) exit(0);
56 }
57
58 exit(1) ;
59 }
60