Hit-and-Miss Transform Code Snippet

This code snippet shows how to highlight the left corner of a rhombus by means of a Hit-and-Miss operation.

C++

#include <eVision/EasyImage/EasyImage.h>
using namespace eVision;
// Images constructor
EImageBW8 srcImage;
EImageBW8 dstImage;
// ...
// Create and define a Hit-and-Miss kernel
// corresponding to the left corner of a rhombus
EHitAndMissKernel leftCorner(-1, -1, 1, 1);
// Left column of the kernel
leftCorner.SetValue(-1, 0, EHitAndMissValue_Background);
// Middle column of the kernel
leftCorner.SetValue(0, -1, EHitAndMissValue_Background);
leftCorner.SetValue(0, 0, EHitAndMissValue_Foreground);
leftCorner.SetValue(0, 1, EHitAndMissValue_Background);
// Right column of the kernel
leftCorner.SetValue(1, -1, EHitAndMissValue_Foreground);
leftCorner.SetValue(1, 0, EHitAndMissValue_Foreground);
leftCorner.SetValue(1, 1, EHitAndMissValue_Foreground);
// Source and destination images must have the same size
dstImage.SetSize(&srcImage);
// Apply the Hit-and-Miss kernel
EasyImage::HitAndMiss(&srcImage, &dstImage, leftCorner);

C#

using eVision;
// Images constructor
EImageBW8 srcImage = new EImageBW8();
EImageBW8 dstImage = new EImageBW8();
// ...
// Create and define a Hit-and-Miss kernel
// corresponding to the left corner of a rhombus
EHitAndMissKernel leftCorner = new EHitAndMissKernel(-1, -1, 1, 1);
// Left column of the kernel
leftCorner.SetValue(-1, 0, EHitAndMissValue.Background);
// Middle column of the kernel
leftCorner.SetValue(0, -1, EHitAndMissValue.Background);
leftCorner.SetValue(0, 0, EHitAndMissValue.Foreground);
leftCorner.SetValue(0, 1, EHitAndMissValue.Background);
// Right column of the kernel
leftCorner.SetValue(1, -1, EHitAndMissValue.Foreground);
leftCorner.SetValue(1, 0, EHitAndMissValue.Foreground);
leftCorner.SetValue(1, 1, EHitAndMissValue.Foreground);
// Source and destination images must have the same size
dstImage.SetSize(srcImage);
// Apply the Hit-and-Miss kernel
EasyImage.HitAndMiss(srcImage, dstImage, leftCorner);

Python

from eVision import EImageBW8, EasyImage, EHitAndMissKernel, EHitAndMissValue
# Images constructor
src_image = EImageBW8()
dst_image = EImageBW8()
# ...
# Create and define a Hit-and-Miss kernel
# corresponding to the left corner of a rhombus
leftCorner = EHitAndMissKernel(-1, -1, 1, 1)
# Left column of the kernel
leftCorner.SetValue(-1, 0, EHitAndMissValue.Background)
# Middle column of the kernel
leftCorner.SetValue(0, -1, EHitAndMissValue.Background)
leftCorner.SetValue(0, 0, EHitAndMissValue.Foreground)
leftCorner.SetValue(0, 1, EHitAndMissValue.Background)
# Right column of the kernel
leftCorner.SetValue(1, -1, EHitAndMissValue.Foreground)
leftCorner.SetValue(1, 0, EHitAndMissValue.Foreground)
leftCorner.SetValue(1, 1, EHitAndMissValue.Foreground)
# Source and destination images must have the same size
dst_image.SetSize(src_image)
# Apply the Hit-and-Miss kernel
EasyImage.HitAndMiss(src_image, dst_image, leftCorner)