NNEngine
UTextureProcessFunctionLibrary Class Reference
Inheritance diagram for UTextureProcessFunctionLibrary:
Collaboration diagram for UTextureProcessFunctionLibrary:

Static Public Member Functions

static void getImageSize (UTexture *inputTexture, FVector2D &dimensions)
 
static bool isExternal (UTexture *texture)
 
static void getInverseAffineMatFrom2Points (const FVector2D &center, const FVector2D &topCenter, const float &scalingFactor, FAffineMat2D &out_inverseAffineMat)
 
static void getInverseAffineMat (const FVector2D &center, const FVector2D &orientation, const float &size, FAffineMat2D &out_inverseAffineMat)
 
static void correctAspectRatio (const FVector2D &uvScalingFactor, const FAffineMat2D &affineMat, FAffineMat2D &correctedAffineMat)
 
static FVector2D affineTransformPoint (const FAffineMat2D &affineMat, const FVector2D &point)
 
static void affineTransformPoints (const TArray< FVector2D > &in_points, TArray< FVector2D > &out_points, const FAffineMat2D affineMat)
 
static void showImageWith2dPoints (const TArray< uint8 > &rawDataHxWxBGR, const TArray< FVector2D > &overlayPoints, const int imageWidth, const int imageHeight, const int windowSize=700, const FString windowTitle="Debug", const bool denormalizePoints=true)
 
static void showImageWith3dPoints (const TArray< uint8 > &rawDataHxWxBGR, const TArray< FVector > &overlayPoints, const int imageWidth, const int imageHeight, const int windowSize=700, const FString windowTitle="Debug", const bool denormalizePoints=true)
 
static void showImage (const TArray< uint8 > &rawDataHxWxBGR, const int imageWidth, const int imageHeight, const int windowSize=700, const FString windowTitle="Debug")
 
static void showImageFloat (const TArray< float > &rawDataHxWxBGR, const int imageWidth, const int imageHeight, const int windowSize=700, const FString windowTitle="Debug")
 
static void convertToIntImage (UPARAM(ref) TArray< uint8 > &in_rawDataHxWxBGR, TArray< int > &out_rawDataHxWxBGR, const int imageWidth, const int imageHeight)
 
static void normalizeFloatArray (UPARAM(ref) TArray< float > &in_data, TArray< float > &out_data, const float bias=0.0f, const float scalingFactor=1.0f)
 
static void normalizeFloatArrayWith3Channels (UPARAM(ref) TArray< float > &in_data, TArray< float > &out_data, const FVector bias=FVector::ZeroVector, const FVector scalingFactor=FVector(1.0f, 1.0f, 1.0f), const bool isCHW=true)
 
static UTexture2D * CreateTexture2d_Gray_Byte (const int32 width, const int32 height)
 
static UTexture2D * CreateTexture2d_Gray_Float (const int32 width, const int32 height)
 
static UTexture2D * CreateTexture2d_BGRA_Byte (const int32 width, const int32 height)
 
static UTexture2D * CreateTexture2d_RGBA_Float (const int32 width, const int32 height)
 
static void CopyByteArrayToTexture2D (const TArray< uint8 > &source_data, UPARAM(ref) UTexture2D *destination_texture2D, const bool useMultiThread=true)
 
static void CopyFloatArrayToTexture2D (const TArray< float > &source_data, UPARAM(ref) UTexture2D *destination_texture2D, const bool useMultiThread=true)
 
static void CopyByteArrayToTexture2D_RGB_To_BGRA (const TArray< uint8 > &source_data, UPARAM(ref) UTexture2D *destination_texture2D, const bool useMultiThread=true, const bool CHW_to_HWC=true)
 
static void CopyFloatArrayToTexture2D_RGB_To_RGBA (const TArray< float > &source_data, UPARAM(ref) UTexture2D *destination_texture2D, const bool useMultiThread=true, const bool CHW_to_HWC=true)
 
static void multiplyAffineTransformMatrices (const FAffineMat2D &affineMat_A, const FAffineMat2D &affineMat_B, FAffineMat2D &affineMat_C)
 

Detailed Description

Blueprint-callable static function library for image processing

Member Function Documentation

◆ affineTransformPoint()

