{"id":40,"date":"2006-02-24T07:00:34","date_gmt":"2006-02-24T12:00:34","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=40"},"modified":"2022-05-29T20:00:39","modified_gmt":"2022-05-30T00:00:39","slug":"all-about-pixel-colors-reference-information","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2006\/02\/24\/all-about-pixel-colors-reference-information\/","title":{"rendered":"All about pixel colors: Reference information"},"content":{"rendered":"<div class=\"alert alert-info\">\r\n<span class=\"alert_icon icon-alert-info-reverse\"><\/span>\r\n<p class=\"alert_heading\"><strong>Note<\/strong><\/p>\r\n<p>See the following posts for new or updated information about this topic:<\/p>\r\n<li><a href=\"https:\/\/blogs.mathworks.com\/steve\/2016\/02\/09\/matlab-image-display-from-data-values-to-pixel-colors\/\">MATLAB image display - from data values to pixel colors<\/a><\/li>\r\n<li><a href=\"https:\/\/blogs.mathworks.com\/steve\/2016\/02\/22\/matlab-image-display-truecolor-and-indexed-images\/\">MATLAB image display - truecolor and indexed images<\/a><\/li>\r\n<li><a href=\"https:\/\/blogs.mathworks.com\/steve\/2016\/02\/29\/matlab-image-display-scaled-indexed-images\/\">MATLAB image display - scaled indexed images<\/a><\/li>\r\n<li><a href=\"https:\/\/blogs.mathworks.com\/steve\/2016\/03\/14\/matlab-image-display-grayscale-and-binary-images\/\">MATLAB image display - grayscale and binary images<\/a><\/li>\r\n<li>MATLAB image display - autoscaling values with imshow<\/li>\r\n<\/div>\r\n\r\n<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p>In this posting I want to summarize all of the factors that control image pixel colors in MATLAB.  This information is in\r\n         the MATLAB documentation, but it is scattered around in several locations.  If this is way too much detail for you, that's\r\n         OK - just come on back next week!\r\n      <\/p>\r\n   <\/introduction>\r\n   <h2>Contents<\/h2>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">image - CData dimensionality<\/a><\/li>\r\n         <li><a href=\"#2\">image - CData class<\/a><\/li>\r\n         <li><a href=\"#3\">image - CDataMapping<\/a><\/li>\r\n         <li><a href=\"#4\">axes - CLim<\/a><\/li>\r\n         <li><a href=\"#5\">figure - Colormap<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>image - CData dimensionality<a name=\"1\"><\/a><\/h3>\r\n   <div>\r\n      <ul>\r\n         <li>If the image CData is three-dimensional, with the size of the third dimension equal to 3, then the CData values are taken\r\n            to represent RGB values directly.  No other image, axes, or figure properties affect the displayed colors. We sometimes call\r\n            these \"truecolor images.\"\r\n         <\/li>\r\n         <li>If the image CData is two-dimensional, then the image display colors come from the figure colormap.  CData values are used\r\n            (either directly or in scaled form) as lookup indices into the colormap.\r\n         <\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>image - CData class<a name=\"2\"><\/a><\/h3>\r\n   <div>\r\n      <ul>\r\n         <li>For truecolor images, the class of the CData array (uint8, uint16, or double) affects which values are displayed as white.\r\n             The triple [0 0 0] is always black.  For double CData, [1 1 1] is white.  For uint8 CData, [255 255 255] is white.  For uint16\r\n            CData, [65535 65535 65535] is white.\r\n         <\/li>\r\n         <li>For direct indexed images, the class of the CData array affects the indexing operation.  For double CData arrays, the value\r\n            1 corresponds to the first colormap color.  For uint8 or uint16 CData arrays, the value 0 corresponds to the first colormap\r\n            color.\r\n         <\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>image - CDataMapping<a name=\"3\"><\/a><\/h3>\r\n   <p>If the image CData is two-dimensional, then the image display colors come from the figure's colormap, and the image CDataMapping\r\n      property controls how the colormap lookup is done.\r\n   <\/p>\r\n   <div>\r\n      <ul>\r\n         <li>If CDataMapping is 'direct', then CData values are used directly as lookup indices into the colormap.<\/li>\r\n         <li>If CDataMapping is 'scaled', then CData values are scaled to form lookup indices into the colormap.<\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <p>For truecolor images, the CDataMapping property has no effect on the displayed pixel colors.<\/p>\r\n   <h3>axes - CLim<a name=\"4\"><\/a><\/h3>\r\n   <p>If the image CData is two-dimensional, and if the image CDataMapping is scaled, then the two-element axes CLim property determines\r\n      the scaling function.  The first element gives the value that maps to the first colormap color, and the second element gives\r\n      the value that maps to the last colormap color.\r\n   <\/p>\r\n   <p>For truecolor images, or if the image CDataMapping property is 'direct', the CLim property has no effect on the displayed\r\n      pixel colors.\r\n   <\/p>\r\n   <h3>figure - Colormap<a name=\"5\"><\/a><\/h3>\r\n   <p>If the image CData is two-dimensional, then all displayed pixel colors come from the figure Colormap.<\/p>\r\n   <p>For truecolor images, the Colormap property has no effect on the displayed pixel colors.<\/p>\r\n  <script language=\"JavaScript\"> \r\n<!--\r\n    function grabCode_40() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='40 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 40';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Steve Eddins';\r\n        copyright = 'Copyright 2006 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n-->\r\n      <\/script>\r\n<noscript>\r\n<em>A JavaScript-enabled browser is required to use the \"Get the MATLAB code\" link.<\/em>\r\n<\/noscript>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_40()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code<\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.1<br><\/p>\r\n<\/div>\r\n<!--\r\n40 ##### SOURCE BEGIN #####\r\n%%\r\n% In this posting I want to summarize all of the factors that control image\r\n% pixel colors in MATLAB.  This information is in the MATLAB\r\n% documentation, but it is scattered around in several locations.  If this\r\n% is way too much detail for you, that's OK - just come on back next week!\r\n\r\n%% image - CData dimensionality\r\n% * If the image CData is three-dimensional, with the size of the third\r\n% dimension equal to 3, then the CData values are taken to represent RGB\r\n% values directly.  No other image, axes, or figure properties affect the\r\n% displayed colors. We sometimes call these \"truecolor images.\"\r\n% * If the image CData is two-dimensional, then the image display colors\r\n% come from the figure colormap.  CData values are used (either directly or\r\n% in scaled form) as lookup indices into the colormap.\r\n\r\n%% image - CData class\r\n% * For truecolor images, the class of the CData array (uint8, uint16, or\r\n% double) affects which values are displayed as white.  The triple [0 0 0]\r\n% is always black.  For double CData, [1 1 1] is white.  For uint8 CData,\r\n% [255 255 255] is white.  For uint16 CData, [65535 65535 65535] is white.\r\n% * For direct indexed images, the class of the CData array affects the\r\n% indexing operation.  For double CData arrays, the value 1 corresponds to\r\n% the first colormap color.  For uint8 or uint16 CData arrays, the value 0\r\n% corresponds to the first colormap color.\r\n\r\n%% image - CDataMapping\r\n% If the image CData is two-dimensional, then the image display colors come\r\n% from the figure's colormap, and the image CDataMapping property controls\r\n% how the colormap lookup is done.\r\n%\r\n% * If CDataMapping is 'direct', then CData values are used directly as\r\n% lookup indices into the colormap.\r\n% * If CDataMapping is 'scaled', then CData values are scaled to form\r\n% lookup indices into the colormap.\r\n%\r\n% For truecolor images, the CDataMapping property has no effect on the\r\n% displayed pixel colors.\r\n\r\n%% axes - CLim\r\n% If the image CData is two-dimensional, and if the image CDataMapping is\r\n% scaled, then the two-element axes CLim property determines the scaling\r\n% function.  The first element gives the value that maps to the first\r\n% colormap color, and the second element gives the value that maps to the\r\n% last colormap color.\r\n%\r\n% For truecolor images, or if the image CDataMapping property is 'direct',\r\n% the CLim property has no effect on the displayed pixel colors.\r\n\r\n%% figure - Colormap\r\n% If the image CData is two-dimensional, then all displayed pixel colors\r\n% come from the figure Colormap.\r\n%\r\n% For truecolor images, the Colormap property has no effect on the\r\n% displayed pixel colors.\r\n\r\n##### SOURCE END ##### 40\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n\r\nNote\r\nSee the following posts for new or updated information about this topic:\r\nMATLAB image display - from data values to pixel colors\r\nMATLAB image display - truecolor and indexed... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2006\/02\/24\/all-about-pixel-colors-reference-information\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/40"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":5555,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/40\/revisions\/5555"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}