home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 9 / CD_ASCQ_09_1193.iso / news / 4441 / yuvpak / wdyusual.c < prev    next >
C/C++ Source or Header  |  1993-01-30  |  6KB  |  138 lines

  1. /**************************************************************************/
  2. /*                                                                        */
  3. /*                         Usual Classification 1.0                       */
  4. /*                                                                        */
  5. /**************************************************************************/
  6. long int usual (unsigned char image[max_patch][max_patch], int size)
  7. {
  8. char rmsstr[13];
  9. int mag, max, min, class, class1, subclass, rx, ry, x, y, i, j;
  10. long int q[2][2], sumof[4], horizontal, vertical;
  11. unsigned char temp[size][size];
  12. struct max_t {
  13.     int rx;
  14.     int ry;
  15.     } four, three, two, one;
  16.  
  17. struct class_t {
  18.     int c;
  19.     int m;
  20.     } C[4322];
  21.  
  22.                 C[4321].c = C[4123].c = C[3412].c = C[3214].c =
  23.                 C[2341].c = C[2143].c = C[1432].c = C[1234].c = 1;
  24.  
  25.                 C[4312].c = C[4213].c = C[3421].c = C[3124].c =
  26.                 C[1342].c = C[1243].c = C[2431].c = C[2134].c = 2;
  27.  
  28.                 C[4132].c = C[4231].c = C[3241].c = C[3142].c =
  29.                 C[2413].c = C[2314].c = C[1423].c = C[1324].c = 3;
  30.  
  31.  
  32.                 C[4321].m = 0; C[4123].m = 5; C[3412].m = 4; C[3214].m = 3;
  33.                 C[2341].m = 7; C[2143].m = 2; C[1432].m = 1; C[1234].m = 6;
  34.  
  35.                 C[4312].m = 0; C[4213].m = 5; C[3421].m = 4; C[3124].m = 1;
  36.                 C[1342].m = 7; C[1243].m = 2; C[2431].m = 1; C[2134].m = 5;
  37.  
  38.                 C[4132].m = 5; C[4231].m = 0; C[3241].m = 5; C[3142].m = 2;
  39.                 C[2413].m = 4; C[2314].m = 3; C[1423].m = 1; C[1324].m = 6;
  40.  
  41.                 for (ry = 0; ry < size; ry +=size/2)
  42.                 for (rx = 0; rx < size; rx +=size/2) {
  43.                     q[ry/(size/2)][rx/(size/2)] = 0;
  44.                     for (y = ry; y < ry + size/2; y++)
  45.                     for (x = rx; x < rx + size/2; x++)
  46.                         q[ry/(size/2)][rx/(size/2)]+=image[y][x];
  47.                     }
  48.                 mag = -1;
  49.                 for (ry = 0; ry < 2; ry++)
  50.                 for (rx = 0; rx < 2; rx++)
  51.                     if (q[ry][rx] > mag) {
  52.                         mag = q[ry][rx];
  53.                         four.rx = rx; four.ry = ry;
  54.                         }
  55.                 q[four.ry][four.rx] = -2;
  56.                 mag = -1;
  57.                 for (ry = 0; ry < 2; ry++)
  58.                 for (rx = 0; rx < 2; rx++)
  59.                         if (q[ry][rx] > mag) {
  60.                             mag = q[ry][rx];
  61.                             three.rx = rx; three.ry = ry;
  62.                         }
  63.                 q[three.ry][three.rx] = -2;
  64.                 mag = -1;
  65.                 for (ry = 0; ry < 2; ry++)
  66.                 for (rx = 0; rx < 2; rx++)
  67.                      if (q[ry][rx] > mag) {
  68.                         mag = q[ry][rx];
  69.                         two.rx = rx; two.ry = ry;
  70.                         }
  71.                 q[two.ry][two.rx] = -2;
  72.                 mag = -1;
  73.                 for (ry = 0; ry < 2; ry++)
  74.                 for (rx = 0; rx < 2; rx++)
  75.                     if (q[ry][rx] > mag) {
  76.                         mag = q[ry][rx];
  77.                         one.rx = rx; one.ry = ry;
  78.                         }
  79.  
  80.                 q[four.rx][four.ry] = 4;
  81.                 q[three.rx][three.ry] = 3;
  82.                 q[two.rx][two.ry] = 2;
  83.                 q[one.rx][one.ry] = 1;
  84.                 class1 = 1000*q[0][0] + 100*q[1][0] + 10*q[1][1] + q[0][1];
  85.                 class = C[class1].c;
  86.                 mapping = C[class1].m;
  87.  
  88.                 for (y = 0; y < size; y++)
  89.                 for (x = 0; x < size; x++)
  90.                     {
  91.                     if (mapping == 0) temp[y][x] =image [        +y] [        +x];
  92.                     else
  93.                     if (mapping == 1) temp[y][x] =image [size -1 -x] [        +y];
  94.                     else
  95.                     if (mapping == 2) temp[y][x] =image [size -1 -y] [size -1 -x];
  96.                     else
  97.                     if (mapping == 3) temp[y][x] =image [        +x] [size -1 -y];
  98.  
  99.                     else
  100.                     if (mapping == 4) temp[y][x] =image [size -1 -y] [        +x];
  101.                     else
  102.                     if (mapping == 5) temp[y][x] =image [size -1 -x] [size -1 -y];
  103.                     else
  104.                     if (mapping == 6) temp[y][x] =image [        +y] [size -1 -x];
  105.                     else              temp[y][x] =image [        +x] [        +y];
  106.                     }
  107.  
  108.                     if (mapping != 0)
  109.                         for (y = 0; y < size; y++)
  110.                         for (x = 0; x < size; x++)
  111.                             image[y][x] = temp[y][x];
  112.  
  113. finish:
  114.            for (j = 0; j < 2; j++)
  115.            for (i = 0; i < 2; i++) {
  116.                 sumof[0] = sumof[1] = sumof[2] = sumof[3] = 0;
  117.                 for (ry = j*size/2; ry < j*size/2 + size/4; ry ++)
  118.                 for (rx = i*size/2; rx < i*size/2 + size/2; rx ++) {
  119.                     sumof[0] += image[rx][ry];
  120.                     sumof[2] += image[rx][ry+size/4];
  121.                     }
  122.                 for (ry = j*size/2; ry < j*size/2 + size/2; ry ++)
  123.                 for (rx = i*size/2; rx < i*size/2 + size/4; rx ++) {
  124.                     sumof[1] += image[rx][ry];
  125.                     sumof[3] += image[rx+size/4][ry];
  126.                     }
  127.                 horizontal = labs(sumof[0] - sumof[2]);
  128.                 vertical = labs(sumof[1] - sumof[3]);
  129.  
  130.                 q[i][j] = (horizontal >= vertical);
  131.                 }
  132.  
  133.                 subclass = 10000*class + 1000*q[0][0] + 100*q[1][0] + 10*q[0][1] + q[1][1];
  134.  
  135.                 return subclass;
  136. }
  137.  
  138.