Profile-Based Color Space Conversions
If two colors have the same CIE colorimetry, they will match if viewed under the same conditions. However, because color images are typically produced for a wide variety of viewing environments, it is necessary to go beyond simple application of the CIE system.
For this reason, the International Color Consortium (ICC) has defined a Color Management System (CMS) that provides a means for communicating color information among input, output, and display devices. The CMS uses device profiles that contain color information specific to a particular device. Vendors that support CMS provide profiles that characterize the color reproduction of their devices, and methods, called Color Management Modules (CMM), that interpret the contents of each profile and perform the necessary image processing.
Device profiles contain the information that color management systems need to translate color data between devices. Any conversion between color spaces is a mathematical transformation from some domain space to a range space. With profile-based conversions, the domain space is often called the source space and the range space is called the destination space. In the ICC color management model, profiles are used to represent the source and destination spaces.
For more information about color management systems, go to the International Color Consortium website, https://www.color.org.
Read ICC Profiles
To read an ICC profile into the workspace, use the
function. In this example, the function reads in the profile for the color space that
describes color monitors.
P = iccread('sRGB.icm');
You can use the
iccfind function to find ICC color
profiles on your system, or to find a particular ICC color profile whose description
contains a certain text string. To get the name of the directory that is the default
system repository for ICC profiles, use
iccread returns the contents of the profile in the structure
P. All profiles contain a header, a tag table, and a series of
tagged elements. The header contains general information about the profile, such as the
device class, the device color space, and the file size. The tagged elements, or tags,
are the data constructs that contain the information used by the CMM. For more
information about the contents of this structure, see the
iccread function reference page.
iccread, you can read both Version 2 (ICC.1:2001-04) or
Version 4 (ICC.1:2001-12) ICC profile formats. For detailed information about these
specifications and their differences, visit the ICC website, https://www.color.org.
Write ICC Profile Information to a File
To export ICC profile information from the workspace to a file, use the
iccwrite function. This example reads a profile into the workspace
and then writes the profile information out to a new file.
P = iccread('sRGB.icm'); P_new = iccwrite(P,'my_profile.icm');
iccwrite returns the profile it writes to the file in
P_new because it can be different than the input profile
P. For example,
iccwrite updates the
Filename field in
P to match the name of the
file specified as the second argument.
When it creates the output file,
iccwrite checks the validity of
the input profile structure. If any required fields are missing,
iccwrite returns an error message. For more information about the
writing ICC profile data to a file, see the
iccwrite function reference page. To determine if a structure is a valid
ICC profile, use the
iccwrite, you can export profile information in both Version
2 (ICC.1:2001-04) or Version 4 (ICC.1:2001-12) ICC profile formats. The value of the
Version field in the file profile header determines the format
version. For detailed information about these specifications and their differences,
visit the ICC website, https://www.color.org.
Convert RGB to CMYK Using ICC Profiles
This example shows how to convert color data from the RGB color space used by a monitor to the CMYK color space used by a printer. This conversion requires two profiles: a monitor profile and a printer profile. The source color space in this example is monitor RGB and the destination color space is printer CMYK:
Import RGB color space data. This example imports an RGB color image into the workspace.
I_rgb = imread('peppers.png');
Read ICC profiles. Read the source and destination profiles into the workspace. This example uses the sRGB profile as the source profile. The sRGB profile is an industry-standard color space that describes a color monitor.
inprof = iccread('sRGB.icm');
For the destination profile, the example uses a profile that describes a
particular color printer. The printer vendor supplies this profile. (The following
profile and several other useful profiles can be obtained as downloads from
outprof = iccread('USSheetfedCoated.icc');
Create a color transformation structure. You must create a color transformation
structure to define the conversion between the color spaces in the profiles. You
makecform function to create the structure, specifying
a transformation type string as an argument. This example creates a color
transformation structure that defines a conversion from RGB color data to CMYK
color data. The color space conversion might involve an intermediate conversion
into a device-independent color space, called the Profile Connection Space (PCS),
but this is transparent to the user.
C = makecform('icc',inprof,outprof);
Perform the conversion. You use the
applycform function to
perform the conversion, specifying as arguments the color data you want to convert
and the color transformation structure that defines the conversion. The function
returns the converted data.
I_cmyk = applycform(I_rgb,C);
Write the converted data to a file. To export the CMYK data, use the
imwrite function, specifying the format as TIFF. If the
format is TIFF and the data is an m-by-n-by-4 array,
writes CMYK data to the file.
To verify that the CMYK data was written to the file, use
imfinfo to get information about the file and look at the
info = imfinfo('pep_cmyk.tif'); info.PhotometricInterpretation
ans = 'CMYK'
What is Rendering Intent in Profile-Based Conversions?
For most devices, the range of reproducible colors is much smaller than the range of colors represented by the PCS. It is for this reason that four rendering intents (or gamut mapping techniques) are defined in the profile format. Each one has distinct aesthetic and color-accuracy tradeoffs.
When you create a profile-based color transformation structure, you can specify the
rendering intent for the source as well as the destination profiles. For more
information, see the
makecform reference information.