$ \gdef\vec#1{\mathbf{#1}} \gdef\d{d} $

Image posterization using principal component analysis

May 2025

Here's the idea: want a grayscale image? Project onto the first principal component. It works pretty well.

Processing image...

Original Image

Original image

Grayscale

Here's some yap about how I did this. I couldn't figure out how to use javascript libraries to I wrote a barebones program to find the first principal component. Finding the covariance matrix is pretty straightforward, especially since this is only $3\times3$ so I just hard coded it. Our professor randomly covered power method in linear algebra II which I thought was weird at the time, but I guess it saved me this time. I only wanted the first principal component, so I used power iteration to find it. Everything is hard coded since I didn't have a linear algebra library and didn't want to write one. The rest of the program is vibe coded with the help of cursor.

Some possible extensions to this include: (1) using the projected values on the principal component instead of only the lengths, to get an image along a single color spectrum, and (2) using two principal components to get an image with two colors. I hope to do color quantization with some sort of clustering soon but that's unrelated to this.