Intel® Integrated Performance Primitives (Intel® IPP) Developer Guide and Reference

ID 790148
Date 10/31/2024
Public
Document Table of Contents

BinToGray, GrayToBin

Converts a bitonal image to a grayscale image and vice versa.

Syntax

Case 1: Conversion of a bitonal image to a grayscale image

IppStatus ippiBinToGray_1u<dstDataType>_C1R(const Ipp8u* pSrc, int srcStep, int srcBitOffset, Ipp<dstDataType>* pDst, int dstStep, IppiSize roiSize, Ipp<dstDataType> loVal, Ipp<dstDataType> hiVal);

Supported values for dstDataType:

8u 16u 16s 32f

Case 2: Conversion of a grayscale image to a bitonal image

IppStatus ippiGrayToBin_<srcDataType>1u_C1R(const Ipp<srcDataType>* pSrc, int srcStep, Ipp8u* pDst, int dstStep, int dstBitOffset, IppiSize roiSize, Ipp<sourceDataType> threshold);

Supported values for srcDataType:

8u 16u 16s 32f

Include Files

ippi.h

Domain Dependencies

Headers: ippcore.h, ippvm.h, ipps.h

Libraries: ippcore.lib, ippvm.lib, ipps.lib

Parameters

pSrc

Pointer to the source image ROI.

srcStep

Distance, in bytes, between the starting points of consecutive lines in the source image.

srcBitOffset

Offset, in bits, from the first byte of the source image row.

pDst

Pointer to the destination image ROI.

dstStep

Distance, in bytes, between the starting points of consecutive lines in the destination image.

dstBitOffset

Offset, in bits, from the first byte of the destination image row.

roiSize

Size of the ROI in pixels.

loVal

Destination value that corresponds to the "0" value of the corresponding source element.

hiVal

Destination value that corresponds to the "1" value of the corresponding source element.

threshold

Threshold level.

Description

These functions operate with ROI.

The ippiBinToGray function converts a bitonal image to grayscale, and the ippiGrayToBin function converts a grayscale image to bitonal. The data type of the bitonal image is 8u. It means that each byte consists of eight consecutive pixels of the image (1 bit per pixel). You need to specify the start position of the ROI buffer in the srcBitOffset and dstBitOffset parameters.

The ippiBinToGray function transforms each bit of the source image into the pixel of the destination image in the following way:

  • If the input pixel is equal to 0, the corresponding output pixel is set to loVal.
  • If the input pixel is equal to 1, the corresponding output pixel is set to hiVal.

The ippiGrayToBin function transforms each pixel of the source image into the bit of the destination image in the following way:

  • If the input pixel is more than the threshold value, the corresponding output bit is set to 1.
  • If the input pixel is less than, or equal to the threshold value, the corresponding output bit is set to 0.

Return Values

ippStsNoErr

Indicates no error.

ippStsNullPtrErr

Indicates an error when any of the specified pointers is NULL.

ippStsStepErr

Indicates an error when the srcStep or dstStep value is less than, or equal to zero.

ippStsSizeErr

Indicates an error when:

  • roiSize has a zero or negative value
  • the srcBitOffset or dstBitOffset value is less than zero