static FVector2D UTextureProcessFunctionLibrary::affineTransformPoint ( const FAffineMat2D affineMat,
const FVector2D &  point 
)
static

Affine transform a point

Parameters
affineMatInput matrix which represents affine transform
pointPoint to be transformed
Returns
Transformed point

◆ affineTransformPoints()

static void UTextureProcessFunctionLibrary::affineTransformPoints ( const TArray< FVector2D > &  in_points,
TArray< FVector2D > &  out_points,
const FAffineMat2D  affineMat 
)
static

Affine transform points

Parameters
in_pointsPoints to be transformed
out_pointsTransformed points
affineMatInput matrix which represents affine transform

◆ convertToIntImage()

static void UTextureProcessFunctionLibrary::convertToIntImage ( UPARAM(ref) TArray< uint8 > &  in_rawDataHxWxBGR,
TArray< int > &  out_rawDataHxWxBGR,
const int  imageWidth,
const int  imageHeight 
)
static

Convert image from byte array to integer array. Works only when CustomizedOpenCv module is enabled.

Parameters
in_rawDataHxWxBGRInput image as an array of bytes whose length is (imageHeight x imageWidth x 3(BGR)).
out_rawDataHxWxBGROutput image as an array of 32-bit integers whose length is (imageHeight x imageWidth x 3(BGR)).
imageWidthThe width of the image
imageHeightThe height of the image

◆ CopyByteArrayToTexture2D()

static void UTextureProcessFunctionLibrary::CopyByteArrayToTexture2D ( const TArray< uint8 > &  source_data,
UPARAM(ref) UTexture2D *  destination_texture2D,
const bool  useMultiThread = true 
)
static

Fill Texture2D data by byte array.

Parameters
source_dataInput data copied to texture
destination_texture2DTexture to be filled
useMultiThreadWhether to use multithread to copy the data

◆ CopyByteArrayToTexture2D_RGB_To_BGRA()

static void UTextureProcessFunctionLibrary::CopyByteArrayToTexture2D_RGB_To_BGRA ( const TArray< uint8 > &  source_data,
UPARAM(ref) UTexture2D *  destination_texture2D,
const bool  useMultiThread = true,
const bool  CHW_to_HWC = true 
)
static

Fill Texture2D data by byte array while converting CHW-RGB format to HWC-BGRA format.

Parameters
source_dataInput data copied to texture. (Channel x Height x Width), RGB format.
destination_texture2DTexture to be filled. (Width x Height x Channel), BGRA format.
useMultiThreadWhether to use multithread to copy the data
CHW_to_HWCWhether to convert the image from (Channel x Height x Width) to (Width x Height x Channel) format. If false, the input data is assumed to be in (Width x Height x Channel) format.

◆ CopyFloatArrayToTexture2D()

static void UTextureProcessFunctionLibrary::CopyFloatArrayToTexture2D ( const TArray< float > &  source_data,
UPARAM(ref) UTexture2D *  destination_texture2D,
const bool  useMultiThread = true 
)
static

Fill Texture2D data by float array.

Parameters
source_dataInput data copied to texture
destination_texture2DTexture to be filled
useMultiThreadWhether to use multithread to copy the data

◆ CopyFloatArrayToTexture2D_RGB_To_RGBA()

static void UTextureProcessFunctionLibrary::CopyFloatArrayToTexture2D_RGB_To_RGBA ( const TArray< float > &  source_data,
UPARAM(ref) UTexture2D *  destination_texture2D,
const bool  useMultiThread = true,
const bool  CHW_to_HWC = true 
)
static

Fill Texture2D data by float array while converting RGB format to BGRA format.

Parameters
source_dataInput data copied to texture. (Channel x Height x Width), RGB format.
destination_texture2DTexture to be filled. (Width x Height x Channel), RGBA format.
useMultiThreadWhether to use multithread to copy the data
CHW_to_HWCWhether to convert the image from (Channel x Height x Width) to (Width x Height x Channel) format. If false, the input data is assumed to be in (Width x Height x Channel) format.

◆ correctAspectRatio()

static void UTextureProcessFunctionLibrary::correctAspectRatio ( const FVector2D &  uvScalingFactor,
const FAffineMat2D affineMat,
FAffineMat2D correctedAffineMat 
)
static

