IPSDK 0.2
IPSDK : Image Processing Software Development Kit
shortestPath,shortestPathList = ridgeLine2dImg (inImg,inPropagationAxis,inPropagationDirection)
shortestPath,shortestPathList = ridgeLine2dImg (inImg,inOptMaskImg,inPropagationAxis,inPropagationDirection)
shortestPath,shortestPathList = ridgeLine2dImg (inImg,inPropagationAxis,inPropagationDirection,nbIter)
shortestPath,shortestPathList = ridgeLine2dImg (inImg,inOptMaskImg,inPropagationAxis,inPropagationDirection,nbIter)
Pixels2dridgeLine2dImg (inImg,inPropagationAxis,inPropagationDirection,outShortestPathImg,outDistanceMap,outPathMap)
Pixels2dridgeLine2dImg (inImg,inOptMaskImg,inPropagationAxis,inPropagationDirection,outShortestPathImg,outDistanceMap,outPathMap)
Pixels2dridgeLine2dImg (inImg,inPropagationAxis,inPropagationDirection,nbIter,outShortestPathImg,outDistanceMap,outPathMap)
Pixels2dridgeLine2dImg (inImg,inOptMaskImg,inPropagationAxis,inPropagationDirection,nbIter,outShortestPathImg,outDistanceMap,outPathMap)

Detailed Description

Computes the shortest path from one border to its opposite, given distance ponderation map.

The 2D ridge line algorithm allows to compute the shortest path to cross an image along the x or y axis. It is also possible to specify the propagation direction. This direction can be direct (from left to right or from top to bottom) or reverse (from right to left or from bottom to top).

The distance, to reach a pixel, between one of its 8-neighbors is given by its intensity. More the intensity will be high, more the access to the pixel will be unfavourable. This means that the algorithm tries to find a path through the darkest pixels.

This algorithm returns :

The calculation time can be drastically reduced by specifying a number of iterations. If this parameter is higher than 0, the algorithm will stop before converging to the final result. Although the result will be an approximation of the shortest path, it will stay close to the eact result.

Finally, it is possible to specify a propagation area by passing an additional mask as parameter.

Here is an example of the ridge line algorithm output :

ridgeLine2dImg_example.png

In that particular case we can find two interesting paths. One at the middle of the image and one at the bottom. Within the previous figure the shortest path is the interface between the background and the object. It's possible to get the interface between the two materials by using a mask restricting the propagation to the bottom of the image.

Here is a mask use case :

ridgeLine2dImg_exampleMask.png

The distance for each pixel of the shortest path is given by the intensity field of the Pixel2d data item. It is also possible to obtain the shortest path length for slice (z, c, t) thanks to the function computeShortestPathLength.

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLAdvancedMorphology as advmorpho

Code Example

# opening of input images
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# opening of input mask
inOptMaskImg = PyIPSDK.loadTiffImageFile(inputOptMaskPath)
# Ridge Line 2d computation
outShortestPathImg, outPlanIndexedPixels = advmorpho.ridgeLine2dImg(inImg, inOptMaskImg, PyIPSDK.ePropagationAxis.ePA_X, PyIPSDK.ePropagationDirection.ePD_Direct)
firstShortestPath = PyIPSDK.toPyDict(outPlanIndexedPixels)[(0, 0, 0)]
print("First shortest path", firstShortestPath)

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLAdvancedMorphology/Processor/RidgeLine2dImg/RidgeLine2dImg.h>
#include <IPSDKIPL/IPSDKIPLAdvancedMorphology/Processor/RidgeLine2dImg/RidgeLine2dImgInitPassLvl3.h>
#include <IPSDKIPL/IPSDKIPLAdvancedMorphology/Processor/RidgeLine2dImg/RidgeLine2dImgDirectPassLvl3.h>
#include <IPSDKIPL/IPSDKIPLAdvancedMorphology/Processor/RidgeLine2dImg/RidgeLine2dImgReversePassLvl3.h>

Code Example

// opening input image
ImagePtr pInImg = loadTiffImageFile(inputImgPath);
// opening optional mask image
ImagePtr pOptMaskImg = loadTiffImageFile(inputOptMaskPath);
// compute distance map on input image without mask
RidgeLine2dResult rl2d_res = ridgeLine2dImg(pInImg, ePropagationAxis::ePA_X, ePropagationDirection::ePD_Direct);
// compute distance map on input image with mask
RidgeLine2dResult rl2d_res_withMask = ridgeLine2dImg(pInImg, pOptMaskImg, ePropagationAxis::ePA_X, ePropagationDirection::ePD_Direct);
// retrieve computed image and the list of pixels
const ImagePtr pShortestPathImg = rl2d_res._pShortestPath;
const PlanIndexedPixels2dPtr pShortestPathList = rl2d_res._pShortestPathList;
// computes the length of the shortest path
ipReal64 lengthShortestPath = computeShortestPathLength(pShortestPathList, 0, 0, 0);