使用纯c语言实现灰度png图像剪切,例如2048转为512,然后阈值分割二值化
回答不易,求求您采纳点赞哦
代码可以实现从一种尺寸的png图像(20482048)剪切成另一种尺寸(512512),并进行阈值分割二值化,分割后的图像可以根据阈值将像素
实现灰度png图像剪切的C语言代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
// 加载图像
int width = 2048;
int height = 2048;
int resize_width = 512;
int resize_height = 512;
char image[width][height];
// 剪切
int i, j;
for (i=0; i<resize_width; i++){
for (j=0; j<resize_height; j++){
image[i][j] = image[i*4][j*4];
}
}
// 二值化
for (i=0; i<resize_width; i++){
for (j=0; j<resize_height; j++){
if (image[i][j] < 127)
{
image[i][j] = 0;
}
else
{
image[i][j] = 255;
}
}
}
// 输出新图像
FILE *fp;
fp = fopen("result.png", "wb+");
// ... 省略其他代码
return 0;
}