LECTURE 2

Lecture 2. De-identification in four layers

How protected health information leaks from medical data and how to remove it: the DICOM PS3.15 confidentiality profile, private tags, text burned into pixels and faces in 3D scans, and what the project's osv.deid gate checks today. With diagrams, formulas, interactive examples and a 3D animation.

This page is still being reviewed by our scientific, clinical and legal experts. It describes plans, not finished work.

A public repository or benchmark cannot take anything back: once a file with a patient’s name, a date of birth or a recognisable face is downloaded, it stays out there. Protected health information (PHI) hides in four places in medical images: the DICOM header, the vendors’ private tags, text burned into the pixels, and the surface of a 3D scan that shows a face. This lecture goes through all four, what the DICOM standard prescribes for each, and what the project’s osv.deid gate checks. It is lecture 2 of the learning programme, after lecture 1 on data formats.

Every name, number and image on this page is synthetic.

What counts as PHI

  • Direct identifiers name a person on their own: name, patient or record number, address, telephone number, e-mail, a photograph of the face.
  • Indirect identifiers, or quasi-identifiers, narrow down who it is when combined: dates of birth, examination and admission, age, sex, the hospital and department, the scanner’s serial number, a rare diagnosis, a small town. The day of an operation together with the hospital may be enough.
  • The law draws the line in different places. The US HIPAA Safe Harbor method lists 18 kinds of identifier to remove, among them all elements of dates except the year. The EU’s GDPR treats pseudonymised data, where a key could restore the identity, as personal data still; only data that can no longer reasonably be linked to a person falls outside it.
  • The project’s rule is simpler: nothing with PHI enters a public repository, a benchmark or the annotation workspace. Only de-identified data reaches CVAT, and the ethics page sets out the rest.

Four layers

DICOM headers1 · DICOM tagsPS3.15 profilenames, IDs, dates, clinicsvendor blocks2 · Private tagsodd groupsundocumented vendor datapixels of frames3 · Burned-in textOCR and maskingnames, record numbersCT and MRI surfaces4 · Defacingface surfacenose, eyes, lips, chinpython -m osv.deid.scan → deid-verdict.json → label deid:pass or deid:fail
Each layer looks at a different part of the data; one gate checks all four before data enters the repository.

Layer 1. DICOM tags: the PS3.15 profile

DICOM PS3.15, Annex E defines the Basic Application Level Confidentiality Profile: a table of several hundred attributes, each with the action a de-identifier must take. The actions use one-letter codes:

Code Action
D replace with a dummy value of the right type
Z replace with an empty value, or a dummy one
X remove the attribute
K keep it
C clean: replace with a value of similar meaning that identifies no one
U replace a UID with a new one, consistently within the data set

Combinations such as X/Z/D mean “remove, unless the IOD requires the attribute; then empty it, unless it must have a value; then a dummy”.

The basic profile is strict. Options relax it where a study needs something back, each recorded with a code in the header: retain longitudinal temporal information with full or with modified dates, retain patient characteristics such as age and sex, retain device identity, retain institution identity, retain UIDs, retain safe private tags; or tighten it, for example by cleaning pixel data, graphics or free-text descriptions.

Try the profile on a synthetic header. The actions are those of Annex E; tick an option to see what it brings back.

TagNameOriginal (synthetic)ActionResult
(0010,0010)PatientNameSYNTHETIC^PATIENTZ(empty)
(0010,0030)PatientBirthDate19650412Z(empty)
(0010,1010)PatientAge060YX(removed)
(0010,0040)PatientSexFZ(empty)
(0008,0020)StudyDate20260302Z(empty)
(0008,0050)AccessionNumberACC-0000001Z(empty)
(0008,0080)InstitutionNameExample ClinicX/Z/D(removed)
(0018,1000)DeviceSerialNumberSN-000123X/Z/D(removed)
(0020,000D)StudyInstanceUID1.2.3.4.5.67890.1U2.25.199338573285018412369876543210987654
(0012,0062)PatientIdentityRemoved–addedYES
(0012,0064)DeidentificationMethodCodeSequence–added113100

The last two rows matter as much as the others: a de-identified file must say so. PatientIdentityRemoved becomes YES, and the method code sequence lists the profile (113100) and every option applied, from the codes in PS3.16, CID 7050. A reader of the data then knows that ages were kept or dates shifted.

Pseudonyms, UIDs and dates

Removing everything breaks research: the slices of one series must still belong together, and the scans of one patient must still be linkable. Three techniques keep the links without the identity.

ID′=OSV_‖hex(HMACK(ID)) UID′=2.25.‖dec(HMACK(UID)mod2128)
  • Pseudonyms replace an identifier with a keyed hash of it, HMAC with a secret key K. The same patient always gets the same pseudonym, so studies stay linked. The key is what protects the data: a plain hash of a seven-digit record number can be reversed by trying all ten million numbers, and a key kept outside the data set makes that impossible. Whoever holds the key can re-identify, which is why the GDPR still treats such data as personal.
  • UIDs are replaced the same way. The root 2.25. is reserved for UIDs made from a 128-bit number; taking the hash of the old UID keeps every reference between files consistent.
d′=d+Δp Δp=HMACK(PatientID)mod731−365
  • Date shifting moves every date of a patient by the same number of days, here between −365 and +365, derived from the key. Intervals survive: the follow-up scan is still 92 days after the operation. The header records the modified dates option (113107). The interactive table above shifts the study date by −105 days.

Layer 2. Private tags

