采用第三方dll 写的
#region Image helpers
Bitmap preprocess(Bitmap bmp, FiltersSequence fs)
{
Bitmap tmp = bmp.Clone() as Bitmap;
tmp = fs.Apply(bmp);
return tmp;
}
Bitmap projectHistogram(Bitmap bmp)
{
// stats
if (histo != null)
histo = null;
int width = bmp.Width;
int height = bmp.Height;
histo = new int[width];
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
{
Color color = bmp.GetPixel(x, y);
if (color.R < 50 && color.G < 50 && color.B < 50)
//if (color.A > 200)
histo[x]++;
}
// draw
//int max = getMax(histo);
Bitmap tmp = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(tmp))
for (int i = 0; i < width; i++)
g.DrawLine(
Pens.Black,
i,
height,
i,
height - histo[i]);
return tmp;
}
// get rid of noises
Bitmap denoise(Bitmap bmp, Size size)
{
Bitmap ivbmp = bmp.Clone() as Bitmap;
Invert iv = new Invert();
iv.ApplyInPlace(ivbmp);
BlobCounter bc = new BlobCounter();
bc.FilterBlobs = true;
bc.MinWidth = bc.MinHeight = 0;
bc.MaxWidth = size.Width;
bc.MaxHeight = size.Height;
bc.ProcessImage(ivbmp);
Rectangle[] rects = bc.GetObjectsRectangles();
Bitmap tmp = new Bitmap(bmp);
using (Graphics g = Graphics.FromImage(tmp))
//g.DrawRectangles(Pens.Red, rects);
if (rects.Length > 0)
g.FillRectangles(Brushes.White, rects);
//iv.ApplyInPlace(tmp);
return tmp;
}
// draw some division lines over bitmap
评论0
最新资源