Convert RGB colors to indexed colormap colors in Matlab
rgb2map
converts an RGB image or colormap to an indexed color image or colormap using color differences. rgb2map
calculates the color difference between each RGB pixel in an input image and every RGB triplet in the input colormap by calculating ΔE in the CIE Lab* color space (CIE 1976 standard). The min
function is used to find the index of the minimum ΔE (if more than one minimum value exists, the index of the first is returned). The function is an alternative to Matlab’s rgb2ind
.
Andrew D. Horchler, horchler @ gmail . com, biorobots.case.edu
Created: 5-2-15, Revision: 1.1, 6-20-15
This version tested with Matlab 9.0.0.341360 (R2016a)
Mac OS X 10.11.4 (Build: 15E65), Java 1.7.0_75-b13
Compatibility maintained back through Matlab 8.5 (R2015a)
Copyright © 2015–2017, Andrew D. Horchler
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANDREW D. HORCHLER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.