Convert the matrix of affine transform which was calculated in the scaled UV space which keeps the image's aspect ratio to the matrix in the original UV space.

Parameters
uvScalingFactorThe scaling factor of the UV of the image to keep the aspect ratio of the image. X = 1 and Y > 1 for a landscape image. X > 1 and Y = 1 for a portrait image.
affineMatInput matrix
correctedAffineMatOutput matrix

◆ CreateTexture2d_BGRA_Byte()

static UTexture2D * UTextureProcessFunctionLibrary::CreateTexture2d_BGRA_Byte ( const int32  width,
const int32  height 
)
static

Create Texture2D with 4(BGRA) color channel of byte

Parameters
widthTexture width
heightTexture height

◆ CreateTexture2d_Gray_Byte()

static UTexture2D * UTextureProcessFunctionLibrary::CreateTexture2d_Gray_Byte ( const int32  width,
const int32  height 
)
static

Create Texture2D with one color channel of byte

Parameters
widthTexture width
heightTexture height

◆ CreateTexture2d_Gray_Float()

static UTexture2D * UTextureProcessFunctionLibrary::CreateTexture2d_Gray_Float ( const int32  width,
const int32  height 
)
static

Create Texture2D with one color channel of float32

Parameters
widthTexture width
heightTexture height

◆ CreateTexture2d_RGBA_Float()

static UTexture2D * UTextureProcessFunctionLibrary::CreateTexture2d_RGBA_Float ( const int32  width,
const int32  height 
)
static

Create Texture2D with 4(ABGR) color channel of float32

Parameters
widthTexture width
heightTexture height

◆ getImageSize()

static void UTextureProcessFunctionLibrary::getImageSize ( UTexture *  inputTexture,
FVector2D &  dimensions 
)
static

Get the width and the height of a texture

Parameters
inputTextureInput image
dimensionsWidth and height

◆ getInverseAffineMat()

static void UTextureProcessFunctionLibrary::getInverseAffineMat ( const FVector2D &  center,
const FVector2D &  orientation,
const float &  size,
FAffineMat2D out_inverseAffineMat 
)
static

Calculate the matrix of affine transform to crop image

Parameters
centerThe center of the image after cropping
orientationThe normalized vector from the center of the top edge of the image after cropping to the center of the image after cropping. For example, (0, 1) means no rotation, (1, 0) means 90 degree rotation.
sizeThe side length of cropped square image
out_inverseAffineMatThe matrix which transforms the cropped image to the original image

◆ getInverseAffineMatFrom2Points()

static void UTextureProcessFunctionLibrary::getInverseAffineMatFrom2Points ( const FVector2D &  center,
const FVector2D &  topCenter,
const float &  scalingFactor,
FAffineMat2D out_inverseAffineMat 
)
static

Calculate the matrix of affine transform to crop image

Parameters
centerThe center of the image after cropping
topCenterThe center of the top edge of the image after cropping
scalingFactorThe scaling factor of the cropping.
out_inverseAffineMatThe matrix which transforms the cropped image to the original image

◆ isExternal()

static bool UTextureProcessFunctionLibrary::isExternal ( UTexture *  texture)
static

Check if the sampler type of the texture is "External"

Parameters
TextureInput texture
Returns
Whether the sampler type of the texture is "External"

◆ multiplyAffineTransformMatrices()

static void UTextureProcessFunctionLibrary::multiplyAffineTransformMatrices ( const FAffineMat2D affineMat_A,
const FAffineMat2D affineMat_B,
FAffineMat2D affineMat_C 
)
static

C * x = B * ( A * x )

◆ normalizeFloatArray()

static void UTextureProcessFunctionLibrary::normalizeFloatArray ( UPARAM(ref) TArray< float > &  in_data,
TArray< float > &  out_data,
const float  bias = 0.0f,
const float  scalingFactor = 1.0f 
)
static

Add and multiply values to float array. out_data = scalingFactor * (in_data + bias)

