ImageDev

Cooccurrence2d

Provides texture indicators, also known as Haralick features, based on the computation of co-occurrence matrix.

Access to parameter description

This algorithm provides some information regarding the texture by performing the computation of a co-occurrence matrix. It allows the classification of pairs of pixels by their gray level, along a directional offset $(dx,dy)$.
The co-occurrence matrix components are given by $$ M(i,j)=number\left(\{x,y\}/(I(x,y)=i)\cap(I(x+dx,y+dy)=j)\right) $$ where $I(x,y)$ is the image gray level for $(x,y)$ coordinates.

This formulation means that for a given pair $(i,j)$, $M(i,j)$ contains the number of pixels verifying $I(x,y)=i$ and $I(x+dx,y+dy)=j$.

This matrix is made symmetric and normalized such as $$ \forall(i,j),M(i,j)=M(j,i) ~\mbox{and} \sum_{i,j=1}^{N}M(i,j)=1 $$ These operations are independent of the image size and reveal some properties on a direction and its symmetry.
Thirteen indicators are computed from this matrix:
In addition, this algorithm returns the number of image pixels used for computation in the result object.

References
R.Haralick , K.Shanmugam & I.Dinstein "Textural features for image classification". IEEE Transactions on Systems, Man, and Cybernetics. vol. 3, no. 6, pp 610-621, Oct. 1973.

See also

Function Syntax

This function returns outputMeasurement.
// Function prototype
CoocurrrenceMsr::Ptr cooccurrence2d( std::shared_ptr< iolink::ImageView > inputImage, std::shared_ptr< iolink::ImageView > inputMaskImage, int32_t offsetX, int32_t offsetY, CoocurrrenceMsr::Ptr outputMeasurement = nullptr );
This function returns outputMeasurement.
// Function prototype.
cooccurrence_2d(input_image: idt.ImageType,
                input_mask_image: idt.ImageType,
                offset_x: int = 1,
                offset_y: int = 0,
                output_measurement: Union[Any, None] = None) -> CoocurrrenceMsr
This function returns outputMeasurement.
// Function prototype.
public static CoocurrrenceMsr
Cooccurrence2d( IOLink.ImageView inputImage,
                IOLink.ImageView inputMaskImage,
                Int32 offsetX = 1,
                Int32 offsetY = 0,
                CoocurrrenceMsr outputMeasurement = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral nullptr
input
inputMaskImage
The binary mask image where co-occurrence is computed. If it equals null, computations are performed on all pixels of the input image. This image must have the same dimensions as the input image. Image Binary nullptr
input
offsetX
The X offset defining the co-occurrence vector. Int32 Any value 1
input
offsetY
The Y offset defining the co-occurrence vector. Int32 Any value 0
output
outputMeasurement
The output measurement result object containing the haralick features. CoocurrrenceMsr nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input image. image Binary, Label, Grayscale or Multispectral None
input
input_mask_image
The binary mask image where co-occurrence is computed. If it equals null, computations are performed on all pixels of the input image. This image must have the same dimensions as the input image. image Binary None
input
offset_x
The X offset defining the co-occurrence vector. int32 Any value 1
input
offset_y
The Y offset defining the co-occurrence vector. int32 Any value 0
output
output_measurement
The output measurement result object containing the haralick features. CoocurrrenceMsr None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral null
input
inputMaskImage
The binary mask image where co-occurrence is computed. If it equals null, computations are performed on all pixels of the input image. This image must have the same dimensions as the input image. Image Binary null
input
offsetX
The X offset defining the co-occurrence vector. Int32 Any value 1
input
offsetY
The Y offset defining the co-occurrence vector. Int32 Any value 0
output
outputMeasurement
The output measurement result object containing the haralick features. CoocurrrenceMsr null

Object Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );
auto polystyrene_mask = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene_mask.vip" );

Cooccurrence2d cooccurrence2dAlgo;
cooccurrence2dAlgo.setInputImage( polystyrene );
cooccurrence2dAlgo.setInputMaskImage( polystyrene_mask );
cooccurrence2dAlgo.setOffsetX( 1 );
cooccurrence2dAlgo.setOffsetY( 0 );
cooccurrence2dAlgo.execute();

std::cout << "pixelCount: " << cooccurrence2dAlgo.outputMeasurement()->pixelCount( 0 ) ;
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))
polystyrene_mask = imagedev.read_vip_image(imagedev_data.get_image_path("polystyrene_mask.vip"))

cooccurrence_2d_algo = imagedev.Cooccurrence2d()
cooccurrence_2d_algo.input_image = polystyrene
cooccurrence_2d_algo.input_mask_image = polystyrene_mask
cooccurrence_2d_algo.offset_x = 1
cooccurrence_2d_algo.offset_y = 0
cooccurrence_2d_algo.execute()

print("pixelCount: ", str(cooccurrence_2d_algo.output_measurement.pixel_count(0)))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );
ImageView polystyrene_mask = Data.ReadVipImage( @"Data/images/polystyrene_mask.vip" );

Cooccurrence2d cooccurrence2dAlgo = new Cooccurrence2d
{
    inputImage = polystyrene,
    inputMaskImage = polystyrene_mask,
    offsetX = 1,
    offsetY = 0
};
cooccurrence2dAlgo.Execute();

Console.WriteLine( "pixelCount: " + cooccurrence2dAlgo.outputMeasurement.pixelCount( 0 ) );

Function Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );
auto polystyrene_mask = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene_mask.vip" );

auto result = cooccurrence2d( polystyrene, polystyrene_mask, 1, 0 );

std::cout << "pixelCount: " << result->pixelCount( 0 ) ;
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))
polystyrene_mask = imagedev.read_vip_image(imagedev_data.get_image_path("polystyrene_mask.vip"))

result = imagedev.cooccurrence_2d(polystyrene, polystyrene_mask, 1, 0)

print("pixelCount: ", str(result.pixel_count(0)))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );
ImageView polystyrene_mask = Data.ReadVipImage( @"Data/images/polystyrene_mask.vip" );

CoocurrrenceMsr result = Processing.Cooccurrence2d( polystyrene, polystyrene_mask, 1, 0 );

Console.WriteLine(  "pixelCount: " + result.pixelCount( 0 )  );