IPSDK 0.2
IPSDK : Image Processing Software Development Kit
HitAndMiss2dImg algorithmSee full documentation
imagehitAndMiss2dImg (inBinImg,inForegroundSEXY,inBackgroundSEXY)

Detailed Description

Look for particular patterns of foreground and background given as structuring elements.

The Hit and Miss, also known as Hit or Miss, is a binary morphological operation used to find a particular pattern. This algorithm generates a binary image where pixels with the value 1 (or true) match the pattern given by the foreground and background structuring elements.

The foreground structuring element contains relative coordinates in the current pixel neighbourhood whith an intensity of 1, whereas the background structuring element determines the pixels that must have an intensity of 0. If a pixel can indefferently equal 0 or 1, its coordinate is not specified. Obviously, a pixel coordinate can not appear in both structuring elements.

The figure below illustrate an example where two patterns can be accepted by the algorithm. The object must describe a 3x3 cross but allows the top-right neigbhour to either belong to the foreground or the background since it is absent in both structuring elements.

hitAndMiss2dImg_illustration

Here is the result of the hit and miss operation applied to a binary input image (we are here looking for top left corners) :

hitAndMiss2dImg_illustration
See also
https://en.wikipedia.org/wiki/Hit-or-miss_transform
https://homepages.inf.ed.ac.uk/rbf/HIPR2/hitmiss.htm

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLBasicMorphology as morpho

Code Example

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# Fill the structuring element, we want the
# following foreground ('X' are ignored pixels) :
# X X X X
# X 1 1 1
# X 1 1 1
foregroundSE = PyIPSDK.emptySEXYInfo()
foregroundSE.insert(0, 0)
foregroundSE.insert(1, 0)
foregroundSE.insert(2, 0)
foregroundSE.insert(0, 1)
foregroundSE.insert(1, 1)
foregroundSE.insert(2, 1)
# Fill the structuring element, we want the
# following background ('X' are ignored pixels) :
# 0 0 0
# 0 X X
# 0 X X
backgroundSE = PyIPSDK.emptySEXYInfo()
backgroundSE.insert(-1, -1)
backgroundSE.insert(0, -1)
backgroundSE.insert(1, -1)
backgroundSE.insert(-1, 0)
backgroundSE.insert(-1, 1)
# Compute operation on the input image
# With the combination of the 2 structuring elements,
# the algorithm will look for the following pattern
# 0 0 0 0
# 0 1 1 1
# 0 1 1 1
outImg = morpho.hitAndMiss2dImg(inImg, foregroundSE, backgroundSE);

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLBasicMorphology/Processor/HitAndMiss2dImg/HitAndMiss2dImg.h>

Code Example

// opening input image
ImagePtr pInBinImg = loadTiffImageFile(inputImgPath);
// Create an empty structuring element to describe the desired foreground
// Fill the structuring element, we want the
// following foreground ('X' are ignored pixels) :
// X X X X
// X 1 1 1
// X 1 1 1
pForegroundSE->insert(0, 0);
pForegroundSE->insert(1, 0);
pForegroundSE->insert(2, 0);
pForegroundSE->insert(0, 1);
pForegroundSE->insert(1, 1);
pForegroundSE->insert(2, 1);
// Create an empty structuring element to describe the desired background
// Fill the structuring element, we want the
// following background ('X' are ignored pixels) :
// 0 0 0
// 0 X X
// 0 X X
pBackgroundSE->insert(-1, -1);
pBackgroundSE->insert(0, -1);
pBackgroundSE->insert(1, -1);
pBackgroundSE->insert(-1, 0);
pBackgroundSE->insert(-1, 1);
// Compute operation on the input image
// With the combination of the 2 structuring elements,
// the algorithm will look for the following pattern
// 0 0 0 0
// 0 1 1 1
// 0 1 1 1
ImagePtr pOutImg = hitAndMiss2dImg(pInBinImg, pForegroundSE, pBackgroundSE);