我的图像SHADING算法和5x5滤波
本人直接使用Markdown编辑器,用它写博客玩一玩的哦:
- 目录
-
项目3
- 定义 C
-
定义 D
定义D内容
代码块
下面我的图像SHADING算法和5x5滤波的C#代码:
if (mImage == null)
{
MessageBox.Show("Please open or snap an image first.");
return;
}
if (mRectangle.Width == 0)
{
MessageBox.Show("Please add a rectangele area first.");
return;
}
//----------------------------------------------------------------------
// 将源图像内存区域锁定
Rectangle rect = new Rectangle(0, 0, mImage.Width, mImage.Height);
BitmapData bmpData = mImage.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
// 获取图像参数
int width = bmpData.Width;
int height = bmpData.Height;
int stride = bmpData.Stride; // 扫描线的宽度,比实际图片要大 (RGB用)
//int offset = stride - width * 3; // 显示宽度与扫描线宽度的间隙 (RGB用)
IntPtr ptr = bmpData.Scan0; // 获取bmpData的内存起始位置的指针
int scanBytesLength = stride * height; // 用stride宽度,表示这是内存区域的大小 (RGB用)
int mBigRectangle = mRectangle.Width * mRectangle.Height;
iCellGrayValue = new double[mBigRectangle];
ClassCommon.iCellGrayShadingRate = new double[mBigRectangle];
ClassCommon.iCellGrayShadingRateFinal = new double[mBigRectangle];
int mSmallRectangle = mRectMean.Width * mRectMean.Height;
iCellGrayValueOfSmall = new double[mSmallRectangle];
int posScan = 0;
int ordinal = 0;
byte[] curGrayValue = new byte[scanBytesLength]; // 为目标数组分配内存
Marshal.Copy(ptr, curGrayValue, 0, scanBytesLength)