{
  "source_file": "0930",
  "source_platform": "Hashnode",
  "author": "Lakshmi Mahabaleshwara",
  "title_listed": "How to Build an AI-Powered Medical Image De-Identification Pipeline for Clinical Research",
  "keywords": "",
  "domain": "图像处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://freecodecamp.org/news/build-ai-image-de-identification-for-clinical-research",
  "publish_date": "2026-05-22",
  "corpus_stage": "",
  "notes": "",
  "id": "60f13b09e0e5",
  "collected_at": "2026-10-02T14:12:05",
  "title": "How to Build an AI-Powered Medical Image De-Identification Pipeline for Clinical Research",
  "body_markdown": "Medical imaging is transforming healthcare. Researchers are training deep learning models to detect pneumonia from chest X-rays, estimate cardiac function from echocardiograms, and identify tumors from MRI scans. But before any of these images can be shared with researchers or used to train machine learning models, one critical challenge must be solved.\nHow Do We Protect Patient Privacy?\nMedical images often contain sensitive information such as patient names, dates of birth, hospital identifiers, and accession numbers. Some of this information is stored in DICOM (\nDigital Imaging and Communications in Medicine)\nmetadata, but much of it is also burned directly into the image pixels.\nIn this tutorial, you’ll learn how to build an AI-powered de-identification pipeline that removes PHI from both metadata and image pixels. Along the way, we’ll explore OCR (Optical Character Recognition), NER (Named Entity Recognition), and standards-based DICOM processing.\nAt the end, I’ll show how I combined these ideas into an open-source PyTorch project called Aegis.\nWhat You’ll Build\nPrerequisites\nWhy Privacy Matters in Medical Imaging\nUnderstanding PHI, HIPAA, and DICOM\nWhat Is PHI?\nWhat Is HIPAA?\nWhat Is DICOM?\nWhy Metadata Anonymization Is Not Enough in DICOM format\nOCR and AI for Identifying PHI\nStep 1: Optical Character Recognition (OCR)\nStep 2: Determine Whether the Text Is PHI\nStep 3: Named Entity Recognition\nPixel Redaction and DICOM Scrubbing\nDICOM Metadata Scrubbing\nBuilding the Complete Pipeline\nChallenges and Lessons Learned\nHow I Built Aegis\nKey Design Decisions\nFuture Directions\nConclusion\nWhat You’ll Build\nIn this tutorial, you’ll build a custom MONAI (PyTorch) preprocessing pipeline that automatically de-identifies medical images before they are used for clinical research or AI model training.\nThe pipeline will:\nDiscover DICOM studies\nLoad metadata and pixel data\nDetect burned-in text using OCR\nClassify text as PHI or non-PHI\nRedact sensitive pixel regions\nRemove PHI from DICOM metadata and pixel data\nSave privacy-safe images for downstream AI workflows\nBy the end, you’ll have a reusable MONAI transform that can be integrated directly into any medical imaging workflow to prepare privacy-safe datasets for research and deep learning.\nPrerequisites\nTo follow this tutorial, you should have:\nIntermediate Python experience\nBasic understanding of PyTorch\nFamiliarity with medical imaging concepts\nPython 3.10 or later\nWe’ll use:\nMONAI\npydicom\nEasyOCR\nNumPy\nTransformers\nStanford NER\nSet Up the Environment\n# Create and activate a virtual environment\npython -m venv venv\nsource venv/bin/activate        # On Windows: venv\\Scripts\\activate\n\n# Upgrade pip\npip install --upgrade pip\n\n# Install the core libraries used in this tutorial\npip install \\\n    monai \\\n    pydicom \\\n    easyocr \\\n    numpy \\\n    transformers \\\n    torch \n\n# Download the Stanford medical de-identification model from Hugging Face\npython -c \"\nfrom transformers import AutoTokenizer, AutoModelForTokenClassification\n\nmodel_name = 'StanfordAIMI/stanford-deidentifier-base'\nAutoTokenizer.from_pretrained(model_name)\nAutoModelForTokenClassification.from_pretrained(model_name)\nprint('Stanford NER model downloaded successfully.')\n\"\nWhy Privacy Matters in Medical Imaging\nHealthcare organizations generate enormous volumes of imaging data every day. These datasets are invaluable for:\nClinical research\nMulti-center collaborations\nRegulatory submissions\nArtificial intelligence model development\nEducational datasets\nBut privacy regulations such as the HIPAA (Health Insurance Portability and Accountability Act) in the United States require that PHI (Protected Health Information) be removed before data can be shared. This creates a significant bottleneck.\nMany hospitals still rely on manual review to inspect thousands of images, searching for patient identifiers hidden in metadata and image annotations. This process is slow, expensive, and prone to human error.\nAutomated de-identification solves this problem by combining software engineering, computer vision, and natural language processing.\nUnderstanding PHI, HIPAA, and DICOM\nWhat Is PHI?\nProtected Health Information (PHI) includes any information that can identify a patient, such as:\nName\nMedical record number\nDate of birth\nStudy date\nHospital ID\nAccession number\nWhat Is HIPAA?\nThe Health Insurance Portability and Accountability Act (HIPAA) defines rules for safeguarding patient data. One common approach is the Safe Harbor method, which requires removing specific identifiers before data is shared.\nWhat Is DICOM?\nMedical images such as\nComputed Tomography (CT)\n,\nMagnetic Resonance Imaging (MRI)\n, and\nUltrasound (US)\nare commonly stored in the DICOM\n(Digital Imaging and Communications in Medicine)\nformat, the international standard for storing and exchanging medical imaging data.\nUnlike ordinary image formats such as JPEG or PNG, a DICOM file contains both the image itself and a rich set of structured metadata that describes the patient, the study, and the imaging procedure.\nA typical DICOM file contains two main components:\nPixel Data\n– the actual medical image, such as a CT slice, MRI volume, or ultrasound frame.\nMetadata\n– structured fields that may include:\nPatient name and medical record number\nDate of birth\nStudy and acquisition dates\nImaging modality (CT, MRI, US)\nScanner manufacturer and technical acquisition parameters\nThis combination makes DICOM far more than just an image format. It serves as a standardized container that allows imaging devices, hospital systems, and research software to exchange data reliably and consistently.\nBecause DICOM metadata often contains protected health information (PHI), and because identifiers may also be burned directly into the image pixels, particularly in ultrasound studies, both the metadata and the pixel data must be addressed during de-identification before images can be safely shared for clinical research or AI development.\nWhy Metadata Anonymization Is Not Enough in DICOM format\nMany tools remove PHI only from metadata. For example, deleting the PatientName tag may appear sufficient.\nBut in modalities such as ultrasound, fluoroscopy, and some X-ray workflows, identifying information is often burned directly into the image.\nCommon examples include:\nNAME: JOHN DOE\nDOB: 01/01/1980\nMRN: 123456\nHOSPITAL: ABC\nIf these annotations remain, privacy is still compromised. This means a complete solution must inspect both:\nDICOM metadata\nImage pixels\nOCR and AI for Identifying PHI\nTo detect PHI embedded in pixels, we first need to find all visible text.\nStep 1: Optical Character Recognition (OCR)\nOCR converts image text into machine-readable strings.\nimport easyocr\nreader = easyocr.Reader(['en'])\nresults = reader.readtext('ultrasound.png')\nEach OCR result typically includes:\nBounding box coordinates – where the text appears in the image\nExtracted text – the recognized characters\nConfidence score – how certain the model is about the result\nExample:\n[\n  ([[10, 20], [120, 20], [120, 45], [10, 45]], 'JOHN DOE', 0.98)\n]\nStep 2: Determine Whether the Text Is PHI\nNot all detected text should be removed.\nMedical images also contain clinically relevant labels such as:\nLEFT VENTRICLE\nAPICAL VIEW\nB-MODE\nTo distinguish PHI from legitimate clinical text, we can combine:\nAllowlists of known clinical terms\nRegular-expression heuristics\nNamed Entity Recognition (NER)\nStep 3: Named Entity Recognition\nNER models identify entities such as:\nPERSON\nDATE\nLOCATION\nID\ndef contains_phi(text): \n    if looks_like_date(text): \n    return True \n    if looks_like_identifier(text): \n    return True \n    return ner_model.predict(text)\nThis hybrid approach reduces both false positives and false negatives.\nPixel Redaction and DICOM Scrubbing\nPixel Redaction\nOnce PHI is detected, the corresponding image regions can be masked.\nimage[y1:y2, x1:x2] = 0\nThis replaces the sensitive area with black pixels.\nDICOM Metadata Scrubbing\nUsing pydicom, metadata fields can be modified or removed.\nimport pydicom\n\nds = pydicom.dcmread('study.dcm')\nds.PatientName = 'ANONYMIZED'\ndel ds.PatientBirthDate\nAdditional steps may include:\nRemoving private tags\nReplacing UIDs\nRecursively processing nested sequences\nTogether, metadata scrubbing and pixel redaction provide comprehensive de-identification.\nBuilding the Complete Pipeline\nThe overall workflow looks like this:\nDiscover medical image files\nLoad DICOM metadata and pixel data\nRun OCR on annotation regions\nClassify text as PHI or non-PHI\nRedact sensitive pixel regions\nRemove PHI from metadata\nSave the de-identified output\nChallenges and Lessons Learned\nBuilding a production-ready de-identification system involves many practical challenges.\nClinical Terminology\nOCR may detect legitimate labels that should not be removed.\nOCR Errors\nLow-contrast text and ultrasound overlays can produce inaccurate detections.\nNested DICOM Sequences\nPHI may appear in deeply nested metadata structures.\nMulti-Frame Studies\nUltrasound cine loops may contain dozens or hundreds of frames.\nDeterministic Pseudonymization\nResearchers often need the same patient to receive the same replacement identifier across studies.\nThese challenges require thoughtful engineering rather than a single machine learning model.\nHow I Built Aegis\nWhile exploring this problem, I developed an open-source MONAI (PyTorch based) project called\nAegis\n.\nAegis combines:\nOCR-based text detection\nAI-driven PHI classification\nPixel-level redaction\nStandards-based DICOM de-identification\nBatch processing for research workflows\nKey Design Decisions\nStandards First\nI aligned metadata scrubbing with the DICOM confidentiality profile to follow established healthcare standards.\nHybrid AI + Rules\nClinical allowlists, heuristics, and NER models work together to improve accuracy.\nUltrasound-Specific Optimization\nAegis uses\nSequenceOfUltrasoundRegions\nto focus OCR on annotation areas instead of scanning the entire image.\nDeterministic Identity Management\nConsistent pseudonyms enable longitudinal research while protecting privacy.\nOpen Source Architecture\nThe project is modular, testable, and designed to integrate with research pipelines.\nYou can explore the full implementation in the Aegis GitHub repository:\nhttps://github.com/lakshmi-mahabaleshwara/aegis\nFuture Directions\nAutomated de-identification continues to evolve.\nFuture enhancements may include:\nMultilingual OCR\nHandwriting recognition\nVision-language models\nHuman-in-the-loop review\nCloud-native deployment\nIntegration with AI training pipelines\nAs healthcare AI expands, privacy-preserving data preparation will become even more important.\nConclusion\nClinical research depends on access to high-quality medical imaging data.\nBut privacy regulations require that patient identifiers be removed from both DICOM metadata and image pixels.\nBy combining OCR, named entity recognition, pixel redaction, and standards-based DICOM processing, we can automate this task and dramatically reduce the burden of manual review.\nThe techniques covered in this tutorial are applicable far beyond a single project.\nWhether you’re building a hospital data pipeline, preparing research datasets, or training the next generation of healthcare AI models, automated de-identification is a foundational capability.\nTo put these ideas into practice, I built Aegis as an open source reference implementation.\nMore importantly, the underlying concepts can help developers and researchers create privacy-safe workflows that accelerate innovation while respecting patient confidentiality.\nReferences\nhttps://pydicom.github.io/\nhttps://project-monai.github.io/\nhttps://www.dicomstandard.org/\nhttps://www.hhs.gov/hipaa/",
  "metadata": {
    "title": "How to Build an AI-Powered Medical Image De-Identification Pipeline for Clinical Research",
    "description": "Medical imaging is transforming healthcare. Researchers are training deep learning models to detect pneumonia from chest X-rays, estimate cardiac function from echocardiograms, and identify tumors fro",
    "keywords": null,
    "author": null,
    "og:site_name": "freeCodeCamp.org",
    "og:type": "article",
    "og:title": "How to Build an AI-Powered Medical Image De-Identification Pipeline for Clinical Research",
    "og:description": "Medical imaging is transforming healthcare. Researchers are training deep learning models to detect pneumonia from chest X-rays, estimate cardiac function from echocardiograms, and identify tumors fro",
    "og:url": "https://www.freecodecamp.org/news/build-ai-image-de-identification-for-clinical-research/",
    "og:image": "https://cdn.hashnode.com/uploads/covers/5fc16e412cae9c5b190b6cdd/04f2b51b-5590-4bde-9d2c-4af3a6d4237c.png",
    "og:image:width": "1920",
    "og:image:height": "1080",
    "twitter:card": "summary_large_image",
    "twitter:title": "How to Build an AI-Powered Medical Image De-Identification Pipeline for Clinical Research",
    "twitter:description": "Medical imaging is transforming healthcare. Researchers are training deep learning models to detect pneumonia from chest X-rays, estimate cardiac function from echocardiograms, and identify tumors fro",
    "twitter:url": "https://www.freecodecamp.org/news/build-ai-image-de-identification-for-clinical-research/",
    "twitter:image": "https://cdn.hashnode.com/uploads/covers/5fc16e412cae9c5b190b6cdd/04f2b51b-5590-4bde-9d2c-4af3a6d4237c.png",
    "twitter:label1": "Written by",
    "twitter:data1": "Lakshmi Mahabaleshwara",
    "twitter:label2": "Filed under",
    "twitter:data2": "healthcare, AI, open source",
    "twitter:site": "@freecodecamp",
    "article:published_time": "2026-05-22T15:06:15.292Z",
    "article:modified_time": "2026-05-22T15:06:15.292Z",
    "article:tag": "open source",
    "article:publisher": "https://www.facebook.com/freecodecamp"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "file": "attachments/60f13b09e0e5/code/body-000.txt",
      "chars": 693,
      "language": "text"
    },
    {
      "file": "attachments/60f13b09e0e5/code/body-001.txt",
      "chars": 81,
      "language": "text"
    },
    {
      "file": "attachments/60f13b09e0e5/code/body-002.txt",
      "chars": 57,
      "language": "text"
    },
    {
      "file": "attachments/60f13b09e0e5/code/body-003.txt",
      "chars": 91,
      "language": "text"
    },
    {
      "file": "attachments/60f13b09e0e5/code/body-004.txt",
      "chars": 69,
      "language": "text"
    },
    {
      "file": "attachments/60f13b09e0e5/code/body-005.txt",
      "chars": 34,
      "language": "text"
    },
    {
      "file": "attachments/60f13b09e0e5/code/body-006.txt",
      "chars": 24,
      "language": "text"
    },
    {
      "file": "attachments/60f13b09e0e5/code/body-007.txt",
      "chars": 163,
      "language": "text"
    },
    {
      "file": "attachments/60f13b09e0e5/code/body-008.txt",
      "chars": 24,
      "language": "text"
    },
    {
      "file": "attachments/60f13b09e0e5/code/body-009.txt",
      "chars": 104,
      "language": "text"
    }
  ],
  "images": [
    {
      "status": "ok",
      "url": "https://cdn.hashnode.com/uploads/covers/69fd77e89f93a850a46d376f/74b371d7-cb4a-47b5-afa6-d9e39331d03f.png",
      "bytes": 936618,
      "reused": true,
      "local_path": "attachments/60f13b09e0e5/images/003.png",
      "src": "https://cdn.hashnode.com/uploads/covers/69fd77e89f93a850a46d376f/74b371d7-cb4a-47b5-afa6-d9e39331d03f.png",
      "alt": "Step-by-step workflow for medical image de-identification: discover files, load DICOM metadata, run OCR, classify PHI, redact pixels, scrub metadata, and save de-identified output.",
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [],
  "links": [
    {
      "href": "https://github.com/lakshmi-mahabaleshwara/aegis",
      "label": "https://github.com/lakshmi-mahabaleshwara/aegis",
      "type": "a"
    },
    {
      "href": "https://pydicom.github.io/",
      "label": "https://pydicom.github.io/",
      "type": "a"
    },
    {
      "href": "https://project-monai.github.io/",
      "label": "https://project-monai.github.io/",
      "type": "a"
    },
    {
      "href": "https://www.dicomstandard.org/",
      "label": "https://www.dicomstandard.org/",
      "type": "a"
    },
    {
      "href": "https://www.hhs.gov/hipaa/",
      "label": "https://www.hhs.gov/hipaa/",
      "type": "a"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T10:50:59Z",
  "source_url": "https://freecodecamp.org/news/build-ai-image-de-identification-for-clinical-research",
  "papers": [],
  "actual_video_files": [],
  "body_chars": 11701,
  "expected_body_images": 1,
  "discovery_status": "ok",
  "delivery_status": "ok",
  "missing_reason": "",
  "raw_html": "attachments/60f13b09e0e5/pages/source.html",
  "local_html": "attachments/60f13b09e0e5/pages/article.html",
  "body_base_path": "attachments/60f13b09e0e5/pages/",
  "body_markdown_path": "attachments/60f13b09e0e5/pages/article.md"
}