tagVRvalue(0029,0010)LOEXAMPLE VENDOR 1.0(0029,1001)LOprotocol name(0029,1010)OBbinary, undocumented(0029,1020)OBbinary, undocumentedodd group number: privatethe creator reserves (0029,1000–10FF)content known only to the vendor:it may hold names, dates, even screenshots
A fictional vendor block. Real ones carry acquisition parameters, protocol names and sometimes the operator's notes.

Standard attributes live in even-numbered groups. Elements in odd groups are private: a vendor writes a private creator element, say (0029,0010), with its name, and that reserves the block (0029,1000) to (0029,10FF) for its own data (PS3.5, section 7.8). What is in the block is documented, if at all, in the vendor’s conformance statement. Binary blobs may contain a copy of the patient’s name, the operator, the hospital, even an embedded screenshot, and no generic tool can inspect them.

So the rule is to remove every private element unless it is on an allowlist of elements someone has checked; the profile’s “retain safe private” option exists for exactly those. The project’s gate keeps that allowlist empty: any element in an odd group fails it.

Layer 3. Text burned into pixels

Some images carry identity in the pixels themselves: ultrasound screens with the patient’s name and the date along the top, endoscopy towers that overlay the patient’s name, the date and time and the hospital on the video, screenshots saved as DICOM secondary captures, scanned documents. Removing tags does nothing to them, and the header element BurnedInAnnotation (0028,0301), which is supposed to say whether text is present, is often missing or wrong.

framewith textgradientmax − min, 3 × 3thresholdOtsujoin glyphsclosing 9 × 3keep linesh 8–60 px, w/h ≥ 1.5maskopaque fill
The shape detector that osv.deid always runs, next to Tesseract when it is installed: it finds text by its shape, without reading it.

Two complementary detectors find it:

  • OCR reads the text, here with Tesseract, and looks for patterns: dates, times, and words such as “patient”, “DOB” or “MRN”.
  • Shape: text is made of sharp, high-contrast strokes in horizontal lines, unlike smooth tissue. A morphological gradient (the maximum minus the minimum over 3 × 3 pixels) lights up strokes, Otsu’s method picks a threshold, a closing with a 9 × 3 rectangle joins letters into lines, and only boxes with the height and proportions of a text line are kept.

Found text is then masked: covered with an opaque fill in the stored pixels. Three rules: the fill must be opaque, because blurred or pixelated text can sometimes be read back; it must change the pixel data itself, not a graphics layer or a DICOM overlay that a viewer can switch off; and in video it must cover every frame, since overlays appear, move and disappear. Try it on a synthetic frame with a synthetic overlay:

Look closely at the masked frame: the detector boxes some tissue edges and misses part of the overlay, so a line of the synthetic identity stays readable. The gate would still fail this frame, because it finds more than one text-like region, but masking only what a detector found is not enough. Masking tools therefore also blank the fixed areas where a device prints its overlay, and a person checks the result.

Layer 4. Defacing

brainremovedbrainbefore: the face can be rebuilt in 3Dafter: face voxels set to zero
A side view. Real tools fit the cut to each head, usually by registering a template with a face mask.

A CT or MRI of the head contains the skin of the face. Rendered in 3D, it is a portrait, and Schwarz et al. (NEJM, 2019) showed that ordinary face-recognition software can match such renders from research MRI to participants’ photographs. Removing the name does not help when the face itself is in the data.

Defacing sets the voxels of the face to zero (air): nose, eyes, lips, chin, sometimes the ears, while leaving the brain and the rest of the anatomy untouched. Tools such as pydeface and FreeSurfer’s mri_deface register a template to the scan and remove what falls inside its face mask. Two checks follow every run: no recognisable face remains in a 3D render, and the brain has not been cut. Skull stripping, which removes everything but the brain, also hides the face but throws away anatomy many tasks need. Scans that do not include the head, an abdominal CT for example, need no defacing.

What osv.deid does today

osv.deid is a gate: it inspects files and fails a pull request that still contains PHI. The removal itself is done before, with tools built for it, for example deid, dicognito or dicom-anonymizer for headers, OCR and masking for pixels, pydeface or mri_deface for faces.

Layer What the gate checks Limits to know
1. DICOM tags 33 identifying attributes of the PS3.15 profile: any with a value that is not empty or a placeholder fails values starting with a pseudonym prefix such as OSV_ or CASE_ pass unread
2. Private tags every element in an odd group fails; the allowlist is empty strict on purpose
3. Burned-in text image files (PNG, JPEG, BMP, TIFF): Tesseract with date, time and keyword patterns when installed, and always the shape detector, which fails an image with two or more text-like regions DICOM pixel data and video are not scanned; a single line of text can pass the shape detector
4. Defacing volumes named like head scans (head, brain, skull, face) must carry a defacing marker in the file name a geometric check of the face surface is planned, not built

In practice:

  • In CI, the deid-scan workflow runs python -m osv.deid.scan on every changed file under osv/datasets, osv/deid, data and the DVC files, writes deid-verdict.json and labels the pull request deid:pass or deid:fail. It is a required check; the deid-gate agent explains a failure in a comment but does not decide it.
  • Before a pull request, run the same check yourself, or /deid <path> with the project’s AI assistant.
  • A pass is necessary, not sufficient. The gate checks known places with known rules. A person who knows the data still reviews every new source, and real data never enters a public repository in the first place.

Checklist

  • Headers: the basic profile applied, options chosen deliberately and recorded, PatientIdentityRemoved set to YES.
  • Links kept with a keyed hash; the key stored apart from the data.
  • Private tags removed unless allowlisted.
  • Every image and every video frame checked for burned-in text; text masked opaquely in the pixels.
  • Head CT and MRI defaced, and the result checked in 3D.
  • python -m osv.deid.scan passes, and a person has looked at the new source.

Further reading