MediaPipeTasksCommon Framework Reference

MPMask

final class MPMask: Sendable, Equatable

Single-channel MediaPipe segmentation mask supporting conversion between 0...255 and 0.0...1.0 representations.

  • Creates a .float32 mask by copying width * height elements from float32Data.

    Declaration

    Swift

    convenience init(float32Data: UnsafePointer<Float>, width: Int, height: Int)
  • Creates a .uInt8 mask by copying width * height elements from uint8Data.

    Declaration

    Swift

    convenience init(uint8Data: UnsafePointer<UInt8>, width: Int, height: Int)
  • Primary native data type of the segmentation mask.

    Declaration

    Swift

    final let dataType: MaskDataType
  • Mask values in 0.0...1.0.

    When dataType is .uInt8, each element is scaled by 1.0 / 255.0.

    Declaration

    Swift

    final var float32Elements: [Float] { get }
  • Height of the segmentation mask in pixels.

    Declaration

    Swift

    final let height: Int
  • Total number of pixels in the mask (width * height).

    Declaration

    Swift

    final let pixelCount: Int
  • Mask values in 0...255.

    When dataType is .float32, each element is clamped to 0.0...1.0 (mapping NaN to 0) and scaled by 255.0.

    Declaration

    Swift

    final var uint8Elements: [UInt8] { get }
  • Width of the segmentation mask in pixels.

    Declaration

    Swift

    final let width: Int
  • Invokes body with an UnsafeBufferPointer<Float> covering all width * height pixels.

    Declaration

    Swift

    final func withUnsafeFloat32BufferPointer<Result>(_ body: (UnsafeBufferPointer<Float>) throws -> Result) rethrows -> Result
  • Invokes body with an UnsafeBufferPointer<UInt8> covering all width * height pixels.

    Declaration

    Swift

    final func withUnsafeUInt8BufferPointer<Result>(_ body: (UnsafeBufferPointer<UInt8>) throws -> Result) rethrows -> Result