Skip to content
Guides9 min read

Medical Image Annotation with Potato

Label X-rays and clinical photographs, segment CT and MR volumes from DICOM or NIfTI, and outline regions on whole-slide pathology images in Potato.

Potato Team

Potato 2.12 annotates three kinds of medical image. X-rays and clinical photographs use the ordinary image scheme, CT and MR volumes open from a DICOM series or a NIfTI file in volume_annotation, and whole-slide pathology images open through openslide in the deep-zoom viewer. Every kind runs on servers your institution controls, with several readers per case and their agreement measured.

This guide covers the setup for each kind of image, what Potato does with patient information in DICOM headers, and what Potato leaves to your institution. The healthcare page covers clinical text as well as images.

Before you start

A medical annotation project comes with obligations that Potato does not take over. Remove or pseudonymize patient information before the files reach the server, since Potato withholds DICOM header fields from annotators but does not rewrite the files. Keep the data on your institution's own infrastructure, and sign annotators in through the identity provider you already run. Bring in your IRB and compliance teams early, so the requirements shape the setup instead of arriving after the study starts.

Potato has no HIPAA compliance feature, and no audit log of who viewed which patient image. Whether a deployment may store protected health information is a decision for your institution's privacy and security office.

X-rays and clinical photographs

A 2D image uses the image_annotation scheme, with boxes, polygons, brush masks, and other tools. Potato reads PNG and JPEG directly and converts TIFF (including 16-bit), JPEG 2000, HEIC, and camera RAW on first request. The config below is a complete chest X-ray task:

yaml
annotation_task_name: "Chest X-Ray Findings"
task_dir: .
output_annotation_dir: annotation_output/
data_files:
  - data/xray_images.json
item_properties:
  id_key: id
  text_key: image
 
annotation_schemes:
  - annotation_type: image_annotation
    name: abnormalities
    description: "Outline each abnormality"
    source_field: image
    tools: [polygon, bbox]
    labels:
      - {name: opacity, color: "#EF4444"}
      - {name: consolidation, color: "#F97316"}
      - {name: nodule, color: "#EAB308"}
      - {name: effusion, color: "#3B82F6"}
 
  - annotation_type: multiselect
    name: findings
    description: "Select all findings present"
    labels:
      - {name: normal, label: "No acute findings"}
      - {name: pneumonia, label: "Pneumonia"}
      - {name: atelectasis, label: "Atelectasis"}
      - {name: pneumothorax, label: "Pneumothorax"}
      - {name: fracture, label: "Fracture"}
 
  - annotation_type: radio
    name: image_quality
    description: "Overall image quality"
    labels:
      - {name: diagnostic, label: "Diagnostic quality"}
      - {name: limited, label: "Limited quality"}
      - {name: non_diagnostic, label: "Non-diagnostic"}

source_field names the item field with the image path, and each item in the data file has that field:

json
[
  {"id": "case_001", "image": "images/case_001.png"},
  {"id": "case_002", "image": "images/case_002.png"}
]

An image label takes a name, a color, and an optional key_value for a keyboard shortcut. Potato reads no other keys on image labels, so a definition for each finding belongs in the annotation guidelines.

A single radiograph in DICOM format usually needs converting to PNG or TIFF. The volume scheme below reads DICOM, but refuses a file without patient position and pixel spacing, and many CR and DX radiographs lack the position field.

Dermoscopy and fundus images

The same scheme fits other clinical photographs. The schemes below replace the X-ray schemes in the config above, first for dermoscopy:

yaml
annotation_schemes:
  - annotation_type: image_annotation
    name: lesion_boundary
    description: "Outline the lesion boundary"
    source_field: image
    tools: [polygon]
    labels:
      - {name: lesion, color: "#EF4444"}
 
  - annotation_type: multiselect
    name: dermoscopic_features
    description: "Select all features present"
    labels:
      - {name: pigment_network, label: "Pigment network"}
      - {name: dots_globules, label: "Dots or globules"}
      - {name: streaks, label: "Streaks"}
      - {name: blue_white_veil, label: "Blue-white veil"}
      - {name: regression, label: "Regression structures"}
      - {name: vascular, label: "Vascular structures"}
 
  - annotation_type: radio
    name: diagnosis
    description: "Most likely diagnosis"
    labels:
      - {name: benign_nevus, label: "Benign nevus"}
      - {name: seborrheic_keratosis, label: "Seborrheic keratosis"}
      - {name: basal_cell, label: "Basal cell carcinoma"}
      - {name: melanoma, label: "Melanoma"}
      - {name: other, label: "Other"}
 
  - annotation_type: likert
    name: confidence
    description: "Diagnostic confidence"
    size: 5
    min_label: "Low"
    max_label: "High"

For fundus photographs, a scheme for anatomy and a scheme for pathology keep the two kinds of outline apart, and a radio question records the grade:

yaml
annotation_schemes:
  - annotation_type: image_annotation
    name: anatomical_structures
    description: "Outline each anatomical structure"
    source_field: image
    tools: [polygon]
    labels:
      - {name: optic_disc, color: "#FDE68A"}
      - {name: fovea, color: "#A78BFA"}
      - {name: macula, color: "#93C5FD"}
 
  - annotation_type: image_annotation
    name: pathology
    description: "Outline each pathological finding"
    source_field: image
    tools: [polygon]
    labels:
      - {name: hemorrhage, color: "#EF4444"}
      - {name: exudate, color: "#FCD34D"}
      - {name: microaneurysm, color: "#F97316"}
 
  - annotation_type: radio
    name: dr_grade
    description: "Diabetic retinopathy grade"
    labels:
      - {name: none, label: "No DR"}
      - {name: mild, label: "Mild NPDR"}
      - {name: moderate, label: "Moderate NPDR"}
      - {name: severe, label: "Severe NPDR"}
      - {name: proliferative, label: "PDR"}

