17. Naïve Box Blur
Image convolution - the convolution of a 2D image is O(m2*n2)
For it to be fast you must implement it as an accumulator, not a convolution loop.
for each row
for each col
set count to 0
for every neighboring pixel within the radius m in the x direction
for every neighboring pixel within the radius m in the y direction
add the color to the total
count++
final_color = total/count
setpixel(current x, current y, final_color)
21. Better Box Blur
Image convolution - the convolution of a 2D image is O(n^2 * 2m)
For it to be fast you must implement it as an accumulator, not a convolution loop.
for each row
for every neighboring pixel within the radius m in the x direction
add the color to the total
count++
final_color = total/count
setpixel(current x, current y, final_color)
!
repeat above for the columns
22. Calculate all Pixels
Sample image 6 x 6 pixels, radius is 2
in the x direction
in the y direction
if x <= r
for var _i=i-x; _i<=i+r; _i++
if x > r && x < (w-r)
for var _i=i-r; _i<=i+r; _i++
if x >= (w-r)
for var _i=i-r; _i<=i+(w-x); _i++
if _y <= r
for var _i=0; _i<=_y+r; _i++
let currentIndex = _i*w+_x
if r < _y && _y < (h-r)
for var _i=_y-r; _i<=_y+r; _i++
let currentIndex = _i*w+_x
if _y >= (h-r)
for var _i=_y-r; _i<=(h-1); _i++
let currentIndex = _i*w+_x
25. Convolution
for each image row in output image:
for each pixel in image row:
!
set accumulator to zero
!
for each kernel row in kernel:
for each element in kernel row:
!
if element position corresponding* to pixel position then
multiply element value corresponding* to pixel value
add result to accumulator
endif
!
set output image pixel to accumulator
26. Accelerate Framework
Consists of two frameworks: vImage and vecLib
Available in OS X v10.4
Use vector co-processor (CPU-based)
Designed to run various mathematical operations with data
Well optimized and uses SIMD