SubImage(HObject imageMinuend, HObject imageSubtrahend, out HObject imageSub, HTuple mult, HTuple add)

公式

x1=imageMinuend此行此列的灰度
x2=imageSubtrahend此行此列的灰度
则imageSub此行此列的灰度为;(x1-x2)*mult+add

溢出裁剪

以byte图为例,小于0,为0;大于255,为255

源码一

   

private void butTemp_Click(object sender, EventArgs e)
         {
             var img1 = WHCSHalCon.Base.CreateByteImage(new byte[] { 0 }, 1);
             var img2 = WHCSHalCon.Base.CreateByteImage(new byte[] { 255 }, 1);
             HObject img3;
             HOperatorSet.SubImage(img2, img1, out img3, 2, 0);
             byte[] b1 = WHCSHalCon.Base.ByteImageToArr(img3);
         }


结果为255

源码二

 

private void butTemp_Click(object sender, EventArgs e)
         {
             var img1 = WHCSHalCon.Base.CreateByteImage(new byte[] { 0 }, 1);
             var img2 = WHCSHalCon.Base.CreateByteImage(new byte[] { 255 }, 1);
             HObject img3;
             HOperatorSet.SubImage(img1, img2, out img3, 2, 0);
             byte[] b1 = WHCSHalCon.Base.ByteImageToArr(img3);
       
         }


结果为0

注意事项

imageMinuend和imageSubtrahend的CountObj和CountChannel必须相同。否则会崩溃

测试环境

Win7 VS2022 Halcon12