1/81
Looks like no tags are added yet.
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.
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
What does d.shape = (546, 658) tell you?
The array has 546 rows (height) and 658 columns (width), in that order.
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.
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.
What does a histogram show?
counts how many pixels have each intensity value
x-axis = pixel intensity value
y-axis = # pixels with that value
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.
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.
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.
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
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
Why are low contrast images hard to segment?
Their histogram peaks are pushed together, so no single threshold separates background from foreground cleanly.
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.
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
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.
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.
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.
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
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.
What does a median filter do?
replaces each pixel with the median of the brightnesses in its neighbourhood, instead of the mean
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.
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.
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.
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
Which features survive a square median filter well?
Straight, thick edges.
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
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.
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.
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
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.
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
Why is overall image brightness preserved by a Gaussian filter?
The kernel weights sum to 1.
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)
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
What does image[mask] give you?
only the signal pixel values, i.e. the pixels where the mask is True
What does mask.sum() give you?
The number of signal pixels (True counts as 1), so it measures the area of the object.
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.
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
When can a threshold be reused on a batch of images?
If they were acquired under the same conditions, unless brightness varies between images.
Why is Otsu's method needed?
picking a threshold by eye from the histogram is subjective + doesn't work for a batch of images
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.
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
How many thresholds does Otsu try?
Every possible one, 0 to 255 for a uint8 image.
Minimising within-group variance is equivalent to what?
Maximising the variance between the two groups' means.
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
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.
Code for Otsu thresholding with skimage?
t = filters.threshold_otsu(image) then mask = image > t.
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.
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
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.
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.
What is the rule for dilation?
a pixel becomes True if at least one pixel under the footprint is True
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.
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.
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.
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
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.
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.
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.
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.
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.
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
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.
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.
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.
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
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.
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.
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.
Why do we scan row by row (raster scan)?
It means fewer jumps between memory locations, which is more efficient.
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).
What is a problem with this labelling algorithm?
Objects that are really close together may be labelled as one object.
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).
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.
What did the median filter do to the bacteria image?
It denoised the image while preserving the edges of the objects of interest.
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
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
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.
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.
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.
Why clear small objects from the bacteria mask?
It removes small specks, which are likely noise rather than bacteria (erode then dilate).
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.