Images as Data
CSC3104 · Lab

Pixels & normalisation

Follow one pixel through ToTensor() and Normalize() exactly as PyTorch does, then push a whole image's brightness and contrast until values clip.

  1. 1 · Predict0/1
  2. 2 · Experiment0/2
  3. 3 · Explain0/1
  4. 4 · Code it0/2
  5. 5 · Challenge
  6. 0/4 tasks done

Predict first

Commit to a guess before you touch anything. Being wrong here is how it sticks.

A red pixel of 255 after ToTensor + ImageNet Normalize — what value comes out? (2 dp)

Experiment

Move the controls and watch the outputs. Goals tick off automatically when you reach them.

Normalise one pixel

Normalised value
0.074
128/255 = 0.5020 (0.5020 − 0.485) / 0.229 = 0.074

Brightness, contrast & grayscale

Mean intensity
—
Values clipped to [0, 255]
0%

Explain it

Put what you saw into words. This is what the exam will ask you to do.

Why normalise with the ImageNet mean and std when fine-tuning a pretrained network?

Code it

Write real code against real data. Python and SQL run right here in your browser and hidden tests check your work; the AI reviews it like an examiner.

Pythoncore

ToTensor + Normalize in NumPy

Re-implement what transforms.ToTensor() + transforms.Normalize(MEAN, STD) do:

preprocess(img) takes an H × W × 3 uint8 array and returns a 3 × H × W float32 array: scale to [0, 1], move channels first (CHW), then normalise each channel with MEAN/STD. Also write bgr_to_rgb(img) — OpenCV loads images in BGR order.

Ctrl/⌘ + Enter to run

Challenge

Fixed variations, a new problem every day, and unlimited AI challenges built from your current settings.

Red Channel Max Normalisation

A red-channel pixel has raw value 255 (μ = 0.485, σ = 0.229). What is it after ToTensor() + ImageNet Normalize()? (2 decimals)