Mil学习之Mim的简单操作
Posted Thomas会写字
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mil学习之Mim的简单操作相关的知识,希望对你有一定的参考价值。
1. 旋转矩形区域的矫正
MIL.MbufAllocColor(MilSystem, MIL.MbufInquire(MilImage, MIL.M_SIZE_BAND, MIL.M_NULL),
nWidth, nHeight, 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, ref MilImageTmp);
MIL.MimRotate(MilImage, MilImageTmp, -rectAngle, rectCenter.x, rectCenter.y, nWidth / 2, nHeight / 2, MIL.M_DEFAULT);
2. 图像的位运算与提亮
图像位运算效果如下
MIL.MimShift(MilImage, MilImageTmp, -3);
图像位运算与做差运算组合效果如下
MIL.MimShift(MilImage, MilImageTmp, -3);
MIL.MimArith(MilImage, MilImageTmp, MilImageTmp, MIL.M_SUB_ABS);
3. 图片的缩放、镜像、移动、傅立叶变换
这里说下,傅立叶变换效果与你选择特征点的分布特征有关,比如对称、非对称等
效果如如下
int nW = (int)MIL.MbufInquire(MilImageTmp, MIL.M_SIZE_X, MIL.M_NULL);
int nH = (int)MIL.MbufInquire(MilImageTmp, MIL.M_SIZE_Y, MIL.M_NULL);
int nB = (int)MIL.MbufInquire(MilImageTmp, MIL.M_SIZE_BAND, MIL.M_NULL);
int nD = (int)MIL.MbufInquire(MilImageTmp, MIL.M_SIZE_BIT, MIL.M_NULL);
MIL.MgraColor(showTmp.MilGraphContext, MIL.M_COLOR_RED);
MIL.MgraControl(showTmp.MilGraphContext, MIL.M_FONT_X_SCALE, 2.2);
MIL.MgraControl(showTmp.MilGraphContext, MIL.M_FONT_Y_SCALE, 2.2);
MIL_ID MimSmall = 0;
MIL_ID MimChild = 0;
MIL.MbufAllocColor(MilSystem, nB, nW / 2, nH / 2, nD + MIL.M_UNSIGNED, MIL.M_PROC + MIL.M_IMAGE + MIL.M_DISP, ref MimSmall);
MIL.MimResize(MilImageTmp, MimSmall, 0.5, 0.5, MIL.M_DEFAULT);
MIL.MbufClear(MilImageTmp, 0);
MIL.MbufChild2d(MilImageTmp, 0, 0, nW / 2, nH / 2, ref MimChild);
MIL.MbufCopy(MimSmall, MimChild);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "Resize Image");
MIL.MbufFree(MimChild);
MIL.MbufChild2d(MilImageTmp, nW / 2, 0, nW / 2, nH / 2, ref MimChild);
MIL.MimFlip(MimSmall, MimChild, MIL.M_FLIP_HORIZONTAL, MIL.M_DEFAULT);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "Mirror Image");
MIL.MbufFree(MimChild);
MIL.MbufChild2d(MilImageTmp, 0, nH / 2, nW / 2, nH / 2, ref MimChild);
MIL.MimTranslate(MimSmall, MimChild, -100, 100, MIL.M_DEFAULT);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "Move Image");
MIL.MbufFree(MimChild);
// 傅立叶变换要求图片宽高必须是2的幂
int nW2 = 512;
int nH2 = 512;
MIL_ID MilTransformReal = 0;
MIL_ID MilTransformIm = 0;
MIL_ID MimSmall2 = 0;
float[] ZeroVal = new float[1];
ZeroVal[0] = 0.0F;
MIL.MbufChild2d(MilImageTmp, nW / 2, nH / 2, nW / 2, nH / 2, ref MimChild);
MIL.MbufAlloc2d(MilSystem, nW2, nH2, nD + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_PROC, ref MimSmall2);
MIL.MbufAlloc2d(MilSystem, nW2, nH2, 32 + MIL.M_FLOAT, MIL.M_IMAGE + MIL.M_PROC, ref MilTransformReal);
MIL.MbufAlloc2d(MilSystem, nW2, nH2, 32 + MIL.M_FLOAT, MIL.M_IMAGE + MIL.M_PROC, ref MilTransformIm);
MIL.MimResize(MimSmall, MimSmall2, nW2 * 1.0 / nW, nH2 * 1.0 / nH, MIL.M_DEFAULT);
MIL.MimTransform(MimSmall2, MIL.M_NULL, MilTransformReal, MilTransformIm, MIL.M_FFT, MIL.M_FORWARD + MIL.M_CENTER + MIL.M_MAGNITUDE + MIL.M_LOG_SCALE);
// 分析 MilTransformReal 数据得到异常点坐标为 511 511
MIL.MimTransform(MimSmall2, MIL.M_NULL, MilTransformReal, MilTransformIm, MIL.M_FFT, MIL.M_FORWARD + MIL.M_CENTER);
MIL.MbufPut2d(MilTransformReal, 511, 511, 1, 1, ZeroVal);
MIL.MbufPut2d(MilTransformIm, 511, 511, 1, 1, ZeroVal);
MIL.MimTransform(MilTransformReal, MilTransformIm, MimSmall2, MIL.M_NULL, MIL.M_FFT, MIL.M_REVERSE + MIL.M_CENTER + MIL.M_SATURATION);
MIL.MimResize(MimSmall2, MimChild, nW * 1.0 / nW2, nH * 1.0 / nH2, MIL.M_DEFAULT);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "FFT Image");
MIL.MbufFree(MimChild);
MIL.MbufFree(MimSmall2);
MIL.MbufFree(MilTransformIm);
MIL.MbufFree(MilTransformReal);
MIL.MbufFree(MimSmall);
4.图片的拉普拉斯边缘、锐化、平滑、平滑+50%模糊
MIL.MgraColor(showTmp.MilGraphContext, MIL.M_COLOR_RED);
MIL.MgraControl(showTmp.MilGraphContext, MIL.M_FONT_X_SCALE, 2.2);
MIL.MgraControl(showTmp.MilGraphContext, MIL.M_FONT_Y_SCALE, 2.2);
MIL_ID MimSmall = 0;
MIL_ID MimChild = 0;
MIL.MbufAllocColor(MilSystem, nB, nW / 2, nH / 2, nD + MIL.M_UNSIGNED, MIL.M_PROC + MIL.M_IMAGE + MIL.M_DISP, ref MimSmall);
MIL.MimResize(MilImageTmp, MimSmall, 0.5, 0.5, MIL.M_DEFAULT);
MIL.MbufClear(MilImageTmp, 0);
MIL.MbufChild2d(MilImageTmp, 0, 0, nW / 2, nH / 2, ref MimChild);
MIL.MimConvolve(MimSmall, MimChild, MIL.M_LAPLACIAN_EDGE + MIL.M_OVERSCAN_FAST);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "M_LAPLACIAN_EDGE ");
MIL.MbufFree(MimChild);
MIL.MbufChild2d(MilImageTmp, nW / 2, 0, nW / 2, nH / 2, ref MimChild);
MIL.MimConvolve(MimSmall, MimChild, MIL.M_SHARPEN + MIL.M_OVERSCAN_FAST);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "M_SHARPEN ");
MIL.MbufFree(MimChild);
MIL.MbufChild2d(MilImageTmp, 0, nH / 2, nW / 2, nH / 2, ref MimChild);
MIL.MimConvolve(MimSmall, MimChild, MIL.M_SMOOTH + MIL.M_OVERSCAN_FAST);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "M_SMOOTH ");
MIL.MbufFree(MimChild);
MIL.MbufChild2d(MilImageTmp, nW / 2, nH / 2, nW / 2, nH / 2, ref MimChild);
MIL.MimConvolve(MimSmall, MimChild, MIL.M_DERICHE_FILTER(MIL.M_SMOOTH, 50));
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "M_SMOOTH 50");
MIL.MbufFree(MimChild);
MIL.MbufFree(MimSmall);
5. 图片的开运算、闭运算、腐蚀、膨胀
MIL.MgraColor(showTmp.MilGraphContext, MIL.M_COLOR_RED);
MIL.MgraControl(showTmp.MilGraphContext, MIL.M_FONT_X_SCALE, 2.2);
MIL.MgraControl(showTmp.MilGraphContext, MIL.M_FONT_Y_SCALE, 2.2);
MIL_ID MimSmall = 0;
MIL_ID MimChild = 0;
MIL_ID MilStructElement = 0;
MIL.MbufAllocColor(MilSystem, nB, nW / 2, nH / 2, nD + MIL.M_UNSIGNED, MIL.M_PROC + MIL.M_IMAGE + MIL.M_DISP, ref MimSmall);
MIL.MimResize(MilImageTmp, MimSmall, 0.5, 0.5, MIL.M_DEFAULT);
MIL.MbufClear(MilImageTmp, 0);
MIL.MbufChild2d(MilImageTmp, 0, 0, nW / 2, nH / 2, ref MimChild);
MIL.MbufAlloc2d(MilSystem, 1, 8, 32, MIL.M_STRUCT_ELEMENT, ref MilStructElement);
MIL.MbufClear(MilStructElement, 0);
MIL.MimMorphic(MimSmall, MimChild, MilStructElement, MIL.M_OPEN, 1, MIL.M_GRAYSCALE);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "M_OPEN");
MIL.MbufFree(MilStructElement);
MIL.MbufFree(MimChild);
MIL.MbufChild2d(MilImageTmp, nW / 2, 0, nW / 2, nH / 2, ref MimChild);
MIL.MbufAlloc2d(MilSystem, 1, 8, 32, MIL.M_STRUCT_ELEMENT, ref MilStructElement);
MIL.MbufClear(MilStructElement, 0);
MIL.MimMorphic(MimSmall, MimChild, MilStructElement, MIL.M_CLOSE, 1, MIL.M_GRAYSCALE);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "M_CLOSE");
MIL.MbufFree(MilStructElement);
MIL.MbufFree(MimChild);
MIL.MbufChild2d(MilImageTmp, 0, nH / 2, nW / 2, nH / 2, ref MimChild);
MIL.MbufAlloc2d(MilSystem, 1, 8, 32, MIL.M_STRUCT_ELEMENT, ref MilStructElement);
MIL.MbufClear(MilStructElement, 0);
MIL.MimMorphic(MimSmall, MimChild, MilStructElement, MIL.M_ERODE, 1, MIL.M_GRAYSCALE);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "M_ERODE");
MIL.MbufFree(MilStructElement);
MIL.MbufFree(MimChild);
MIL.MbufChild2d(MilImageTmp, nW / 2, nH / 2, nW / 2, nH / 2, ref MimChild);
MIL.MbufAlloc2d(MilSystem, 1, 8, 32, MIL.M_STRUCT_ELEMENT, ref MilStructElement);
MIL.MbufClear(MilStructElement, 0);
MIL.MimMorphic(MimSmall, MimChild, MilStructElement, MIL.M_DILATE, 1, MIL.M_GRAYSCALE);
MIL.MgraText(showTmp.MilGraphContext, MimChild, 20, 20, "M_DILATE");
MIL.MbufFree(MilStructElement);
MIL.MbufFree(MimChild);
MIL.MbufFree(MimSmall);
以上是关于Mil学习之Mim的简单操作的主要内容,如果未能解决你的问题,请参考以下文章