Mil学习之图片的ROI获取及半透膜掩膜效果着色
Posted Thomas会写字
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mil学习之图片的ROI获取及半透膜掩膜效果着色相关的知识,希望对你有一定的参考价值。
只对地球部分着色
用到Blob Buf Image几个部分
MIL_ID MImageSrc = 0;
MIL_ID MImageMask = 0;
MIL_ID MImageGray = 0;
ReadColorImage("C:\\\\Users\\\\kakie\\\\Desktop\\\\Image\\\\75.bmp", ref MImageSrc);
MIL.MbufClone(MImageSrc, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT, ref MImageMask);
// 准备画布
if (MilImageTmp != 0)
MIL.MbufFree(MilImageTmp);
if (showTmp != null) showTmp.MilFree();
int nW = (int)MIL.MbufInquire(MImageSrc, MIL.M_SIZE_X, MIL.M_NULL);
int nH = (int)MIL.MbufInquire(MImageSrc, MIL.M_SIZE_Y, MIL.M_NULL);
MIL.MbufAllocColor(MilSystem, 3, nW * 2, nH, 8 + MIL.M_UNSIGNED, MIL.M_PROC + MIL.M_IMAGE + MIL.M_DISP, ref MilImageTmp);
MIL.MbufAllocColor(MilSystem, 1, nW, nH, 8 + MIL.M_UNSIGNED, MIL.M_PROC + MIL.M_IMAGE + MIL.M_DISP, ref MImageGray);
showTmp = new MilGraphicShow(MilSystem, MilDisplayTmp, MilImageTmp, panel2);
showTmp.DispFit();
// 附上原图
MIL_ID MimgClild = 0;
MIL.MbufChild2d(MilImageTmp, 0, 0, nW, nH, ref MimgClild);
MIL.MbufCopy(MImageSrc, MimgClild);
MIL.MbufFree(MimgClild);
// 转黑白图处理 转后地球是黑色的
MIL.MimConvert(MImageSrc, MImageGray, MIL.M_RGB_TO_L);
MIL.MimBinarize(MImageGray, MImageGray, MIL.M_FIXED + MIL.M_LESS_OR_EQUAL, 50, MIL.M_NULL);
// Blob Blob是处理不为0的部分 这里填充黑色区域中的白色孔洞
MIL_ID MilBlobCtx = MIL.M_NULL;
MIL_ID MilBlobResCtx = MIL.M_NULL;
MIL.MblobAllocFeatureList(MilSystem, ref MilBlobCtx);
MIL.MblobAllocResult(MilSystem, ref MilBlobResCtx);
MIL.MblobSelectFeature(MilBlobCtx, MIL.M_AREA);
MIL.MblobCalculate(MImageGray, MIL.M_NULL, MilBlobCtx, MilBlobResCtx);
MIL_INT nNum = 0;
MIL.MblobGetNumber(MilBlobResCtx, ref nNum);
double[] dRes = new double[nNum];
MIL.MblobGetResult(MilBlobResCtx, MIL.M_AREA, dRes);
double dMax = 0;
for (int i = 0; i < nNum; i++)
if (dRes[i] > dMax)
dMax = dRes[i];
MIL.MblobSelect(MilBlobResCtx, MIL.M_EXCLUDE, MIL.M_AREA, MIL.M_LESS, dMax, MIL.M_NULL);
MIL.MblobFill(MilBlobResCtx, MImageGray, MIL.M_EXCLUDED_BLOBS, 0);
// 反转图片 转后地球是白色的
MIL.MimBinarize(MImageGray, MImageGray, MIL.M_FIXED + MIL.M_LESS_OR_EQUAL, 50, MIL.M_NULL);
MIL.MblobCalculate(MImageGray, MIL.M_NULL, MilBlobCtx, MilBlobResCtx);
nNum = 0;
MIL.MblobGetNumber(MilBlobResCtx, ref nNum);
dRes = new double[nNum];
MIL.MblobGetResult(MilBlobResCtx, MIL.M_AREA, dRes);
dMax = 0;
for (int i = 0; i < nNum; i++)
if (dRes[i] > dMax)
dMax = dRes[i];
MIL.MblobSelect(MilBlobResCtx, MIL.M_EXCLUDE, MIL.M_AREA, MIL.M_LESS, dMax, MIL.M_NULL);
MIL.MblobFill(MilBlobResCtx, MImageGray, MIL.M_EXCLUDED_BLOBS, 0);
MIL.MblobFree(MilBlobResCtx);
MIL.MblobFree(MilBlobCtx);
// 给 Mask 着色
MIL.MbufClear(MImageMask, MIL.M_COLOR_RED);
MIL.MbufChildColor(MImageMask, MIL.M_RED, ref MimgClild);
MIL.MimArith(MimgClild, MImageGray, MimgClild, MIL.M_AND);
MIL.MbufFree(MimgClild);
MIL.MbufChildColor(MImageMask, MIL.M_GREEN, ref MimgClild);
MIL.MimArith(MimgClild, MImageGray, MimgClild, MIL.M_AND);
MIL.MbufFree(MimgClild);
MIL.MbufChildColor(MImageMask, MIL.M_BLUE, ref MimgClild);
MIL.MimArith(MimgClild, MImageGray, MimgClild, MIL.M_AND);
MIL.MbufFree(MimgClild);
MIL.MbufChild2d(MilImageTmp, nW, 0, nW, nH, ref MimgClild);
int Alpha = 100;
MIL.MimArithMultiple(MImageSrc, 256 - Alpha, MImageMask, Alpha, 256, MimgClild, MIL.M_MULTIPLY_ACCUMULATE_2, MIL.M_DEFAULT);
MIL.MbufFree(MimgClild);
以上是关于Mil学习之图片的ROI获取及半透膜掩膜效果着色的主要内容,如果未能解决你的问题,请参考以下文章
Mil学习之 MimStatCalculate 图片信息统计