Larvitar Documentation
Home
Guide
API
GitHub
Home
Guide
API
GitHub
  • API

    • Initializing
    • Parsing
    • Loading
    • Rendering
    • Interacting
    • Testing
    • Modules

      • Logger
      • Store
      • Managers

        • Image Manager
        • GSPS Manager
        • File Manager
      • Parsers

        • PDF Parser
        • NRRD Parser
        • ECG Parser
      • Loaders
        • DICOM Loader
        • MultiFrame Loader
        • SingleFrame Loader
        • DSA Image Loader
        • File Loader
        • Nrrd Loader
      • Interaction Tools

        • Initialize and manage Tools
        • Default and Custom Tools
        • Segmentation Tools
        • DvTools
      • Utilities

        • DICOM Anonymization
        • DICOM Customization
        • Tags
        • Utils
        • Memory
      • Post Processing

        • DSA
      • Visualizations

        • Layers
        • ECG
        • Color Maps
        • Greyscale Presentation States
      • Testing
Larvitar

Image Anonymization Module

Overview

The imageAnonymization module provides functionalities for anonymizing DICOM images by replacing metadata values with randomly generated or de-identified values. This ensures that sensitive patient information is removed while preserving the structural integrity of the image data.

API Reference

anonymize

Anonymizes a given DICOM series by replacing all metadata with randomized values. The function iterates through all image instances in the series and modifies their metadata fields.

Syntax

anonymize(series: Series): Series

Parameters

ParameterTypeDescription
seriesSeriesThe DICOM series to be anonymized.

Returns

Series - The anonymized DICOM series.

Example

import { anonymize } from "./imageAnonymization";
const anonymizedSeries = anonymize(originalSeries);

Implementation Details

  • Iterates through all image instances in the series.

  • Replaces metadata values based on their value representation (VR) type.

  • Updates key metadata attributes such as:

    ParameterDescription
    seriesUIDIndex of the current image in the series
    instanceUIDIndex of the current image in the series
    studyUIDIndex of the current image in the series
    accessionNumberIndex of the current image in the series
    studyDescriptionIndex of the current image in the series
    patientNameIndex of the current image in the series
    patientBirthdateIndex of the current image in the series
    seriesDescriptionIndex of the current image in the series
  • Marks the series as anonymized (series.anonymized = true).

Internal Utility Functions
  • makeDeIdentifiedValue
makeDeIdentifiedValue(length: number, vr: string): string | undefined

Generates a de-identified value based on the provided length and value representation (VR):

  1. LO, SH, PN → Replaced with a random alphanumeric string.

  2. DA (Date) → Set to 19000101 (January 1, 1900).

  3. TM (Time) → Set to the current time with zero-padding.

  • makeRandomString
makeRandomString(length: number): string

Generates a random alphanumeric string of a given length.

  • pad
  pad(num: number, size: number): string

Pads a number with leading zeros to ensure a fixed-size string representation.

Warnings & Considerations

This module does not alter pixel data, only metadata. Always ensure compliance with relevant data privacy regulations (e.g., HIPAA, GDPR) before anonymizing and sharing DICOM images. This module is provided under an open-source license. Use it responsibly in compliance with local regulations and privacy policies.


D/Vision Lab
Last Updated:
Contributors: Laura Borghesi, Simone "Lateralus" Manini
Next
DICOM Customization