/******************************************** * * file txtrsubs.c * * Functions: This file contains * sigma * skewness * amean * adifference * difference_array * hurst * compare * get_texture_options * * Purpose: * These functions calculate measures * that help distinguish textures. * * External Calls: * utility.c - fix_edges * sort_elements * fitt.c - fit * * Modifications: * 12 August 1993- created * 27 August 1998 - modified to work on * entire images at once. * ********************************************/ #include "cips.h" /******************************************* * * sigma(.. * * This calculates the variance and the * sigma for a sizeXsize area. * * It sums the squares of the difference * between each pixel and the mean of * the area and divides that by the * number of pixels in the area. * * The output image is set to the square * root of the variance since the variance * will almost certainly be out of range * for the image. The square root of the * variance will be sigma. * *******************************************/ sigma(the_image, out_image, size, threshold, high, rows, cols, bits_per_pixel) int high, threshold, size; long bits_per_pixel, cols, rows; short **the_image, **out_image; { int a, b, count, i, j, k, max, mean, new_hi, new_low, sd2, sd2p1; short sigma; unsigned long diff, variance; sd2 = size/2; sd2p1 = sd2 + 1; max = 255; new_hi = 250; new_low = 16; if(bits_per_pixel == 4){ new_hi = 10; new_low = 3; max = 16; } /*************************** * * Loop over image array * ****************************/ printf("\n"); for(i=sd2; i max) sigma = max; out_image[i][j] = sigma; } /* ends loop over j */ } /* ends loop over i */ /* if desired, threshold the output image */ if(threshold == 1){ for(i=0; i high){ out_image[i][j] = new_hi; } else{ out_image[i][j] = new_low; } } } } /* ends if threshold == 1 */ fix_edges(out_image, sd2, rows-1, cols-1); } /* ends sigma */ /******************************************* * * skewness(.. * * This calculates the skewness for a * sizeXsize area. * * Look at Levine's book page 449 for * the formula. * "Vision in Man and Machine" by * Martin D. Levine, McGraw Hill, 1985. * *******************************************/ skewness(the_image, out_image, size, threshold, high, rows, cols, bits_per_pixel) int high, threshold, size; long bits_per_pixel, cols, rows; short **the_image, **out_image; { int a, b, count, i, j, k, max, mean, new_hi, new_low, sd2, sd2p1; long cube; short sigma, skew; unsigned long diff, sigma3, variance; sd2 = size/2; sd2p1 = sd2 + 1; max = 255; new_hi = 250; new_low = 16; if(bits_per_pixel == 4){ new_hi = 10; new_low = 3; max = 16; } /*************************** * * Loop over image array * ****************************/ printf("\n"); for(i=sd2; i max) out_image[i][j] = max; } /* ends loop over j */ } /* ends loop over i */ /* if desired, threshold the output image */ if(threshold == 1){ for(i=0; i high){ out_image[i][j] = new_hi; } else{ out_image[i][j] = new_low; } } } } /* ends if threshold == 1 */ fix_edges(out_image, sd2, rows-1, cols-1); } /* ends skewness */ /******************************************* * * adifference(.. * * This function performs the difference * operation for a specified array * in an image file. * *******************************************/ adifference(the_image, out_image, size, rows, cols) int size; long cols, rows; short **the_image, **out_image; { int sd2, sd2p1; sd2 = size/2; sd2p1 = sd2 + 1; difference_array(the_image, out_image, size, rows, cols); fix_edges(out_image, sd2, rows-1, cols-1); } /* ends adifference */ /******************************************* * * difference_array(.. * * This function takes the input image * array the_image and places in out_image * the gray level differences of the pixels * in the_image. It uses the size * parameter for the distance between pixels * used to get the difference. * *******************************************/ difference_array(the_image, out_image, size, rows, cols) int size; long cols, rows; short **the_image, **out_image; { int i, j, sd2; sd2 = size/2; for(i=sd2; i max) out_image[i][j] = max; } /* ends loop over j */ } /* ends loop over i */ fix_edges(out_image, sd2, rows-1, cols-1); } /* ends amean */ /******************************************* * * hurst(.. * * This routine performs the Hurst * operation as described in "The Image * Processing Handbook" by John C. Russ * CRC Press 1992. * * The following show the definitions of * the pixel classes used in this routine. * * 3x3 case * c b c * d b a b d * c b c * * 5x5 case * f e d e f * e c b c e * d b a b d * e c b c e * f e d e f * * 7x7 case * h g h * f e d e f * h e c b c e h * g d b a b d g * h e c b c e h * f e d e f * h g h * *******************************************/ hurst(the_image, out_image, size, rows, cols, bits_per_pixel) int size; long bits_per_pixel, cols, rows; short **the_image, **out_image; { float x[8], y[8], sig[8]; float aa, bb, siga, sigb, chi2, q; int ndata, mwt; int a, b, count, i, j, k, new_hi, new_low, length, number, sd2, sd2p1, ss, width; short *elements, max, prange; /********************************************** * * Initialize the ln's of the distances. * Do this one time to save computations. * **********************************************/ x[1] = 0.0; /* ln(1) */ x[2] = 0.34657359; /* ln(sqrt(2)) */ x[3] = 0.69314718; /* ln(2) */ x[4] = 0.80471896; /* ln(sqrt(5)) */ x[5] = 1.03972077; /* ln(sqrt(8)) */ x[6] = 1.09861229; /* ln(3) */ x[7] = 1.15129255; /* ln(sqrt(10)) */ sig[1] = 1.0; sig[2] = 1.0; sig[3] = 1.0; sig[4] = 1.0; sig[5] = 1.0; sig[6] = 1.0; sig[7] = 1.0; sd2 = size/2; printf("\nHURST>sd2=%d",sd2); if(sd2 < 2) sd2 = 2; printf("\nHURST>sd2=%d",sd2); /********************************** * * ***********************************/ max = 255; if(bits_per_pixel == 4){ max = 16; } /*************************** * * Loop over image array * ****************************/ printf("\n"); for(i=sd2; i max) out_image[i][j] = max; if(out_image[i][j] < 0) out_image[i][j] = 0; } /* ends loop over j */ } /* ends loop over i */ fix_edges(out_image, sd2, rows-1, cols-1); } /* ends hurst */ /******************************************* * * compare(.. * * This function compares a sizeXsize area * starting at line,element in an image * with all the sizeXsize areas in the * image. * *******************************************/ compare(the_image, out_image, line, element, size, rows, cols, bits_per_pixel) int line, element, size; long bits_per_pixel, cols, rows; short **the_image, **out_image; { int a, b, count, i, j, k, max, sd2, sd2p1; short pixel; int big, diff; /************************************** * * Declare and allocate memory for the * two dimensional small array. * ***************************************/ short **small; small = malloc(size * sizeof(short *)); for(i=0; i max) out_image[i][j] = max; } /* ends loop over j */ } /* ends loop over i */ fix_edges(out_image, sd2, rows-1, cols-1); /************************************** * * Free the memory for the * two dimensional small array. * ***************************************/ for(i=0; i