/*對原始圖進行subsample,使原本的pixels變為1/n倍
此程式在此對256x256 pixels進行subsampling使其變成64x64 pixels*/
#include
#include
#define ROWS 256 /*定義原始圖形的行數*/
#define COLUMNS 256 /*定義原使圖形的列數*/
#define sqr(x) ((x)*(x))
int main( int argc, char **argv )
{
int i;
int j;
int k;
int threshold;
FILE *fp;
char *ifile, *ofile;
unsigned char image[ROWS][COLUMNS]; /*用來儲存原始圖片畫素灰階值*/
unsigned char image4[ROWS/4][COLUMNS/4];/*用來儲存subsampling後的畫素灰階值*/
/*輸入輸出設定,xxx.exe [input filename] [output filename] [threshold value]*/
if ( argc != 4 )
{
fprintf( stderr, "usage: %s input output threshold\n", argv[0] );
exit( 1 );
}
ifile = argv[1];
ofile = argv[2];
threshold = atoi(argv[3]);
if (( fp = fopen( ifile, "rb" )) == NULL )
{
fprintf( stderr, "error: couldn't open %s\n", ifile );
exit( 1 );
}
for ( i = 0; i new index->0所以可以使用(old index-3)/4來當new index*/
}
}
/*輸出處理後的圖形*/
if (( fp = fopen( ofile, "wb" )) == NULL )
{
fprintf( stderr, "error: could not open %s\n", ofile );
exit( 1 );
}
for ( i = 0 ; i
subsampling 結果如下:
大小變成原來的16分之1,為64x64 pixels
- Nov 17 Fri 2006 12:55
數位影像處理-使用C
全站熱搜
留言列表