📄 cips5.c
字号:
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<ROWS; i++){
if ( (i%10) == 0) printf(" %d", i);
for(j=0; j<COLS; j++){
if(the_image[i][j] > 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<ROWS; i++){
if ( (i%10) == 0) printf(" %d", i);
for(j=0; j<COLS; j++){
if(the_image[i][j] < 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 less_overlay */
/**************************************************
*
* average_overlay(...
*
* This function mixes in1 and in2
* and writes the result to the output image.
* It writes the average of in1 and in2 to the
* output image.
*
***************************************************/
average_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<ROWS; i++){
if ( (i%10) == 0) printf(" %d", i);
for(j=0; j<COLS; j++){
out_image[i][j] =
(the_image[i][j] + out_image[i][j])/2;
} /* ends loop over j */
} /* ends loop over i */
write_array_into_tiff_image(out_name, out_image,
il3, ie3, ll3, le3);
} /* ends average_overlay */
/***********************************************
*
* file d:\cips\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:
* wtiff.c - round_off_image_size
* create_file_if_needed
* write_array_into_tiff_image
* tiff.c - read_tiff_header
* rtiff.c - read_tiff_image
* edge.c - fix_edges
* fitt.c - fit
* filter.c - sort_elements
*
* Modifications:
* 12 August 1993- created
*
*************************************************/
/*******************************************
*
* 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(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;
short sigma;
struct tiff_header_struct image_header;
unsigned long diff, 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<ROWS-sd2; i++){
if( (i%10) == 0) printf("%d ", i);
for(j=sd2; j<COLS-sd2; j++){
/*****************************
*
* Run through the small area
* and calculate the mean.
*
******************************/
mean = 0;
for(a=-sd2; a<sd2p1; a++){
for(b=-sd2; b<sd2p1; b++){
mean = mean + the_image[i+a][j+b];
}
}
mean = mean/(size*size);
/*****************************
*
* Run through the small area
* again and the calculate the
* variance.
*
******************************/
variance = 0;
diff = 0;
for(a=-sd2; a<sd2p1; a++){
for(b=-sd2; b<sd2p1; b++){
diff = the_image[i+a][j+b] - mean;
variance = variance + (diff*diff);
}
}
variance = variance/(size*size);
sigma = sqrt(variance);
if(sigma > 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<ROWS; i++){
for(j=0; j<COLS; j++){
if(out_image[i][j] > 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<ROWS-sd2; i++){
if( (i%10) == 0) printf("%d ", i);
for(j=sd2; j<COLS-sd2; j++){
/*****************************
*
* Run through the small area
* and calculate the mean.
*
******************************/
mean = 0;
for(a=-sd2; a<sd2p1; a++){
for(b=-sd2; b<sd2p1; b++){
mean = mean + the_image[i+a][j+b];
}
}
mean = mean/(size*size);
/*****************************
*
* Run through the small area
* again and the calculate the
* variance and the cube.
*
******************************/
variance = 0;
diff = 0;
cube = 0;
for(a=-sd2; a<sd2p1; a++){
for(b=-sd2; b<sd2p1; b++){
diff = the_image[i+a][j+b] - mean;
cube = cube + (diff*diff*diff);
variance = variance + (diff*diff);
}
}
variance = variance/(size*size);
sigma = sqrt(variance);
sigma3 = sigma*sigma*sigma;
if(sigma3 == 0)
sigma3 = 1;
skew = cube/(sigma3*size*size);
out_image[i][j] = skew;
if(out_image[i][j] > 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<ROWS; i++){
for(j=0; j<COLS; j++){
if(out_image[i][j] > 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<ROWS; i++)
for(j=0; j<COLS; j++)
the_image[i][j] = out_image[i][j];
/**************************************
*
* Loop over the image array and
* calculate the mean measure.
*
***************************************/
printf("\n");
for(i=sd2; i<ROWS-sd2; i++){
if( (i%10) == 0) printf("%d ", i);
for(j=sd2; j<COLS-sd2; j++){
pixel = 0;
for(a=-sd2; a<sd2p1; a++){
for(b=-sd2; b<sd2p1; b++){
pixel = pixel + the_image[i+a][j+b];
}
}
out_image[i][j] = pixel/(size*size);
if(out_image[i][j] > 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,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -