ENGGEN 131 Chap.4 Matrices, Images and Transformations
Matrices, Images and Transformations
This chapter connects matrix coordinates with image pixels. It develops row-column indexing, full-row and full-column selection, dimension prediction, grayscale ranges, thresholding and the choice between elementwise transformations and matrix multiplication. Original image patches make output shape and pixel location visible, including boundary rules and border cases for neighbourhood operations.
What this chapter covers
- 01
Row and column subscripts
- 02
Full-row and full-column selection
- 03
Image intensity matrices and data range
- 04
Threshold and brightness transformations
- 05
Dimension compatibility for matrix multiplication
Worked example · free
Threshold a small image patch
- 1The first row becomes [0 255].
- 1The second row becomes [0 255].
- 1The result remains two rows by two columns.
Key terms
- Pixel intensity
- A numeric value controlling the displayed brightness of one image position.
- Threshold
- A cut-off used to assign values to classes.
- Inner dimensions
- The matching dimensions required for a matrix product to exist.
Matrices, Images and Transformations FAQ
What does A(:,3) select?
It selects every row in column three and returns a column containing those entries. Rehearse this distinction with a fresh coordinate and dimension trace before relying on program output.
Why can a row-column mistake run successfully?
The swapped coordinate may still identify a legal but unintended element, so valid syntax does not prove the location is correct. Test the claim on a boundary case where the coordinate and dimension assumptions become visible.
How do I choose between multiplication forms?
Use elementwise multiplication for independent pixel or measurement pairs and matrix multiplication for genuine weighted combinations with compatible dimensions. Write the expected coordinate and dimension state first, then compare it carefully with execution.
Exam move
Write every matrix size as rows by columns and label the first subscript row and the second column. Draw a small coordinate grid for selections that involve orientation. Before evaluating any expression, predict the output size. A complete row selection has one row, a complete column selection has one column, transposition swaps the dimensions, concatenation changes a named dimension and cropping reduces the selected extent.
Treat the predicted size as part of the answer, not as an optional formatting detail. Separate elementwise operations from matrix algebra by describing the engineering relationship. If each pixel or measurement is transformed independently, dotted multiplication, division or power usually expresses that model and preserves size.
If each output is a weighted combination of several inputs, matrix multiplication may be appropriate and must satisfy inner-dimension compatibility. Do not add a dot merely to silence an error. Write the output dimensions first and explain which inputs contribute to a single result entry. For image questions, record class, numerical range and spatial size before transforming data.
Work a two-by-two patch by hand, preserving row and column positions. If thresholding, state which side contains equality and count how many values enter each class. If adding brightness or converting class, predict possible minimum and maximum outputs and whether clipping or scaling occurs.
A visually plausible display is weak evidence: saturation, implicit conversion or transposition can remain hidden unless numerical range and coordinates are checked directly. Build tests that distinguish orientation errors. Use a nonsymmetric matrix with unique entries so swapping row and column produces an obviously different value. For a crop, label the original coordinates that should occupy the new corners.
For a transformation using neighbours, identify border positions and the rule applied where a complete neighbourhood does not exist. Verify the number of output rows and columns and sample both an interior and a boundary location. Avoid square, symmetric examples when they conceal a transpose. Practise dimension reasoning without arithmetic.
Given two matrix sizes, decide whether addition, elementwise multiplication and matrix multiplication are defined and state each result size. Then compute a single chosen entry of a valid matrix product as a row-column dot product. Contrast that with the same-position product from elementwise multiplication.
For logical masks, confirm that the mask has the same size as the input and that every true location corresponds to the written threshold rule. This isolates structural understanding from calculation load. Complete revision with a transformation audit containing requirement, input representation, operator meaning, predicted shape, predicted range, hand-worked sample and observed result.
When prediction differs, locate the first failed property rather than adjusting display settings. Keep a list of defects by category: coordinate swap, dimension mismatch, dotted-operator error, threshold equality, clipping and border policy. Mastery means explaining why each output value belongs at its location and why the resulting array has its stated shape and range.
Use one final nonsymmetric image patch to integrate the checks. Label its row and column coordinates, data class and value range. Predict the dimensions and corner coordinates after a crop, then apply an intensity threshold whose equality rule is written explicitly. Calculate the transformed patch by hand, including its minimum, maximum and count of selected pixels.
Compare an elementwise scaling with a small matrix product and explain why their output meanings differ even if both dimensions are legal. Include a border location so the neighbourhood policy must be stated. The completed audit should reconcile operator choice, coordinate locations, result shape, numerical range and representation.
If a displayed image seems correct but any one of those properties disagrees, treat the disagreement as evidence of a transformation defect rather than adjusting the display.