110,566
社区成员
发帖
与我相关
我的任务
分享
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)
histo[x]++;
}
}
Bitmap tmp = new Bitmap(bmp.Width, bmp.Height);
using (Graphics g = Graphics.FromImage(tmp))
for (int i = 0; i < bmp.Width; i++)
{
g.DrawLine(
Pens.Black,
i,
tmp.Height,
i,
tmp.Height - histo[i]);
}
Bitmap getProjectHistogram(Bitmap bmp)
{
int width = bmp.Width;
int height = bmp.Height;
int[] histo = null;
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)
histo[x]++;
}
// draw
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;
}