/* Lee Sigma v1.0.1 Ver.:OK (c) 03/08 - Christos Iosifides */
/*
Name: Lee_Sigma_8UI
Version: 1.0.1
Author: Christos Iosifidis
Date: 01/02/08 11:03
Description: Lee Sigma filtering on 8UI BIL datasets
Usage: >Lee_Sigma_8UI filename_of_the_8UI_BIL_dataset filename_of_the_8UI_BIL_Filtered_dataset rows columns bands structured_element
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include
#include
#define sqr(x) ((x)*(x))
void error(const char *);
int main(int argc, char *argv[]) {
FILE *fpin, *fpout;
int rows, cols, bands, win, win_1, win_2, rows_1, cols_1, cols2, rows_win_2, cols_win_2, cols__win_1, X;
double s, ss, mean, variance, var, Sigma_Value, Sigma_Multiplier, d;
unsigned char *s_element, *in_buffer, *out_buffer;
register int r, c, i, j, k;
/* Check and read argument list items */
if (argc!=7)
error("Usage parameters: Input_image Output_image rows cols bands structure_element");
rows=atoi(argv[3]);
cols=atoi(argv[4]);
bands=atoi(argv[5]);
if (rows<3)
error("rows must be larger than 3");
if (cols<3)
error("columns must be larger than 3");
if (bands<1)
error("bands must be more than 1");
/* Compute helpfull variables */
cols*=bands;
rows_1=rows-1;
cols_1=cols-1;
cols2=cols<<1;
/* Open input element file */
if ((fpin=fopen(argv[6],"r"))==NULL)
error("Bad input element file name");
/* Read structuring element size */
if (fscanf(fpin,"%d",&win)!=1)
error("Bad element file read 1");
/* Check structuring element size */
if (win<3 || win%2==0)
error("Element size must be odd and greater or equal to 3");
/* Allocate structuring element memory */
if ((s_element=(unsigned char *)malloc(win*win))==NULL)
error("Not enough memory avaliable for structuring element");
/* Read structuring element */
for (i=0;i>1;
win_1=win-1;
rows_win_2=rows-win_2;
cols_win_2=cols-win_2;
cols__win_1=cols*win_1;
/* Allocate input buffer */
if ((in_buffer=(unsigned char *)malloc(win*cols))==NULL)
error("Not enough memory avaliable for input buffer");
/* Open input image */
if ((fpin=fopen(argv[1],"rb"))==NULL)
error("Bad input file name");
/* Open output image */
if ((fpout=fopen(argv[2],"wb"))==NULL)
error("Bad output file open");
/* Allocate output file */
if ((out_buffer=(unsigned char *)malloc(cols))==NULL)
error("Not enough memory avaliable for output buffer");
/* Store 0 in first empty line */
memset(out_buffer, 0, cols);
/* Write first win/2 empty lines M_Dilation*/
for (i=0;i.\n",s);
exit(1);
}