{"id":39,"date":"2006-02-17T07:00:05","date_gmt":"2006-02-17T12:00:05","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=39"},"modified":"2022-05-29T19:59:44","modified_gmt":"2022-05-29T23:59:44","slug":"all-about-pixel-colors-window-level","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2006\/02\/17\/all-about-pixel-colors-window-level\/","title":{"rendered":"All about pixel colors: Window-level and CLim"},"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   <p>In a <a>comp.soft-sys.matlab<\/a> newsgroup post on January 17, Kevin wanted to know how the brightness\/contrast control in <tt>imtool<\/tt> worked.  Image Processing Toolbox function <a title=\"https:\/\/www.mathworks.com\/help\/images\/ref\/imtool.html (link no longer works)\"><tt>imtool<\/tt><\/a> is an image viewing\/navigation GUI.\r\n   <\/p>\r\n   <p>In medical imaging the brightness\/contrast control is called the \"window\/level\" control, and there is a reasonably standard\r\n      set of mouse motions for changing the window and level. These mouse motions are supported by <tt>imtool<\/tt>.\r\n   <\/p>\r\n   <p>This diagram shows how the terms \"window\" and \"level\" are related to brightness and contrast adjustment.  Making the window\r\n      wider or narrower decreases or increases the display contrast; moving the level left or right changes the display brightness.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/39\/windowlevel.png\"> <\/p>\r\n   <p>This window-level scaling function is just like the CLim scaling function I <a href=\"https:\/\/blogs.mathworks.com\/steve\/?p=33\">described previously<\/a>.  I replied to Kevin that the brightness\/contrast control in <tt>imtool<\/tt> worked by adjusting the axes CLim property.\r\n   <\/p>\r\n   <p>Here's an non-medical example of how adjusting the CLim can make previously unseen image details visible.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">I = imread(<span style=\"color: #A020F0\">'cameraman.tif'<\/span>);\r\nimshow(I)\r\ntext(256, 265, <span style=\"color: #A020F0\">'Image courtesy of Massachusetts Institute of Technology'<\/span>, <span style=\"color: #0000FF\">...<\/span>\r\n   <span style=\"color: #A020F0\">'HorizontalAlignment'<\/span>, <span style=\"color: #A020F0\">'right'<\/span>, <span style=\"color: #A020F0\">'FontWeight'<\/span>, <span style=\"color: #A020F0\">'light'<\/span>, <span style=\"color: #A020F0\">'FontSize'<\/span>, 7, <span style=\"color: #0000FF\">...<\/span>\r\n   <span style=\"color: #A020F0\">'Color'<\/span>, [.7 .7 .7])<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/39\/windowlevel_clim_01.png\"> <p>Not much detail is visible in the coat or glove.  But you can make out much more detail if you change the CLim property of\r\n      the axes:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">imshow(I)\r\nset(gca, <span style=\"color: #A020F0\">'CLim'<\/span>, [6 21])  <span style=\"color: #228B22\">% caxis([6 21]) does the same thing.<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/39\/windowlevel_clim_02.png\">\r\n <script language=\"JavaScript\"> \r\n<!--\r\n    function grabCode_39() {\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='39 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 39';\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_39()\"><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\n39 ##### SOURCE BEGIN #####\r\n%%\r\n% In a <http:\/\/.shtml\r\n% comp.soft-sys.matlab> newsgroup post on January 17, Kevin wanted to know\r\n% how the brightness\/contrast control in |imtool| worked.  Image Processing\r\n% Toolbox function\r\n% <https:\/\/www.mathworks.com\/help\/images\/index.htmldisplay7.html#39829 \r\n% |imtool|> is an image viewing\/navigation GUI.  \r\n%\r\n% In medical imaging the brightness\/contrast control is called the\r\n% \"window\/level\" control, and there is a reasonably standard set of mouse\r\n% motions for changing the window and level. These mouse motions are \r\n% supported by |imtool|.\r\n%\r\n% This diagram shows how the terms \"window\" and \"level\" are related to\r\n% brightness and contrast adjustment.  Making the window wider or narrower\r\n% decreases or increases the display contrast; moving the level left or\r\n% right changes the display brightness.\r\n%\r\n% <<wp-content\/images\/39\/windowlevel.png>>\r\n%\r\n% This window-level scaling function is just like the CLim scaling function \r\n% I <https:\/\/blogs.mathworks.com\/steve\/?p=33 described previously>.  I \r\n% replied to Kevin that the brightness\/contrast control in |imtool|\r\n% worked by adjusting the axes CLim property.\r\n%\r\n% Here's an non-medical example of how adjusting the CLim can make\r\n% previously unseen image details visible.\r\n\r\nI = imread('cameraman.tif');\r\nimshow(I)\r\ntext(256, 265, 'Image courtesy of Massachusetts Institute of Technology', ...\r\n   'HorizontalAlignment', 'right', 'FontWeight', 'light', 'FontSize', 7, ...\r\n   'Color', [.7 .7 .7])\r\n\r\n%%\r\n% Not much detail is visible in the coat or glove.  But you can make out\r\n% much more detail if you change the CLim property of the axes:\r\n\r\nimshow(I)\r\nset(gca, 'CLim', [6 21])  % caxis([6 21]) does the same thing.\r\n\r\n%%\r\n% If you want to see how to make this adjustment interactively, look\r\n% <https:\/\/www.mathworks.com\/help\/images\/index.htmlf10-44495.html\r\n% here> in the Image Processing Toolbox Users Guide.\r\n\r\n##### SOURCE END ##### 39\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\/17\/all-about-pixel-colors-window-level\/\">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":[80,76,36,78],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/39"}],"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=39"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":5552,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/39\/revisions\/5552"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}