home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Libraries / grayimage / vimage.cc < prev    next >
Encoding:
Text File  |  1994-06-30  |  23.9 KB  |  597 lines  |  [TEXT/R*ch]

  1. xel_value(0);
  2.   assert( Test_image == 0 );
  3.  
  4.   cout << "Writing a pattern 0x" << hex(pattern) << "...\n";
  5.   for(i=0; i<Test_image.q_nrows(); i++)
  6.     for(j=0; j<Test_image.q_ncols(); j++)
  7.       Test_image(rowcol(i,j)) = pattern;
  8.  
  9.   verify_pixel_value(pattern);
  10.   assert( Test_image == pattern );
  11.   assert( Test_image >  0 && Test_image >= pattern );
  12.   assert( !(Test_image ==  0) && Test_image != 0 );
  13.   assert( Test_image > pattern-1 && Test_image >= pattern-1 );
  14.   assert( Test_image < pattern+1 && Test_image <= pattern+1 );
  15.   assert( Test_image <= pattern && !(Test_image < pattern) );
  16.   assert( Test_image >= pattern && !(Test_image > pattern) );
  17.  
  18.   cout << "Inverting the image, the pattern has to turn to " << 
  19.     hex(0xff - pattern) << "...\n";
  20.   Test_image.invert();
  21.   verify_pixel_value(0xff - pattern);
  22.  
  23.   cout << "Clearing the image ...\n";
  24.   Test_image.clear();
  25.   verify_pixel_value(0);
  26.   assert( Test_image < pattern && Test_image <= pattern );
  27.  
  28.   const int test_val = 0x7e;
  29.   cout << "Assigning the value " << hex(test_val) << " to all the pixels...\n";
  30.   Test_image = test_val;
  31.   verify_pixel_value(test_val);
  32.  
  33.   cout << "Adding three...\n";
  34.   Test_image += 3;
  35.   verify_pixel_value(test_val+3);
  36.   assure( Test_image > 0, "Negative pixel unexpected");
  37.  
  38.   cout << "Subtracting " << 2*test_val << "...\n";
  39.   Test_image -= 2*test_val;
  40.   verify_pixel_value(test_val+3-2*test_val);
  41.   assure( Test_image < 0, "Non-Negative pixel unexpected");
  42.  
  43.   cout << "Subtracting " << -2*test_val+3 << "...\n";
  44.   Test_image -= -2*test_val+3;
  45.   verify_pixel_value(test_val);
  46.  
  47.   cout << "Set two lowest bits\n";
  48.   Test_image |= 0x03;
  49.   verify_pixel_value(test_val | 0x03);
  50.  
  51.   cout << "Reset two lowest bits\n";
  52.   Test_image &= 0xff - 0x03;
  53.   verify_pixel_value(test_val & (0xff - 0x03));
  54.  
  55.   cout << "Set the 2nd bit with XOR\n";
  56.   Test_image ^= 0x02; 
  57.   verify_pixel_value(test_val);
  58.  
  59.   cout << "Multiply by 2\n";
  60.   Test_image *= 2; 
  61.   verify_pixel_value(2*test_val);
  62.  
  63.   cout << "Multiply by 2 once more by shifting to the left\n";
  64.   Test_image <<= 1; 
  65.   verify_pixel_value(4*test_val);
  66.  
  67.   cout << "Divide by 4 by shifting to the right\n";
  68.   Test_image >>= 2; 
  69.   verify_pixel_value(test_val);
  70.  
  71.   cout << "If image >=0, then abs(image) should coincide with itself\n";
  72.   assert( Test_image >= 0 );
  73.   Test_image.abs();
  74.   verify_pixel_value(test_val);
  75.  
  76.   cout << "Assign image = -test_val and test image.abs()\n";
  77.   Test_image -= 2*test_val;
  78.   assert( Test_image < 0 );
  79.   Test_image.abs();
  80.   verify_pixel_value(test_val);
  81.   
  82.   cout << "Assign image = -test_val and test image.apply(abs)\n";
  83.   Test_image -= 2*test_val;
  84.   assert( Test_image < 0 );
  85.   Test_image.apply(::abs);
  86.   verify_pixel_value(test_val);
  87.  
  88.   cout << "Assign image = -test_val and put down all negative pixels\n";
  89.   Test_image -= 2*test_val;
  90.   assert( Test_image < 0 );
  91.   Test_image.clip_to_intensity_range();
  92.   verify_pixel_value(0);
  93.  
  94.   cout << "Assign image = max_val+test_val and clip to the intensity region\n";
  95.   Test_image = test_val;
  96.   Test_image.clip_to_intensity_range();
  97.   verify_pixel_value(test_val);
  98.   Test_image += (1<<Test_image.q_depth())-1;
  99.   Test_image.clip_to_intensity_range();
  100.   verify_pixel_value((1<<Test_image.q_depth())-1);
  101.  
  102.   cout << "\nDone\n\n";
  103. }
  104.  
  105. static void test_image_op()
  106. {
  107.   const int pattern = 144;
  108.  
  109.   cout << "\n\nTest binary image operations and comparisons\n";
  110.   cout << "Pattern value being used " << pattern <<
  111.                             " (0x" << hex(pattern) << ")\n";
  112.  
  113.   cout << "Allocation with assignment\n";
  114.   Test_image = pattern;
  115.   IMAGE im2 = Test_image; im2 = Test_image;
  116.   assure(Test_image == im2, "Non-identical images");
  117.  
  118.   cout << "Assignment of one image to the other\n";
  119.   im2 += pattern;
  120.   Test_image = im2;
  121.   assure(Test_image==im2, "Non-identical images");
  122.   verify_pixel_value(2*pattern);
  123.  
  124.   cout << "Subtraction of two images\n";
  125.   im2 = pattern;
  126.   Test_image -= im2;
  127.   assure(Test_image==im2, "Non-identical images");
  128.   verify_pixel_value(pattern);
  129.   assert(Test_image == pattern);
  130.   
  131.   cout << "Addition of images\n";
  132.   Test_image += im2;
  133.   assure(!(Test_image==im2), "Identical images unexpected");
  134.   verify_pixel_value(2*pattern);
  135.   
  136.   cout << "Addition of images through add() function\n";
  137.   add(Test_image,2,im2);
  138.   assure(!(Test_image==im2), "Identical images unexpected");
  139.   verify_pixel_value(4*pattern);
  140.   
  141.   cout << "Subtraction of images through add() function\n";
  142.   add(Test_image,-3,im2);
  143.   assure(Test_image==im2, "Non-identical images");
  144.   verify_pixel_value(pattern);
  145.  
  146.   cout << "Double only one pixel,(5,6), and perform operations to triple it\n";
  147.   Test_image(5,6) *= 2;
  148.   Test_image += im2;
  149.   add(Test_image,-3,im2);
  150.   Test_image += Test_image;
  151.   add(Test_image,3,im2);
  152.   compare(Test_image,im2,"Image with one pixel different and original");
  153.  
  154.   cout << "Subtracting the image from itself\n";
  155.   Test_image -= Test_image;
  156.   verify_pixel_value(0);
  157.  
  158.   cout << "Set two lower bits\n";
  159.   Test_image = pattern; im2 = 0x03;
  160.   Test_image |= im2;
  161.   verify_pixel_value(pattern | 0x03);
  162.  
  163.   cout << "Reset two lowest bits\n";
  164.   im2.invert();
  165.   Test_image &= im2;
  166.   verify_pixel_value(pattern & (0xff - 0x03));
  167.  
  168.   cout << "Set the 2nd bit with XOR\n";
  169.   im2 = 0x02;
  170.   Test_image ^= im2;
  171.   verify_pixel_value(pattern | 0x02);
  172.  
  173.   cout << "OR with 0x13 followed by AND with 0x6d for non-uniform image\n";
  174.   Test_image = pattern; Test_image(4,5) += 5;
  175.   im2 = 0x13; Test_image |= im2; im2.invert(); Test_image &= im2;
  176.   im2 = pattern; im2(4,5) += 5;
  177.   im2 |= 0x13; im2 &= ~(0x13);
  178.   assure(Test_image == im2,"Pixel-by-pixel and image-by-image produced"
  179.      "different results");
  180.   
  181.   cout << "XORing the image with itself\n";
  182.   Test_image ^= Test_image;
  183.   verify_pixel_value(0);
  184.  
  185.   cout << "Add two images through shift_clip_add\n";
  186.   Test_image = pattern;
  187.   Test_image.shift_clip_add(rowcol(0,0),1,Test_image);
  188.   verify_pixel_value(2*pattern);
  189.   im2 = pattern;
  190.   Test_image.shift_clip_add(rowcol(0,0),-2,im2);
  191.   verify_pixel_value(0);
  192.  
  193.   {
  194.     cout << "Change a single pixel through shift_clip_add\n";
  195.     Test_image = 2*pattern;
  196.     im2 = pattern;
  197.     rowcol rightbottom(Test_image.q_nrows()-1,Test_image.q_ncols()-1);
  198.     Test_image(rightbottom) += pattern;           // Increment a pixel
  199.     assert( !(Test_image == 2*pattern) && !(Test_image != 2*pattern) );
  200.     Test_image.shift_clip_add(rightbottom,-1,im2); // and decrement it back
  201.     verify_pixel_value(2*pattern);           // in the other way
  202.     assert( Test_image == 2*pattern );
  203.  
  204.   {
  205.     Test_image(0,0) -= pattern;
  206.     assert( !(Test_image == 2*pattern) && !(Test_image != 2*pattern) );
  207.     rowcol pos = rightbottom * (-1);
  208.     Test_image.shift_clip_add(pos,1,im2);
  209.     // Test_image.shift_clip_add(rightbottom * (-1),1,im2);
  210.     verify_pixel_value(2*pattern);
  211.     assert( Test_image == 2*pattern );
  212.   }
  213.   }
  214.   
  215.   {
  216.     cout << "Change a bottom right quadrant through shift_clip_add\n";
  217.     Test_image = 2*pattern;
  218.     im2 = pattern;
  219.     rowcol rightbottom(Test_image.q_nrows()-1,Test_image.q_ncols()-1);
  220.     rowcol center(Test_image.q_nrows()/2,Test_image.q_ncols()/2);
  221.     Test_image.rectangle(center,rightbottom) -= 2*pattern; // Decrement a block
  222.     assert( !(Test_image == 2*pattern) && !(Test_image != 2*pattern) );
  223.     Test_image.shift_clip_add(center,2,im2);     // and increment it back
  224.     verify_pixel_value(2*pattern);           // in the other way
  225.     assert( Test_image == 2*pattern );
  226.   }
  227.  
  228.   {
  229.     cout << "Change a part of the image through shift_clip_add\n";
  230.     Test_image = 3*pattern;
  231.     rowcol pos1(4,5);
  232.     rowcol pos2(Test_image.q_nrows()-2,Test_image.q_ncols()-3);
  233.     IMAGE im3 = Test_image.rectangle(pos1,pos2);
  234.     Test_image.rectangle(pos1,pos2) -= 3*pattern; // Decrement a block
  235.     assert( !(Test_image == 3*pattern) && !(Test_image != 3*pattern) );
  236.     assert( im3 == 3*pattern );
  237.     Test_image.shift_clip_add(pos1,1,im3);        // and increment it back
  238.     verify_pixel_value(3*pattern);           // in the other way
  239.     assert( Test_image == 3*pattern );
  240.   }
  241.  
  242.   cout << "\nDone\n\n";
  243. }
  244.  
  245. /*
  246.  *------------------------------------------------------------------------
  247.  *        Testing norm and scalar product calculations
  248.  */
  249.  
  250. static void test_scalar_product()
  251. {
  252.   const int pattern = 145;
  253.  
  254.   cout << "\n\nTest the computation of the scalar product of two images\n";
  255.   cout << "Pattern value being used " << pattern;
  256.  
  257.   int dim = (max(Test_image.q_nrows(),Test_image.q_ncols()) >> 1) << 1;
  258.   IMAGE imt(dim,dim,8), ims(dim,dim,8);
  259.  
  260.   cout << "\nSquare image of size " << dim << " is being tested";
  261.   cout << "\nTesting by making the Haar (+ - - +) function and checking\n" 
  262.           "its orthogonality with other Haar functions";
  263.  
  264.                 // Make the Haar (+ - - +) function
  265.   ims.square_of(dim/2,rowcol(0,0))         = pattern;
  266.   ims.square_of(dim/2,rowcol(0,dim/2))         = -pattern;
  267.   ims.square_of(dim/2,rowcol(dim/2,0))         = -pattern;
  268.   ims.square_of(dim/2,rowcol(dim/2,dim/2))     = pattern;
  269.   assert( ims != 0 && !(ims == 0) && !(ims == pattern) && !(ims != pattern) );
  270.   assert( !(ims >= pattern) && ims >= -pattern && ims <= pattern );
  271.   assert( !(ims > 0) && !(ims < 0) );
  272.     
  273.  
  274.   cout << "\nsum over ims " << sum_over(ims.square_of(dim,rowcol(0,0)));
  275.  
  276.   imt = pattern;
  277.   cout << "\n Scalar product with Haar (+ + + +) function is " << ims * imt;
  278.  
  279.   imt.square_of(dim/2,rowcol(0,0))         = -pattern;
  280.   imt.square_of(dim/2,rowcol(0,dim/2))         = -pattern;
  281.   imt.square_of(dim/2,rowcol(dim/2,0))         = pattern;
  282.   imt.square_of(dim/2,rowcol(dim/2,dim/2))     = pattern;
  283.   cout << "\n Scalar product with Haar (- - + +) function is " << imt * ims;
  284.  
  285.   imt.square_of(dim/2,rowcol(0,0))         = -pattern;
  286.   imt.square_of(dim/2,rowcol(0,dim/2))         = pattern;
  287.   imt.square_of(dim/2,rowcol(dim/2,0))         = -pattern;
  288.   imt.square_of(dim/2,rowcol(dim/2,dim/2))     = pattern;
  289.   cout << "\n Scalar product with Haar (- + - +) function is " << ims * imt;
  290.  
  291.   imt = ims;
  292.   cout << "\n Scalar product with Haar (+ - - +) function is " << imt * ims;
  293.   cout << "\n Theoretical value                     " 
  294.        << sqr(pattern * dim);
  295.   assure( imt * ims == sqr(pattern * dim), "There is discrepancy!" );
  296.  
  297.   cout << "\nDone\n\n";
  298. }
  299.  
  300. static void test_image_norms(void)
  301. {
  302.   const int pattern = 154;
  303.  
  304.   cout << "\n\nTest image norm computations\n";
  305.  
  306.   Test_image.clear();
  307.  
  308.   cout << "\nInitializing the image with the pattern " << pattern << "...\n";
  309.   Test_image = pattern;
  310.  
  311.   cout << "\tChecking out the 1. image norm, which should be "
  312.        << pattern * (double)Test_image.q_npixels() << "\n";
  313.   assert( Test_image.norm_1() == pattern * (double)Test_image.q_npixels() );
  314.   cout << "\tChecking out the 2. image norm, which should be "
  315.        << pattern * pattern * (double)Test_image.q_npixels() << "\n";
  316.   assert( Test_image.norm_2_sqr() ==
  317.       sqr(pattern) * (double)Test_image.q_npixels() );
  318.   cout << "\tChecking out the 2. image norm is equal to the scalar product\n"
  319.           "\t\tof the image with itself\n";
  320.   assert( Test_image.norm_2_sqr() == Test_image * Test_image );
  321.   cout << "\tChecking out the inf image norm is equal to the pattern itself\n";
  322.   assert( Test_image.norm_inf() == pattern );
  323.  
  324.   cout << "\nInitializing the image with the pattern " << pattern << 
  325.           "\n with a quater of it being set to " << -2*pattern << "\n";
  326.   Test_image = pattern;
  327.   int size = min(Test_image.q_ncols(),Test_image.q_nrows())/2;
  328.   Test_image.square_of(size,rowcol(0,0)) = -2*pattern;
  329.   assert( !(Test_image == pattern) && !(Test_image != pattern) );
  330.   assert( Test_image <= pattern && Test_image >= -2*pattern );
  331.   assert( !(Test_image > 0) && !(Test_image < 0) && Test_image != 0 );
  332.  
  333.   cout << "\tChecking out the 1. image norm\n";
  334.   assert( Test_image.norm_1() == pattern * (double)Test_image.q_npixels() 
  335.       + pattern * size * size );
  336.   {
  337.     IMAGE im(Test_image);
  338.     im = Test_image;
  339.     im.abs();
  340.     assert( im.norm_1() == Test_image.norm_1() );
  341.   }
  342.  
  343.   cout << "\tChecking out the 2. image norm\n";
  344.   assert( Test_image.norm_2_sqr() ==
  345.       sqr(pattern) * (double)Test_image.q_npixels() + 
  346.       3 * sqr(pattern) * sqr(size) );
  347.   {
  348. //    IMAGE im(Test_image);
  349. //    im = Test_image;
  350. //    im.apply((USER_F *)::sqr);
  351. //    assert( sum_over((Rectangle)im) == Test_image.norm_2_sqr() );
  352.   }
  353.   cout << "\tChecking out the 2. image norm is equal to the scalar product\n"
  354.           "\t\tof the image with itself\n";
  355.   assert( Test_image.norm_2_sqr() == Test_image * Test_image );
  356.   cout << "\tChecking out the inf image norm\n";
  357.   assert( Test_image.norm_inf() == 2*pattern );
  358.  
  359.   cout << "\nChecking out that the image is equal to itself\n"
  360.           "(according to norms)\n";
  361.   assert( norm_1(Test_image,Test_image) == 0 );
  362.   assert( norm_2_sqr(Test_image,Test_image) == 0 );
  363.   assert( norm_inf(Test_image,Test_image) == 0 );
  364.   
  365.   cout << "\nCheck the difference between the test images set as above"
  366.           "\nand the image with the uniform pattern\n";
  367.   IMAGE im1(Test_image);
  368.   im1 = pattern;
  369.  
  370.   cout << "\tVerify the identity ||im1-im2|| = ||im2-im1||\n";
  371.   assert( norm_1(Test_image,im1) == norm_1(im1,Test_image) );
  372.   assert( norm_2_sqr(Test_image,im1) == norm_2_sqr(im1,Test_image) );
  373.   assert( norm_inf(Test_image,im1) == norm_inf(im1,Test_image) );
  374.  
  375.   cout << "\tVerify the norm values\n";
  376.   assert( norm_1(Test_image,im1) == 3 * pattern * sqr(size) );
  377.   assert( norm_2_sqr(Test_image,im1) == sqr(3 * pattern) * sqr(size) );
  378.   assert( norm_inf(Test_image,im1) == 3 * pattern );
  379.   
  380.   cout << "\nDone\n\n";
  381. }
  382.  
  383.                 // Check out min/max finding operations
  384. static void test_image_extrema(void)
  385. {
  386.   const int pattern = 154;
  387.  
  388.   cout << "\n\nTest finding extremum pixel values and image normalization\n";
  389.  
  390.   {
  391.     cout << "\n\tExtrema of the zero image\n";
  392.     Test_image.clear();
  393.     Extrema extr(Test_image);
  394.     assert( extr.min() == 0 && extr.max() == 0 );
  395.   }
  396.  
  397.   {
  398.     cout << "\tInitializing the image with the pattern " << pattern << "\n";
  399.     Test_image = pattern;
  400.     Extrema extr(Test_image);
  401.     assert( extr.min() == pattern && extr.max() == pattern );
  402.   }
  403.  
  404.   {
  405.     cout << "\tSetting pixel (1,2) to 0\n";
  406.     Test_image(1,2) = 0;
  407.     Extrema extr(Test_image);
  408.     assert( extr.min() == 0 && extr.max() == pattern &&
  409.         extr.min_pixel.row() == 1 && extr.min_pixel.col() == 2 );
  410.     assert( Test_image >= extr.min() && Test_image <= extr.max() );
  411.   }
  412.  
  413.   {
  414.     cout << "\tSetting pixel (2,1) to 2*pattern = " << 2*pattern << "\n";
  415.     Test_image(2,1) = 2*pattern;
  416.     Extrema extr(Test_image);
  417.     assert( extr.min() == 0 && extr.max() == 2*pattern &&
  418.         extr.min_pixel.row() == 1 && extr.min_pixel.col() == 2 &&
  419.         extr.max_pixel.row() == 2 && extr.max_pixel.col() == 1 );
  420.     assert( Test_image >= extr.min() && Test_image <= extr.max() );
  421.   }
  422.  
  423.   {
  424.     cout << "\tOffsetting by " << pattern << "\n";
  425.     Test_image -= pattern;
  426.     Extrema extr(Test_image);
  427.     assert( extr.min() == -pattern && extr.max() == pattern &&
  428.         extr.min_pixel.row() == 1 && extr.min_pixel.col() == 2 &&
  429.         extr.max_pixel.row() == 2 && extr.max_pixel.col() == 1 );
  430.     assert( Test_image >= extr.min() && Test_image <= extr.max() );
  431.   }
  432.  
  433.   {
  434.     cout << "\tOffsetting by " << 2*pattern << "\n";
  435.     Test_image -= 2*pattern;
  436.     Extrema extr(Test_image);
  437.     assert( extr.min() == -3*pattern && extr.max() == -pattern &&
  438.         extr.min_pixel.row() == 1 && extr.min_pixel.col() == 2 &&
  439.         extr.max_pixel.row() == 2 && extr.max_pixel.col() == 1 );
  440.     assert( Test_image >= extr.min() && Test_image <= extr.max() );
  441.   }
  442.  
  443.   cout << "\tNormalization ... \n";
  444.   Test_image = pattern;
  445.   Test_image.square_of(4,rowcol(2,1)) = -3*pattern;
  446.   Test_image.normalize_for_display();
  447.   Extrema extr(Test_image);
  448.   assert( extr.min() == 0 && extr.max() >= (1<<Test_image.q_depth())-2 );
  449.   assert( Test_image >= extr.min() && Test_image <= extr.max() );
  450.  
  451.   cout << "\nDone\n\n";
  452.  
  453. }
  454.  
  455.                 // Test the histogram equalization
  456. static void test_equalization(void)
  457. {
  458.   cout << "\n\nTest the histogram equalization\n";
  459.  
  460.   {
  461.     cout << "\tTest equalizing 16x16x8 full-gray scale image\n";
  462.     IMAGE full_gray(16,16,8);
  463.     register int i,j;
  464.     for(i=0; i<16; i++)
  465.       for(j=0; j<16; j++)
  466.     full_gray(i,j) = (i<<4) | j;
  467.     Extrema full_gray_extr(full_gray);
  468.     assert( full_gray_extr.min() == 0 && full_gray_extr.max() == 255 );
  469.  
  470.     full_gray.equalize(128);
  471.                     // After the equalization, the
  472.                     // image should have (almost) the
  473.                     // same span but have only even
  474.                     // pixel values
  475.     Extrema full_gray_extr_eq(full_gray);
  476.     assert( full_gray_extr_eq.min() == 0 && full_gray_extr_eq.max() == 254 );
  477.     for(i=0; i<16; i++)
  478.       for(j=0; j<16; j++)
  479.     assert( (full_gray(i,j) & 1) == 0 );
  480.   }
  481.  
  482.   {
  483.     cout << "\tAn image with a flat histogram should stay this way\n";
  484.     IMAGE test_im(16,16,8);
  485.     test_im.rectangle(rowcol(0,0),rowcol(15,3)) = 0;
  486.     test_im.rectangle(rowcol(0,4),rowcol(15,7)) = 80;
  487.     test_im.rectangle(rowcol(0,8),rowcol(15,11)) = 160;
  488.     test_im.rectangle(rowcol(0,12),rowcol(15,15)) = 255;
  489.  
  490.     test_im.equalize(128);
  491.  
  492.     IMAGE test_im_ethalon(test_im);
  493.     test_im_ethalon.rectangle(rowcol(0,0),rowcol(15,3)) = 31;
  494.     test_im_ethalon.rectangle(rowcol(0,4),rowcol(15,7)) = 94;
  495.     test_im_ethalon.rectangle(rowcol(0,8),rowcol(15,11)) = 158;
  496.     test_im_ethalon.rectangle(rowcol(0,12),rowcol(15,15)) = 222;
  497.  
  498.     assert( test_im == test_im_ethalon );
  499.   }
  500.  
  501. #if 0
  502.   {
  503.     cout << "\tTest equalizing of uneven histogram\n";
  504.     IMAGE test_im(16,16,4);
  505.     test_im = 8;            // Make a stripy image
  506.     register int i,j;            // with very uneven histogram
  507.     for(i=0; i<8; i++)            // (large peak at value 8)
  508.       for(j=0; j<16; j++)
  509.     test_im(i,j) = j;
  510.  
  511.     test_im.print("before");
  512.     test_im.equalize(16);
  513.     test_im.print("after");
  514.   }
  515. #endif
  516.  
  517.   cout << "\nDone\n\n";
  518. }
  519.  
  520.  
  521.                 // Test expand/shrink operations
  522. static void test_expand_shrink()
  523. {
  524.   const int pattern = 154;
  525.  
  526.   cout << "\n\nTest shrink/expand image operations\n";
  527.  
  528.   {
  529.     cout << "\tExpansion/shrinking of the uniform image\n";
  530.     Test_image = pattern;
  531.     IMAGE blown_out(IMAGE::Expand,Test_image);
  532.     assert( blown_out.q_nrows() == 2*Test_image.q_nrows() );
  533.     assert( blown_out.q_ncols() == 2*Test_image.q_ncols() );
  534.     assert( blown_out.q_depth() == Test_image.q_depth() );
  535.     assert( blown_out == pattern );
  536.     IMAGE blown_shrunk(IMAGE::Shrink,blown_out);
  537.     assert( blown_shrunk == Test_image );
  538.   }
  539.  
  540.   {
  541.     cout << "\tExpansion of the uniform image with a small stain\n";
  542.     Test_image = pattern;
  543.     Test_image(0,0) = 1;
  544.     Test_image(1,1) = 0;
  545.     IMAGE blown_out(IMAGE::Expand,Test_image);
  546.     assert( blown_out(1,1) == 1 );
  547.     assert( blown_out(3,3) == 0 );
  548.     IMAGE blown_shrunk(IMAGE::Shrink,blown_out);
  549.     assert( blown_shrunk == Test_image );
  550.     blown_out.square_of(2,rowcol(0,0)) += pattern - 1;
  551.     blown_out.square_of(2,rowcol(2,2)) += pattern;
  552.     assert( blown_out == pattern );
  553.   }
  554.   {
  555.     cout << "\tShrinking the uniform image with small stains\n";
  556.     Test_image = pattern;
  557.     Test_image.square_of(2,rowcol(0,0)) = 1; Test_image(0,0) = 0;
  558.     Test_image.square_of(2,rowcol(2,0)) = 5; Test_image(3,1) = 0;
  559.     Test_image.square_of(2,rowcol(0,2)) = 0; Test_image(0,2) = 1;
  560.     Test_image.square_of(2,rowcol(0,4)) = 0; Test_image(1,5) = 7;
  561.     Test_image.square_of(2,rowcol(2,2)) = 1; 
  562.     Test_image(2,2) = 0; Test_image(3,3) = 0;
  563.  
  564.     IMAGE shrunk(IMAGE::Shrink,Test_image);
  565.     assert( shrunk(0,0) == 1 );
  566.     assert( shrunk(0,1) == 0 );
  567.     shrunk(0,0) += pattern - 1;
  568.     shrunk(1,0) += pattern - 4;
  569.     shrunk(0,1) += pattern;
  570.     shrunk(0,2) += pattern - 2;
  571.     shrunk(1,1) += pattern - 1;
  572.     assert( shrunk == pattern );
  573.   }
  574.   cout << "\nDone\n";
  575. }
  576.  
  577. /*
  578.  *------------------------------------------------------------------------
  579.  *            The testing routing module
  580.  */
  581.  
  582. main()
  583. {
  584.   test_primitive();
  585.   test_rowcol();
  586.   test_pixel_op();
  587.   test_image_op();
  588.  
  589.   test_scalar_product();
  590.   test_image_norms();
  591.   test_image_extrema();
  592.  
  593.   test_equalization();
  594.   test_expand_shrink();
  595. }
  596.  
  597.