用C语言进行BMP图像二值化,显示其长宽,最好有解释*⼀

麻烦各位啦。。要VC++6.0环境能跑像素点的灰度值设置为0或255
2025-03-18 16:44:19
推荐回答(2个)
回答1:

#include
void whiteblack(int *selimage, int height, int width, int *twovalimage)
{
int indexh,indexw;
int val1=0,val2=255;

//求取阀值
for(indexh=0; indexh < height; indexh++)
for(indexw=0; indexw < width; indexw++)
{
if(*(twovalimage + width*indexh + indexw) < val2)
val2 = *(twovalimage + width*indexh + indexw); //val2:minvalue
if(*(twovalimage + width*indexh + indexw) > val1)
val1 = *(twovalimage + width*indexh + indexw); //val1:maxvalue
}
val1 = val1 - (val1 - val2)/3; //calculate limit value
//二值化
for(indexh=0; indexh < height; indexh++)
for(indexw=0; indexw < width; indexw++)
{
/*tr=*(selimage + width*indexh + indexw);
*(twovalimage + width*indexh + indexw)=tr;*/
if(*(selimage + width*indexh + indexw) <20)
{
*(twovalimage + width*indexh + indexw) = 0;

}
else
*(twovalimage + width*indexh + indexw) = 255;
}
}

回答2:

CImage image;
//加载BMG
image.Load(L"");
//宽
image.GetWidth();
//byte 字节 二进制
image.GetBits();
//高
image.GetHeight();