Post Image
By Matt GaidicaMarch 11, 2020In Uncategorized

Reducing Image Colors Using a Custom Palette in MATLAB

You have specific set of colors to choose from and you want to convert in image from “full color” to “reduced color”. I have split this into two steps:

  1. Generate a palette in the form of a colormap.

  2. Apply that palette to an image.

Selecting a Palette

This script will display an image and leverage impixel() to create a colormap (or palette) based on your selections. Click as many points as you would like then press enter. It will overlay the colors you selected on the image.

Select color points, then press enter.

Select color points, then press enter.

Your palette is shown and returned.

Your palette is shown and returned.

Applying your limited palette

Running this short script will execute the pelette maker function and then let you view the results. You’ll notice that the resulting image is only made from the colors selected. It writes a file for the image at the end.

Original image (left) and reduced palette image (right)

Original image (left) and reduced palette image (right)

Zoomed version

Zoomed version

Final Notes

The mapping of colors might not come out as you intended, which is a limitation. Re-mapping based on some set of rules might be really nice. You can see below how selecting from a larger palette of 10 colors begins to approximate the original image much better. This method could be used to ideally compress an image if a specific palette is required—perhaps a problem more suited for 1980’s video game programmers. In my case, I wanted to make a dot painting without remixing the paint I bought.

Screen Shot 2020-03-11 at 7.44.12 AM.png

Screen Shot 2020-03-11 at 7.43.53 AM.png

svgDesigning a Bluetooth Antenna: How to go about it
svg
svgReplaying Neural Signals using a Headphone Jack