Skip to content

[Utilities] Conversion of ISO/IEC 19794-2 to nbis-py compatible #60

@umar-anzar

Description

@umar-anzar

Manipulating ISO/IEC 19794-2 Fingerprint Minutiae Record (FMR) data to make it compatible with the NBIS (NIST Biometric Image Software)

def strip_iso_header_metadata(fmr_data: bytes) -> bytes:
    """
    Removes Resolution Y, Finger Count, and Reserved bytes from the ISO header.
    Relocates Fingerprint Quality to the correct offset for NBIS compatibility.
    """
    fmr_mutable = bytearray(fmr_data)
    
    # Move 'Fingerprint Quality' from offset 26 to offset 20
    # In the original ISO spec, offsets 20-23 contain Resolution Y and Finger Count
    fmr_mutable[20:21] = fmr_mutable[26:27]

    # Slice the array to remove the redundant bytes between the new Quality 
    # position and the start of the minutiae data
    return bytes(fmr_mutable[:25] + fmr_mutable[27:])

def update_fmr_payload_length(fmr_data: bytes) -> bytes:
    """
    Updates the 4-byte 'Total Length' field at offset 8 to reflect 
    the current size of the record.
    """
    fmr_mutable = bytearray(fmr_data)
    total_length = len(fmr_mutable)
    
    # Offset 8-12 in ISO/NIST headers is traditionally the Total Record Length
    fmr_mutable[8:12] = total_length.to_bytes(4, "big")
    return bytes(fmr_mutable)

def transform_iso_to_nist_fmr(fmr_data: bytes) -> bytes:
    """
    Converts a standard ISO FMR to a format compatible with NBIS utilities
    by stripping specific header fields and recalculating the record length.
    """
    stripped_fmr = strip_iso_header_metadata(fmr_data)
    final_fmr = update_fmr_payload_length(stripped_fmr)
    
    return final_fmr

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions