Informatics Week 2: Basics of Image Processing

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/81

encourage image

There's no tags or description

Looks like no tags are added yet.

82 Terms

1
New cards

How is a digital image represented for computer processing?

discrete data structure like a matrix

Digitisation means the function f(x, y) is sampled into a matrix with M rows + N columns.

2
New cards

What does the machine actually start with when given an image?

only an array of numbers, from which it tries to extract ideas + conclusions, image = arrays

3
New cards

What does d.shape = (546, 658) tell you?

The array has 546 rows (height) and 658 columns (width), in that order.

4
New cards

What does dtype uint8 mean, and what is the bit depth?

Each pixel is an unsigned 8-bit whole number from 0 to 255 (2^8 = 256 levels). This is the bit depth.

5
New cards

What were the min, max and mean of D.tif?

min = 0 (darkest pixel), max = 230 (brightest pixel), mean = 63.14 (mean pixel intensity). The max is not 255, so the full 8-bit range is not used.

6
New cards

What does a histogram show?

counts how many pixels have each intensity value

x-axis = pixel intensity value

y-axis = # pixels with that value

7
New cards

What did the histogram of D.tif look like and why?

Three sharp spikes at 0 (black border), 100 (grey rectangle) and 230 (the letter D). The image is synthetic, with flat regions and no noise, so only three intensity values exist.

8
New cards

What is the main limitation of a histogram?

It says how many pixels have each value but not where they are. Two different images can have the same histogram.

9
New cards

What is the overall strategy for the bacteria images?

Get a mask of the bacteria structure from the phase contrast image, then measure the fluorescence intensity inside that mask.

10
New cards

What is each bacteria image used for?

phase contrast gives the edges + contrast between background + foreground, which is used to make the mask

fluorescence is the signal we are interested in measuring

11
New cards

Why do we need convolution (filtering) before segmentation?

to separate the peaks in the histogram so one part can be called background and the other foreground

filtering also lets us fit the mask to the object more precisely

12
New cards

Why are low contrast images hard to segment?

Their histogram peaks are pushed together, so no single threshold separates background from foreground cleanly.

13
New cards

What is convolution?

Sliding a small grid of numbers (the kernel) across an image. At each pixel you multiply the kernel values by the pixel values under it, add them up and write that sum into a new image.

14
New cards

Why is convolution called an intensity transformation in the spatial domain?

each output value depends on nearby pixels, not just on the pixel itself

each output pixel is a weighted combination of a pixel + its neighbours

15
New cards

What is the mean kernel and what does it do?

A 3x3 grid where every entry is 1/9 (np.full((3, 3), 1/9)). Multiplying and summing gives the average of a pixel and its 8 neighbours, so it is a mean blur filter.

16
New cards

After mean filtering the bright square, why did the centre pixel stay at 1?

All 9 pixels under the kernel were 1, so the weighted sum was 9 x 1/9 = 1.

17
New cards

After mean filtering, why did the edges and corners of the square drop in value?

The kernel there covers a mix of 1s and 0s. A pixel on a straight edge has six 1s in its 3x3 window, so it averages to 6/9 = 0.67. A corner pixel of the square has four 1s, so it gives 4/9 = 0.44.

18
New cards

What is the overall effect of the mean filter on the sharp square?

sharp edge is smoothed out into a gradient

on real images this averaging also reduces random noise + blurs the image

mean filter replaces each pixel’s intensity with the average intensity of the neighbouring pixels

in this case, the sharp transition between the object (square) and the background becomes smoother

19
New cards

How does ndi.correlate relate to true convolution?

True convolution flips the kernel and correlation does not. For a symmetric kernel like the mean kernel the result is identical, so the lecture treats them as the same idea.

20
New cards

What does a median filter do?

replaces each pixel with the median of the brightnesses in its neighbourhood, instead of the mean

21
New cards

Why is the median filter not a kernel with fixed weights?

It sorts the neighbourhood values and picks the middle one, rather than multiplying by fixed weights and summing.

22
New cards

Why does the median filter remove noise without blurring edges as much?

median is not affected by individual noise spikes, because an extreme value ends up at the end of the sorted list + is ignored

it also never creates new in-between values.

23
New cards

What happened when a 3x3 median filter was applied to the bright square?

Only a plus-shaped cross of 5 pixels was left. The block's corners had only 4 white pixels out of 9, so they were outvoted by the black background and turned black.

24
New cards

What is the main disadvantage of a median filter with a square 3x3 neighbourhood?

pixel can be outvoted by its neighbours

hurts thin lines + sharp corners, because they have few pixels of their own + surrounding background wins vote

25
New cards

Which features survive a square median filter well?

Straight, thick edges.

26
New cards

How can the median filter's damage to lines and corners be reduced?

choose a different shape for the neighbourhood, e.g., a cross (morphology.disk(1)), which uses only the centre + its up, down, left and right neighbours

27
New cards

What is a low-pass filter?

A filter that keeps slow variations and removes high-frequency content (noise and fine detail). It smooths or blurs the image and reduces noise at the cost of softening edges.

28
New cards

What is a high-pass filter?

A filter that keeps fast variations (edges and fine detail) and removes smooth regions. It is used for edge detection and sharpening, and is roughly the original minus the low-pass (blurred) version.

29
New cards

What is a Gaussian filter?

a smoothing filter that replaces each pixel with a weighted average of its neighbours

pixels closer to the centre of the kernel receive higher weights, pixels further away receive lower weights.

gives a smoother + more natural blur than the flat mean kernel, and reduces noise

30
New cards

What shape are the weights of a Gaussian kernel?

A Gaussian (bell curve). The centre pixel gets the largest weight and the weights fall off smoothly with distance. The mean kernel gives every neighbour the same weight.

31
New cards

What does sigma control in a Gaussian filter?

sigma = amount of blur

small sigma = slight blur, large sigma = strong blur but needs a larger kernel, since weights spread further out

32
New cards

Why is overall image brightness preserved by a Gaussian filter?

The kernel weights sum to 1.

33
New cards

What is a segmentation mask?

boolean array the same shape as the image

pixels above threshold are True (signal / foreground)

pixels below are False (background)

34
New cards

How do you create a boolean mask in code?

mask = image > threshold, for example boolean_mask = mean_square > 0.2

this creates a mask of true (1s) and false (0s) values, indicating which pixels satisfy the condition

35
New cards

What does image[mask] give you?

only the signal pixel values, i.e. the pixels where the mask is True

36
New cards

What does mask.sum() give you?

The number of signal pixels (True counts as 1), so it measures the area of the object.

37
New cards

What does foreground_signal = mean_square * boolean_mask do?

Keeps the original intensity values where the mask is True and sets everything else to 0, leaving only the foreground signal.

38
New cards

How can you choose a threshold?

manually, by looking at the histogram + picking a value in the dip between the two populations, or automatically with Otsu's method

39
New cards

When can a threshold be reused on a batch of images?

If they were acquired under the same conditions, unless brightness varies between images.

40
New cards

Why is Otsu's method needed?

picking a threshold by eye from the histogram is subjective + doesn't work for a batch of images

41
New cards

What is the idea behind Otsu's threshold?

Find the threshold that makes the two groups (below and above it) as different from each other and as tight internally as possible.

42
New cards

What are the steps of Otsu's method?

1) compute histogram

2) for each threshold t, split the pixels into group 1 + group 2

3) compute the variance of each group + combine them, weighted by the number of pixels in each

4) choose the t with the lowest combined within-group variance

43
New cards

How many thresholds does Otsu try?

Every possible one, 0 to 255 for a uint8 image.

44
New cards

Minimising within-group variance is equivalent to what?

Maximising the variance between the two groups' means.

45
New cards

When does Otsu work best and when does it struggle?

works best on a histogram with two clear peaks (bimodal)

struggles when one population is a tiny fraction of the image, when illumination is uneven, or when there are more than 2 populations

46
New cards

What happened when Otsu was applied to mean_square?

It found a threshold of about 0.22, close to the manually chosen 0.2. This shows Otsu automatically finds a sensible threshold between background and signal.

47
New cards

Code for Otsu thresholding with skimage?

t = filters.threshold_otsu(image) then mask = image > t.

48
New cards

What is a footprint in morphology?

A small neighbourhood shape that slides over a binary mask. Entries of 1 mean that neighbour is included in the check and 0 means it is ignored. morphology.square(3) is a 3x3 square of 1s.

49
New cards

How does a morphology footprint differ from a convolution kernel?

footprint only marks which pixels count + simple rule (all True or any True) decides output

convolution kernel holds weights that are multiplied by pixel values + summed

50
New cards

What is the rule for erosion?

A pixel stays True only if every pixel under the footprint is True. If any neighbour is False (black), the pixel becomes False.

51
New cards

What are the effects of erosion?

object boundaries move inwards by one pixel so objects shrink

small specks + thin protrusions disappear completely because they can't fill the footprint

holes inside objects get bigger, it can split apart joined objects.

52
New cards

What is the rule for dilation?

a pixel becomes True if at least one pixel under the footprint is True

53
New cards

What are the effects of dilation?

Object boundaries move outwards by one pixel so objects grow. Small holes and gaps are filled in. Nearby objects can end up merging.

54
New cards

Erosion vs dilation in one line?

Erosion uses the rule "all neighbours must be True" and shrinks objects. Dilation uses "any neighbour True" and grows objects.

55
New cards

By how much does erosion enlarge a hole?

By one pixel on every side, so an n x m hole becomes (n+2) x (m+2). In the lecture the 3x3 hole became 5x5.

56
New cards

Why did the lecture use ndi.zoom(boolean_mask, 4, order=0)?

to upsample the 7x7 mask to 28x28 (each pixel becomes a 4x4 block) so a 3x3 footprint is small relative to the shape + erosion and dilation are visible

order=0 is nearest-neighbour so values stay True/False

57
New cards

How do you fill holes in a mask?

Closing: dilate repeatedly, then erode the same number of times. Dilation grows the white area around a hole inwards so the hole shrinks. Erosion then brings the outer edge back to its original size, and the filled holes don't reappear.

58
New cards

Why did the lecture dilate twice and then erode twice to fill holes?

The 3x3 hole needs two dilations to close (3 to 1 to 0 pixels across). The same number of erosions then restores the object's original size.

59
New cards

What is a limitation of closing?

Too many iterations can merge nearby objects, and erosion won't separate them again. It also fills real gaps, not just noise holes.

60
New cards

How do you remove small objects from a mask?

Opening: erode first, then dilate. Erosion deletes objects smaller than the footprint, and dilation restores the size of the surviving large objects.

61
New cards

Why does erode-then-dilate remove small objects but keep large ones?

A 2x2 or smaller object can't fit a 3x3 footprint, so it disappears completely during erosion. Large objects only lose a one-pixel layer, and dilation grows them back to their original size. Small objects are already gone so nothing grows back.

62
New cards

Opening vs closing?

closing = dilate then erode, which fills holes

opening = erode then dilate, which removes small objects

opening is the reverse of hole filling

63
New cards

What is a limitation of opening?

It rounds off corners and can remove thin but real structures, so the footprint size must be chosen carefully.

64
New cards

Semantic vs instance segmentation?

Semantic segmentation only cares about the object (everything is labelled 1). Instance segmentation labels each object individually with a unique number so each can be measured separately.

65
New cards

What is the purpose of connected component labelling?

To give every separate object in a binary mask its own unique number, so everything labelled 1 can be measured together, everything labelled 2 together, and so on.

66
New cards

How does the first pass of connected component labelling work?

scan row by row (raster scan)

for each True pixel, look at the already-visited neighbours

if none is labelled, start a new label, if one is labelled, copy it

if 2 different labels meet, keep one + record in an equivalence table that they are the same object

67
New cards

Why are two passes needed in connected component labelling?

During the first pass the scan doesn't yet know that separate-looking parts will later be joined (e.g. the two arms of the U are joined by the bottom bar). The equivalence is recorded and all labels are fixed together in a second pass.

68
New cards

What is the equivalence table?

A table organised so every temporary label points to one representative, usually the smallest label in its group. Example: 1 becomes 1, 2 becomes 1, 3 becomes 3. Only the survivors are then renumbered without gaps, so label 3 becomes label 2.

69
New cards

What happens in the second pass of connected component labelling?

Only a lookup. Every pixel is visited once more and its label is replaced using the table, with no neighbour comparisons.

70
New cards

Why do we scan row by row (raster scan)?

It means fewer jumps between memory locations, which is more efficient.

71
New cards

How are diagonally connected blocks treated in the lecture's labelling?

A block connected only diagonally gets its own group. Only up, down, left and right neighbours count as connected (4-connectivity).

72
New cards

What is a problem with this labelling algorithm?

Objects that are really close together may be labelled as one object.

73
New cards

What are the steps to segment and measure bacteria?

Read the phase and fluorescence images into arrays, denoise, remove background intensity gradients, separate pixels into two populations (threshold), create a binary mask from the phase image, apply the mask to the fluorescence image, then measure intensities of the masked regions (the bacteria).

74
New cards

Why does the bacteria image need filtering?

The background is not evenly distributed, and noise can be picked up as bacteria. The histogram peaks can't be pulled apart clearly, so we need sharper peaks.

75
New cards

What did the median filter do to the bacteria image?

It denoised the image while preserving the edges of the objects of interest.

76
New cards

Why was a wide Gaussian filter applied to the bacteria image?

not to pick out objects but to capture the smooth distribution of intensities in the background (it gets lighter going down the image)

kernel size is found by trial and error

77
New cards

How was uneven background illumination corrected?

wide Gaussian blur is used to estimate the background slow brightness changes, wherein it smoothens the transitions in brightness

subtract the estimated background from the original image, giving a more even background + sharper histogram peak

78
New cards

What did the Chambolle total variation filter do?

With the weight tweaked just right, it removes the background noise by smoothing. Increasing the weight further could erode the signal of the bacteria, so there is a trade-off.

79
New cards

What mistakes can the binary mask of the bacteria contain?

Noise on the wrong side of the threshold can be mistaken for bacteria, and two bacteria can be merged into one object. The latter can be excluded by size. The question is what is good enough to get significance in the data.

80
New cards

Why clear the border before measuring bacteria?

Bacteria touching the border may be truncated by the field of view, so their size (pixel count) can't be determined accurately.

81
New cards

Why clear small objects from the bacteria mask?

It removes small specks, which are likely noise rather than bacteria (erode then dilate).

82
New cards

What does labelling the bacteria allow?

Every bacterial cell becomes its own unique labelled object, optionally with different colours per label, so statistics can be computed per cell on the fluorescence intensities. This moves from measurements to statistics and analysis of individual objects.