/*************************** * * cips5.c * COMPOSITE FILE COMPRISING: * boole.c * overlay.c * txtrsubs.c * ***************************\ /*********************************************** * * file d:\cips\boole.c * * Functions: This file contains * and_image * or_image * xor_image * nand_image * nor_image * not_image * * Purpose: * These functions implement the basic * Boolean algebra functions AND, OR, * XOR, NAND, NOR, and NOT. * * External Calls: * wtiff.c - create_file_if_needed * write_array_into_tiff_image * tiff.c - read_tiff_header * rtiff.c - read_tiff_image * numcvrt.c - get_integer * * Modifications: * 3 March 1993 - created * ***********************************************/ #include "cips.h" /************************************************** * * and_image(... * * This function performs the Boolean AND * operation. The output image = in1 AND in2. * This works for 0 non-zero images. If both * in1 and in2 are non-zero, the output = in1. * ***************************************************/ and_image(in1_name, in2_name, out_name, the_image, out_image, il1, ie1, ll1, le1, il2, ie2, ll2, le2, il3, ie3, ll3, le3) char in1_name[], in2_name[], out_name[]; int il1, ie1, ll1, le1, il2, ie2, ll2, le2, il3, ie3, ll3, le3; short the_image[ROWS][COLS], out_image[ROWS][COLS]; { int i, j, length, width; struct tiff_header_struct image_header; create_file_if_needed(in1_name, out_name, out_image); read_tiff_image(in1_name, the_image, il1, ie1, ll1, le1); read_tiff_image(in2_name, out_image, il2, ie2, ll2, le2); for(i=0; i out_image[i][j]) out_image[i][j] = the_image[i][j]; } /* ends loop over j */ } /* ends loop over i */ write_array_into_tiff_image(out_name, out_image, il3, ie3, ll3, le3); } /* ends greater_overlay */ /************************************************** * * less_overlay(... * * This function overlays in1 on top of in2 * and writes the result to the output image. * It writes in1 on top of in2 if the value of * in1 is less than in2. * ***************************************************/ less_overlay(in1_name, in2_name, out_name, the_image, out_image, il1, ie1, ll1, le1, il2, ie2, ll2, le2, il3, ie3, ll3, le3) char in1_name[], in2_name[], out_name[]; int il1, ie1, ll1, le1, il2, ie2, ll2, le2, il3, ie3, ll3, le3; short the_image[ROWS][COLS], out_image[ROWS][COLS]; { int i, j, length, width; struct tiff_header_struct image_header; create_file_if_needed(in1_name, out_name, out_image); read_tiff_image(in1_name, the_image, il1, ie1, ll1, le1); read_tiff_image(in2_name, out_image, il2, ie2, ll2, le2); for(i=0; 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); write_array_into_tiff_image(out_name, out_image, il, ie, ll, le); } /* 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(in_name, out_name, the_image, out_image, il, ie, ll, le, size, threshold, high) char in_name[], out_name[]; int il, ie, ll, le, high, threshold, size; short the_image[ROWS][COLS], out_image[ROWS][COLS]; { int a, b, count, i, j, k, max, mean, new_hi, new_low, sd2, sd2p1; long cube; short sigma, skew; struct tiff_header_struct image_header; unsigned long diff, sigma3, variance; sd2 = size/2; sd2p1 = sd2 + 1; create_file_if_needed(in_name, out_name, out_image); read_tiff_image(in_name, the_image, il, ie, ll, le); max = 255; new_hi = 250; new_low = 16; if(image_header.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); write_array_into_tiff_image(out_name, out_image, il, ie, ll, le); } /* ends skewness */ /******************************************* * * amean(.. * * This calculates the mean measure * for a sizeXsize area. * * Look at Levine's book page 451 for * the formula. * "Vision in Man and Machine" by * Martin D. Levine, McGraw Hill, 1985. * *******************************************/ amean(in_name, out_name, the_image, out_image, il, ie, ll, le, size) char in_name[], out_name[]; int il, ie, ll, le, size; short the_image[ROWS][COLS], out_image[ROWS][COLS]; { int a, b, count, i, j, k, max, sd2, sd2p1; short pixel; struct tiff_header_struct image_header; unsigned long big; sd2 = size/2; sd2p1 = sd2 + 1; create_file_if_needed(in_name, out_name, out_image); read_tiff_image(in_name, the_image, il, ie, ll, le); max = 255; if(image_header.bits_per_pixel == 4){ max = 16; } /************************************** * * Calculate the gray level difference * array. * ***************************************/ difference_array(the_image, out_image, size); for(i=0; i max) out_image[i][j] = max; } /* ends loop over j */ } /* ends loop over i */ fix_edges(out_image, sd2); write_array_into_tiff_image(out_name, out_image, il, ie, ll, le); } /* ends amean */ /******************************************* * * adifference(.. * * This function performs the difference * operation for a specified array * in an image file. * *******************************************/ adifference(in_name, out_name, the_image, out_image, il, ie, ll, le, size) char in_name[], out_name[]; int il, ie, ll, le, size; short the_image[ROWS][COLS], out_image[ROWS][COLS]; { int sd2, sd2p1; struct tiff_header_struct image_header; sd2 = size/2; sd2p1 = sd2 + 1; create_file_if_needed(in_name, out_name, out_image); read_tiff_image(in_name, the_image, il, ie, ll, le); difference_array(the_image, out_image, size); fix_edges(out_image, sd2); write_array_into_tiff_image(out_name, out_image, il, ie, ll, le); } /* 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) int size; short the_image[ROWS][COLS], out_image[ROWS][COLS]; { int i, j, sd2; sd2 = size/2; 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); write_array_into_tiff_image(out_name, out_image, il, ie, ll, le); } /* 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(in_name, out_name, the_image, out_image, il, ie, ll, le, line, element, size) char in_name[], out_name[]; int il, ie, ll, le, line, element, size; short the_image[ROWS][COLS], out_image[ROWS][COLS]; { int a, b, count, i, j, k, max, sd2, sd2p1; short pixel; struct tiff_header_struct image_header; 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); write_array_into_tiff_image(out_name, out_image, il, ie, ll, le); /************************************** * * Free the memory for the * two dimensional small array. * ***************************************/ for(i=0; i