liveBook · Manning

Image segmentation

As explained in Deep Learning with PyTorch, Second Edition

A learning task that partitions an input, often an image, into labeled regions or elements, used here to flag voxels or pixels that may belong to a nodule.

Image segmentation answers “where?” rather than just “is it there?” A classifier might report that an image contains a cat; a segmentation model produces an image-like mask showing which pixels belong to the cat. For a CT scan, the same idea flags pixels or voxels that might belong to a lung nodule. section 15.3 section 15.1

Finding possible nodules is a first pass, not a diagnosis. Many flagged structures will not be nodules. Segmentation tells a separate classifier where to look; classification then examines candidates more closely. Here the two models are trained separately rather than optimized together end to end. section 15.1 section 11.4.1

There are several ways to mark what matters in an image:

  • Semantic segmentation assigns a class to each pixel. A binary nodule mask marks candidate pixels as true and other tissue as false; it does not distinguish one nodule from another. section 15.2
  • Instance segmentation gives separate labels to individual objects, such as two distinct tumors. section 15.2
  • Object detection places bounding boxes around objects rather than labeling their pixels precisely. section 15.2

A practical nodule workflow uses 2D CT slices so masks are easier to inspect than they would be in 3D. The dataset supplies slices and corresponding nodule masks. Segment Anything (SAM) demonstrates mask generation guided by a point prompt. To find candidates on unseen slices without supplying a point, a pretrained SegFormer semantic-segmentation model is fine-tuned on the CT images and masks, with background and nodule as its two labels. section 15.1 section 15.7.1 section 15.9

Checking a predicted mask

Pass an unseen CT slice through the trained model, post-process its output into a segmentation map, and display the slice beside the annotated mask and prediction. This makes it possible to see which suspected nodule pixels the model marked and where its prediction differs from the annotation. section 15.8

Figure 15.17 CT images (left) with the ground truth mask (middle) and the model predictions (right)
figure

Compare the CT image, ground-truth mask, and predicted mask side by side. section 15.8

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Defines pixel-level masks, compares segmentation types, and follows dataset preparation, fine-tuning, and inference; uses 2D slices rather than 3D segmentation.
Examples
Uses a cat-location contrast, binary nodule masks, and side-by-side CT slices, annotations, and predictions.
What it assumes
Introduces a new model, dataset, and training loop without requiring the earlier classifier work, though that context helps.
What you can do after
Apply it via SAM prompts or a fine-tuned SegFormer model to generate and inspect candidate-nodule masks.
How it connects
Connects semantic segmentation to classification, instance segmentation, object detection, CT imaging, and model fine-tuning.

Also explained in

Compare how 6 books explain image segmentation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.