📄 waveproc.c
字号:
// Copyright (c) 1999 Stephen T. Welstead. All rights reserved.
// waveproc.c Procedures for wavelet processing
#include <malloc.h>
#include <math.h>
#include "waveproc.h"
int decimate_array (float **array,int rows,int cols,
unsigned long n) {
/* Set all but the largest amplitude n array elements equal to 0 */
/* Array indexes start at 1. */
tindex *indexes;
int i,j;
unsigned long k,count = 0;
int min_index,start_row,start_col;
float min;
if (n == 0) {
for (i=1;i<=rows;i++)
for (j=1;j<=cols;j++)
array[i][j] = 0.0;
return 1;
}
if (!(indexes = malloc ((size_t)(n+1)*sizeof(tindex)))) return 0;
/* Initialize index list and minimum: */
min = fabs(array[1][1]);
min_index = 1;
for (i=1;i<=rows;i++) {
for (j=1;j<=cols;j++) {
count++;
indexes[count].row = i;
indexes[count].col = j;
if (fabs(array[i][j]) < min) {
min = fabs(array[i][j]);
min_index = count;
}
start_row = i;
start_col = j;
if (count == n) break;
} /* end j */
if (count == n) break;
} /* end i */
/* Finish this row */
for (j=start_col+1;j<=cols;j++)
if (fabs(array[start_row][j]) > min) {
/* Set array min list element equal to 0 */
array[indexes[min_index].row][indexes[min_index].col] = 0.0;
/* Replace min element in list with this new element */
indexes[min_index].row = start_row;
indexes[min_index].col = j;
/* search for new min in index list: */
min = fabs(array[start_row][j]);
for (k=1;k<=n;k++)
if (fabs(array[indexes[k].row][indexes[k].col]) < min) {
min = fabs(array[indexes[k].row][indexes[k].col]);
min_index = k;
}
} /* end if, j */
else array[start_row][j] = 0.0; /* not a candidate for list */
for (i=start_row+1;i<=rows;i++)
for (j=1;j<=cols;j++)
if (fabs(array[i][j]) > min) {
/* Set array min list element equal to 0 */
array[indexes[min_index].row][indexes[min_index].col] = 0.0;
/* Replace min element in list with this new element */
indexes[min_index].row = i;
indexes[min_index].col = j;
/* search for new min in index list: */
min = fabs(array[i][j]);
for (k=1;k<=n;k++)
if (fabs(array[indexes[k].row][indexes[k].col]) < min) {
min = fabs(array[indexes[k].row][indexes[k].col]);
min_index = k;
}
} /* end if, i,j */
else array[i][j] = 0.0; /* not a candidate for list */
free (indexes);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -