home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 9
/
CD_ASCQ_09_1193.iso
/
news
/
4441
/
yuvpak
/
wdyusual.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-30
|
6KB
|
138 lines
/**************************************************************************/
/* */
/* Usual Classification 1.0 */
/* */
/**************************************************************************/
long int usual (unsigned char image[max_patch][max_patch], int size)
{
char rmsstr[13];
int mag, max, min, class, class1, subclass, rx, ry, x, y, i, j;
long int q[2][2], sumof[4], horizontal, vertical;
unsigned char temp[size][size];
struct max_t {
int rx;
int ry;
} four, three, two, one;
struct class_t {
int c;
int m;
} C[4322];
C[4321].c = C[4123].c = C[3412].c = C[3214].c =
C[2341].c = C[2143].c = C[1432].c = C[1234].c = 1;
C[4312].c = C[4213].c = C[3421].c = C[3124].c =
C[1342].c = C[1243].c = C[2431].c = C[2134].c = 2;
C[4132].c = C[4231].c = C[3241].c = C[3142].c =
C[2413].c = C[2314].c = C[1423].c = C[1324].c = 3;
C[4321].m = 0; C[4123].m = 5; C[3412].m = 4; C[3214].m = 3;
C[2341].m = 7; C[2143].m = 2; C[1432].m = 1; C[1234].m = 6;
C[4312].m = 0; C[4213].m = 5; C[3421].m = 4; C[3124].m = 1;
C[1342].m = 7; C[1243].m = 2; C[2431].m = 1; C[2134].m = 5;
C[4132].m = 5; C[4231].m = 0; C[3241].m = 5; C[3142].m = 2;
C[2413].m = 4; C[2314].m = 3; C[1423].m = 1; C[1324].m = 6;
for (ry = 0; ry < size; ry +=size/2)
for (rx = 0; rx < size; rx +=size/2) {
q[ry/(size/2)][rx/(size/2)] = 0;
for (y = ry; y < ry + size/2; y++)
for (x = rx; x < rx + size/2; x++)
q[ry/(size/2)][rx/(size/2)]+=image[y][x];
}
mag = -1;
for (ry = 0; ry < 2; ry++)
for (rx = 0; rx < 2; rx++)
if (q[ry][rx] > mag) {
mag = q[ry][rx];
four.rx = rx; four.ry = ry;
}
q[four.ry][four.rx] = -2;
mag = -1;
for (ry = 0; ry < 2; ry++)
for (rx = 0; rx < 2; rx++)
if (q[ry][rx] > mag) {
mag = q[ry][rx];
three.rx = rx; three.ry = ry;
}
q[three.ry][three.rx] = -2;
mag = -1;
for (ry = 0; ry < 2; ry++)
for (rx = 0; rx < 2; rx++)
if (q[ry][rx] > mag) {
mag = q[ry][rx];
two.rx = rx; two.ry = ry;
}
q[two.ry][two.rx] = -2;
mag = -1;
for (ry = 0; ry < 2; ry++)
for (rx = 0; rx < 2; rx++)
if (q[ry][rx] > mag) {
mag = q[ry][rx];
one.rx = rx; one.ry = ry;
}
q[four.rx][four.ry] = 4;
q[three.rx][three.ry] = 3;
q[two.rx][two.ry] = 2;
q[one.rx][one.ry] = 1;
class1 = 1000*q[0][0] + 100*q[1][0] + 10*q[1][1] + q[0][1];
class = C[class1].c;
mapping = C[class1].m;
for (y = 0; y < size; y++)
for (x = 0; x < size; x++)
{
if (mapping == 0) temp[y][x] =image [ +y] [ +x];
else
if (mapping == 1) temp[y][x] =image [size -1 -x] [ +y];
else
if (mapping == 2) temp[y][x] =image [size -1 -y] [size -1 -x];
else
if (mapping == 3) temp[y][x] =image [ +x] [size -1 -y];
else
if (mapping == 4) temp[y][x] =image [size -1 -y] [ +x];
else
if (mapping == 5) temp[y][x] =image [size -1 -x] [size -1 -y];
else
if (mapping == 6) temp[y][x] =image [ +y] [size -1 -x];
else temp[y][x] =image [ +x] [ +y];
}
if (mapping != 0)
for (y = 0; y < size; y++)
for (x = 0; x < size; x++)
image[y][x] = temp[y][x];
finish:
for (j = 0; j < 2; j++)
for (i = 0; i < 2; i++) {
sumof[0] = sumof[1] = sumof[2] = sumof[3] = 0;
for (ry = j*size/2; ry < j*size/2 + size/4; ry ++)
for (rx = i*size/2; rx < i*size/2 + size/2; rx ++) {
sumof[0] += image[rx][ry];
sumof[2] += image[rx][ry+size/4];
}
for (ry = j*size/2; ry < j*size/2 + size/2; ry ++)
for (rx = i*size/2; rx < i*size/2 + size/4; rx ++) {
sumof[1] += image[rx][ry];
sumof[3] += image[rx+size/4][ry];
}
horizontal = labs(sumof[0] - sumof[2]);
vertical = labs(sumof[1] - sumof[3]);
q[i][j] = (horizontal >= vertical);
}
subclass = 10000*class + 1000*q[0][0] + 100*q[1][0] + 10*q[0][1] + q[1][1];
return subclass;
}