CT and MR volumes

From Potato 2.12, a volume_annotation scheme opens a DICOM series or a .nii or .nii.gz file in axial, coronal, and sagittal views. Annotators paint masks with a brush or outline a region with a polygon, and fill the slices between two painted slices with server-side interpolation. From Potato 2.13.1, closing a polygon paints its region into the label's mask on that slice. Boxes drawn on a slice are saved as separate shapes and exported to their own __shapes.json file, so boxes never fill mask voxels and do not count toward Dice. Volume support needs an optional install:

bash
pip install 'potato-annotation[volumes]'

The config below is a complete lesion segmentation task:

yaml
annotation_task_name: "Chest CT Lesion Segmentation"
task_dir: .
output_annotation_dir: annotation_output/
media_directory: media
data_files:
  - data/volumes.json
item_properties:
  id_key: id
  text_key: text
 
annotation_schemes:
  - annotation_type: volume_annotation
    name: ct_segmentation
    description: "Paint the lesion on each slice it appears on"
    source_field: volume
    labels:
      - {name: Lesion, color: "#e6553a", key_value: "1"}
      - {name: Bone, color: "#3a8ee6", key_value: "2"}
    tools: [brush, eraser, polygon]
    views: [axial, coronal, sagittal]
    prefill_rtstruct_field: rtstruct
    default_window: Nodule review
    window_presets:
      - {name: Nodule review, center: -600, width: 1500}
      - {name: Mediastinum, center: 50, width: 350}
    display_tags: [Modality, BodyPartExamined, SliceThickness]
 
  - annotation_type: likert
    name: confidence
    description: "How confident are you in the outline?"
    size: 5
    min_label: "Not confident"
    max_label: "Very confident"

Each item names a folder holding one DICOM series, or a NIfTI file, relative to media_directory. An item can also name an RTSTRUCT file, whose contours become starting masks for labels with the same name:

json
[
  {"id": "case_001", "volume": "case_001_ct", "rtstruct": "case_001_rtstruct.dcm", "text": "Case 001"},
  {"id": "case_002", "volume": "case_002.nii.gz", "text": "Case 002"}
]

Window presets set the gray-level window for the views. A CT series gets four built-in presets (soft tissue, lung, bone, and brain), the window stored in the file, and an automatic window. The menu lists the scheme's own presets first, so give each scheme preset a name that differs from the built-in ones. A NIfTI file has no modality field, so a NIfTI volume gets only the automatic window and the presets listed in window_presets. Annotators can also adjust the window by dragging with the right mouse button.

Potato refuses a series it cannot display correctly, and says why. The refusals cover a folder holding more than one series, uneven or missing slices, a tilted gantry, and a series flagged with burned-in annotation. The release includes a runnable example with a synthetic CT phantom in examples/image/ct-volume/.

Patient information in DICOM headers

DICOM headers usually contain the patient's name, ID, birth date, and institution. The volume viewer shows annotators only the header fields listed in display_tags, and a field that the DICOM de-identification basic profile removes, such as PatientName or PatientID, appears only when allow_identifying_tags lists the field as well. The server applies the list, so a browser cannot request other fields. Raw DICOM and NIfTI files are not served for download unless serve_raw_medical_files is turned on, and then they are served without sign-in.

The filter has limits. File and folder names reach the browser, and exports from a PACS often name folders after the patient, so use pseudonymous names such as case_001_ct/. Pixels are checked only through the burned-in annotation flag, and the files on disk stay as uploaded.

Whole-slide pathology images

Pathology slides in the formats openslide reads, such as .svs, .ndpi, and .mrxs, open in the deep-zoom viewer of an image_annotation scheme with viewer: deepzoom. Potato cuts each tile from the slide's own pyramid, so a 100,000 × 80,000 pixel scan opens as quickly as a small image. Slide support needs pip install 'potato-annotation[wsi]'. Deep zoom has the configuration and explains how to convert stored coordinates to microns.

Agreement and export

Assign each case to more than one reader with num_annotators_per_item, and Potato keeps each reader's labels and reports their agreement. Volume masks are scored by 3D Dice per label for each pair of readers, and a pair where neither reader painted a label is left out for that label rather than counted as agreeing.

Masks from volume_annotation export as NIfTI label volumes in the geometry of the source file (volume_nifti) or, for DICOM sources, as DICOM SEG objects that reference the source series (dicom_seg). A DICOM SEG copies the patient and study information of the source series, as the DICOM standard requires, so treat a SEG export as identifiable. 2D annotations export as PNG masks, COCO, or CVAT, among the other formats.

Best practices

Use annotators with clinical training for clinical labels, and check their work against each other rather than trusting any single reader. Write guidelines specific to the clinical question, with a definition and an example image for each label. Mix in cases with a known answer to watch accuracy over time, and keep your compliance team informed about where the data lives and who can reach the server.

Limitations

Potato does not de-identify files, has no HIPAA compliance feature, keeps no audit log of who viewed which patient image, and does not verify annotators' clinical credentials. The volume viewer does not handle 4D volumes, fused PET/CT, or oblique reformats. For a regulated study, keep identifiable health records in a system built for that purpose and use Potato for the annotation.


For the image scheme's full options, see Image Annotation.