返回> 网站首页
[转载]像素亮度 - 去噪点
yoours2015-12-31 12:08:58
简介一边听听音乐,一边写写文章。
double
GetBrightness(
BYTE
red,
BYTE
green,
BYTE
blue)
{
double
mn,mx;
double
lightness;
if
(red < green)
{
mn=red;mx=green;
}
else
{
mn=green;mx=red;
}
//
if
(blue < mn)
{
mn=blue;
}
else
if
(blue > mx)
{
mx=blue;
}
//
if
(mn==mx)
{
lightness=mn/255;
}
else
{
lightness=(mn+mx)/510;
// 2*255
}
return
lightness;
}
void
XXXX()
{
Bitmap bm = Bitmap(L
"E:\\test\\bmp_bw\\51.jpg"
);
// 得到位图对象
int
w = bm.GetWidth();
int
h = bm.GetHeight();
Bitmap bm2 = Bitmap(w, h);
Color c;
for
(
int
i = 0; i < w; i++)
{
for
(
int
j = 0; j < h; j++)
{
bm.GetPixel(i, j, &c);
double
b = GetBrightness(c.GetR(),c.GetG(),c.GetB());
if
(b <= 0.5)
{
bm2.SetPixel(i, j, Color.Blue);
}
}
}
CLSID encoderClsid;
GetEncoderClsid(L
"image/jpeg"
, &encoderClsid );
bm2.Save(L
"E:\\test\\mp_bw\\black.jpg"
,&encoderClsid);
}
文章评论
1910人参与,0条评论