Parameters
in_dataInput float array.
out_dataOutput float array.
biasThe value added to each array element. For example, if this value is -0.5, data in [0.0, 1.0] is converted to [-0.5, 0.5]. This addition is performed before the multiplication of the scalingFactor.
scalingFactorThe value multiplied to each array element. For example, if this value is 2.0, data in [0, 1.0] is converted to [0.0, 2.0]. This multiplication is performed after the addition of the bias.

◆ normalizeFloatArrayWith3Channels()

static void UTextureProcessFunctionLibrary::normalizeFloatArrayWith3Channels ( UPARAM(ref) TArray< float > &  in_data,
TArray< float > &  out_data,
const FVector  bias = FVector::ZeroVector,
const FVector  scalingFactor = FVector(1.0f, 1.0f, 1.0f),
const bool  isCHW = true 
)
static

Add and multiply values to float array. The data is assumed to have 3 channels in (Channel x Height x Width) format or (Width x Height x Channel) format. out_data = scalingFactor * (in_data + bias)

Parameters
in_dataInput float array.
out_dataOutput float array.
biasThe value added to each array element. XYZ corresponds to 3 channels of the data.
scalingFactorThe value multiplied to each array element. XYZ corresponds to 3 channels of the data.
isCHWWhether the input data is in (Channel x Height x Width) format or (Width x Height x Channel) format.

◆ showImage()

static void UTextureProcessFunctionLibrary::showImage ( const TArray< uint8 > &  rawDataHxWxBGR,
const int  imageWidth,
const int  imageHeight,
const int  windowSize = 700,
const FString  windowTitle = "Debug" 
)
static

Visualize the image. Works only on Windows and when CustomizedOpenCv module is enabled.

Parameters
rawDataHxWxBGRInput image as an array of byte whose length is (imageHeight x imageWidth x 3(BGR)).
imageWidthThe width of the input image
imageHeightThe height of the input image
windowSizeThe size of the output window
windowTitleThe title of the output window

◆ showImageFloat()

static void UTextureProcessFunctionLibrary::showImageFloat ( const TArray< float > &  rawDataHxWxBGR,
const int  imageWidth,
const int  imageHeight,
const int  windowSize = 700,
const FString  windowTitle = "Debug" 
)
static

Visualize the image. Works only on Windows and when CustomizedOpenCv module is enabled.

Parameters
rawDataHxWxBGRInput image as an array of float whose length is (imageHeight x imageWidth x 3(BGR)).
imageWidthThe width of the input image
imageHeightThe height of the input image
windowSizeThe size of the output window
windowTitleThe title of the output window

◆ showImageWith2dPoints()

static void UTextureProcessFunctionLibrary::showImageWith2dPoints ( const TArray< uint8 > &  rawDataHxWxBGR,
const TArray< FVector2D > &  overlayPoints,
const int  imageWidth,
const int  imageHeight,
const int  windowSize = 700,
const FString  windowTitle = "Debug",
const bool  denormalizePoints = true 
)
static

Visualize the image while overlaying points. Works only on Windows and when CustomizedOpenCv module is enabled.

Parameters
rawDataHxWxBGRInput image as an array of bytes whose length is (imageHeight x imageWidth x 3(BGR)).
overlayPointsPoints to be drawn on the input image
imageWidthThe width of the input image
imageHeightThe height of the input image
windowSizeThe size of the output window
windowTitleThe title of the output window
denormalizePointsWhether to multiply the image width and height to the point coordinates

◆ showImageWith3dPoints()

static void UTextureProcessFunctionLibrary::showImageWith3dPoints ( const TArray< uint8 > &  rawDataHxWxBGR,
const TArray< FVector > &  overlayPoints,
const int  imageWidth,
const int  imageHeight,
const int  windowSize = 700,
const FString  windowTitle = "Debug",
const bool  denormalizePoints = true 
)
static

Visualize the image while overlaying points. Works only on Windows and when CustomizedOpenCv module is enabled.

Parameters
rawDataHxWxBGRInput image as an array of bytes whose length is (imageHeight x imageWidth x 3(BGR)).
overlayPointsPoints to be drawn on the input image
imageWidthThe width of the input image
imageHeightThe height of the input image
windowSizeThe size of the output window
windowTitleThe title of the output window
denormalizePointsWhether to multiply the image width and height to the point coordinates