Computer Vision Lab Manual 1
Computer Vision Lab Manual 1
Memory Optimization
Python’s Default Integer:
o Python’s built-in int type is an object, which typically takes about 28
bytes per integer.
o This extra overhead makes it inefficient when processing images,
which contain thousands or millions of pixels.
NumPy’s Data Types:
o With NumPy, you can explicitly set the data type using the dtype
parameter.
o For example, using np.uint8 (an 8-bit unsigned integer) ensures each
number takes 1 byte.
o You can also use other types like np.int32 (4 bytes per number) by
employing the astype() function for type conversion.
Example Calculation
1. Number of Pixels:
Faster Computation
Vectorized Operations:
NumPy arrays support vectorized operations that apply functions element-
wise without explicit Python loops. This is significantly faster than iterating
over Python lists or objects.
Optimized Low-Level Code:
NumPy’s underlying implementation in C allows it to perform mathematical
calculations at a much lower level, reducing the execution time.
tasks gaming
Data
Homogeneous Heterogeneous
Type