Lecture 2
Computer Science Department, Colorado School of Mines
Blue Marble, NASA / Apollo 17
Scene / object
Light as a signal
Camera / sensor
A camera measures light from the world and turns it into a digital image.



Signal: A (multi-dimensional) function that contains information about a phenomenon (e.g., light, heat, gravity, sound, pressure, motion).


Sampling a 2D function returns a matrix.



Image: A sampling of a function that contains information about a 2D signal.
Note
Cameras observe a 2D projection of the 3D world.
2D images appear in many sensing modalities:

Note
The signal may not always be visible light. An image arranges what we have measured over a 2D domain.
World / scene
Continuous signal
Camera
The imaging pipeline converts a continuous physical signal into discrete sensor measurements.
Scene / image plane
Light signal
CMOS / CCD sensor
Digital cameras use sensor arrays to sample light and produce a grid of pixel values.
Camera / sensor hardware
CMOS sensor array
Continuous light is sampled and quantized by the 2D sensor array (pixels) to produce a digital image.
![]()

A digital image can be interpreted as a 2D function whose value is brightness or intensity.
A single pixel does not measure an infinitely thin ray.
It measures light integrated over a small region of the sensor and the corresponding cone/frustum of incoming light.

Note
This is one reason why cameras blur, average, and alias details that are smaller than a pixel can represent.
Both images can have the same number of pixels, but the amount of scene detail represented can be different.
Low geometric resolution
High geometric resolution
Note
Spatial resolution counts pixels. Geometric resolution is how accurately those pixels represent the positions of objects in the real world; or how sharp the image is. Geometric resolution is limited by physics, optics, and the environment (see Rayleigh criterion).


| Bit depth | Number of levels |
|---|---|
| 1 bit | 2 levels |
| 2 bit | 4 levels |
| 4 bit | 16 levels |
| 8 bit | 256 levels |

An image of size \(1000 \times 1000\) with 8-bit quantization per pixel has: \[ 256^{1000 \times 1000} \approx 10^{2,408,239} \] possible intensity configurations.
This is an enormous high-dimensional space – the known universe has only about \(10^{80}\) atoms!
Computer vision works in this extremely high dimensional space – but real images are not arbitrary arrays and they occupy a small, structured subset of this space.
For an \(N \times M\) grayscale image im:

Important
In NumPy, image indexing is usually row first, column second: im[y, x], not im[x, y].

A grayscale image is a matrix that stores one intensity value per pixel.

Note
Different libraries may use different channel order conventions. OpenCV commonly uses BGR; Matplotlib commonly expects RGB.
For an \(N \times M\) color image im with three channels:
Typical shape:
For an RGB image:
For OpenCV-loaded images:
Take care of image data types.
Important
Many image-processing bugs come from mixing uint8, float32, and different value ranges.
r.rand(256, 256) creates a 256 by 256 array of random floating-point values in the range \([0,1)\).
Questions:
I?We will use:
Important
Do not use GenAI to solve homework for you. If you copy-paste code without understanding it, you will not learn how to code.
Be kind and supportive: students come from different backgrounds and have different levels of Python experience.
Course tutorials are available here:
https://ariarobotics.github.io/cv/tutorials/
Review as needed:
Tip
These tutorials are reference material. Use them when you need help with the tools so class time can focus on computer vision.
Recommended workflow:
Keep course Python environments and projects inside WSL.
Open a terminal and check the tools you already have.
Windows users working in WSL can also check:
Tip
If conda is not installed yet, open the Python & Conda tutorial and follow the Miniforge installation section.
We use a dedicated Conda environment named:
The environment file is maintained in the course repository:
https://github.com/ariarobotics/cv/blob/main/code/cv-environment.yml
It defines the software stack used by the course, including:
Do not manually assemble your own version of the environment.
You should now see:
including:
cv EnvironmentFrom the directory containing cv-environment.yml:
This may take several minutes.
The environment file already specifies the name:
When installation finishes:
Your terminal prompt should now begin with something similar to:
Important
Whenever you run course Python code, make sure the cv environment is active.
With cv activated:
Check which Python is being used:
Then verify the main packages:
If all four commands work, the core environment is ready.
Open the project folder from your terminal:
Windows + WSL users should see WSL: Ubuntu in the VS Code status area.
Then:
Ctrl+Shift+PcvFor notebooks, use Select Kernel and choose the same cv environment.
Verify from Python:
The path should point into the cv Conda environment.
Create a file named:
Start by importing the libraries:
Create a folder for output files:
For today’s example, we will create a small synthetic image so everyone has the same input.
height = 360
width = 640
image = np.full(
(height, width, 3),
235,
dtype=np.uint8,
)
# OpenCV uses BGR color ordering.
cv2.rectangle(
image, (70, 80), (260, 280),
(255, 100, 0), thickness=-1
)
cv2.circle(
image, (470, 180), 90,
(0, 180, 255), thickness=-1
)
cv2.putText(
image, "Computer Vision",
(150, 335),
cv2.FONT_HERSHEY_SIMPLEX,
1.0, (30, 30, 30), 2
)
cv2.imwrite(str(output_dir / "sample_image.png"), image)We now have a real image file on disk that we can load with OpenCV.
Load the image:
Inspect it:
You should see something similar to:
An image is fundamentally a NumPy array.
OpenCV loads color images in BGR order.
Matplotlib expects RGB, so convert before displaying:
A useful rule:
Note
Using Matplotlib is also convenient in notebooks and avoids problems that can occur with cv2.imshow() in some WSL setups.
Convert the image to grayscale:
Detect edges:
Display the result:
In only a few lines, we used several ideas that will appear throughout the course:
.shapeuint8conda: command not foundRestart the terminal or reload your shell:
First check:
Use:
and select cv.
If you are using WSL, keep the course environment and projects inside the WSL/Linux filesystem.
Please go through any tutorials that cover tools you are not yet comfortable with:
https://ariarobotics.github.io/cv/tutorials/
In particular, make sure you can:
cv environmentYou do not need to memorize every Git, Conda, or NumPy command. The tutorials are there as references throughout the semester.
Computer Vision; Colorado School of Mines | Kaveh Fathian