May 2020
Intermediate to advanced
530 pages
17h 8m
English
We can use dimensionality reduction algorithms for a slightly different task – data compression with information loss. This can be easily demonstrated when applying the PCA algorithm to images. Let's implement PCA from scratch with the Dlib library using SVD decomposition. We can't use an existing implementation because it performs normalization in a way we can't fully control.
First, we need to load an image and transform it into matrix form:
void PCACompression(const std::string& image_file, long target_dim) { array2d<Dlib::rgb_pixel> img; load_image(img, image_file); array2d<unsigned char> img_gray; assign_image(img_gray, img); save_png(img_gray, "original.png"); array2d<DataType> tmp; assign_image(tmp, img_gray); ...Read now
Unlock full access