📄 模拟图像缩小的c源代码.txt
字号:
模拟图像缩小的c源代码[原创]
做一个简单模拟,真正的要复杂的多
/*
to enlittle an image by K times
AUTHOR:BugEyes
http://BugEyes.blog.edu.cn
*/
#define N 10
#define K 2
#define M 100
#i nclude <stdlib.h>
#i nclude <conio.h>
void init(int arr[N][N])
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
arr[i][j]=random(M);
}
void zoomout(int arr[N][N],int core[K][K],int result[N/K][N/K])
{
int i,j,row,col;
int temp;
int count=0;
for(i=0;i<K;i++)
for(j=0;j<K;j++)
count+=core[i][j];
for(i=0;i<N/K;i++)
for(j=0;j<N/K;j++)
{
temp=0;
for(row=K*i;row<K*i+K;row++)
for(col=K*j;col<K*j+K;col++)
temp+=arr[row][col]*core[row-K*i][col-K*j];
result[i][j]=temp/count;
}
}
void output(int arr[N][N],int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%5d",arr[i][j]);
printf("\n\n\n");
}
}
void output1(int arr[N/K][N/K],int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%5d",arr[i][j]);
printf("\n\n\n");
}
}
main()
{
int array[N][N],result[N/K][N/K];
int core[K][K]={{2,1},{1,2}};
init(array);
zoomout(array,core,result);
clrscr();
output(array,N);
printf("\n\n");
output1(result,N/K);
}
BugEyes 发表于 2005-8-14 18:07:00
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -