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:
-
Generate a palette in the form of a colormap.
-
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.
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.
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.
Recent Comments
Archives
- April 2023
- January 2023
- November 2022
- May 2022
- March 2022
- January 2022
- December 2021
- April 2021
- December 2020
- October 2020
- August 2020
- July 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- January 2019
- December 2018
- November 2018
- August 2018
- July 2018
- April 2018
- March 2018
- November 2017
- October 2017
- February 2017
- October 2016
- August 2016
- July 2016
- November 2015
- October 2013
- February 2013
- January 2013
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- February 2012
- December 2011