{"id":387,"date":"2011-08-26T19:27:42","date_gmt":"2011-08-26T19:27:42","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2011\/08\/26\/digital-image-processing-using-matlab-digital-image-representation\/"},"modified":"2011-08-26T20:33:20","modified_gmt":"2011-08-26T20:33:20","slug":"digital-image-processing-using-matlab-digital-image-representation","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2011\/08\/26\/digital-image-processing-using-matlab-digital-image-representation\/","title":{"rendered":"Digital image processing using MATLAB: digital image representation"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p>Today I'm starting an regular, occasional series with tutorial material on digital image processing using MATLAB. I'm going\r\n         to look at topics in roughly the order used in the book <a href=\"http:\/\/imageprocessingplace.com\/DIPUM-2E\/dipum2e_main_page.htm\"><i>Digital Image Processing Using MATLAB<\/i><\/a>, Gatesmark Publishing, 2009, by Gonzalez, Woods, and Eddins. (Yes, that's me. It was a lot of nights and weekends.)\r\n      <\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Digital image representation<\/a><\/li>\r\n         <li><a href=\"#2\">Coordinate conventions<\/a><\/li>\r\n         <li><a href=\"#3\">Images as matrices and arrays<\/a><\/li>\r\n         <li><a href=\"#4\">For more information<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Digital image representation<a name=\"1\"><\/a><\/h3>\r\n   <p>Let's start with digital image representation. (I do not plan to cover image formation. For that topic, see Chapter 2 of <i>Digital Image Processing<\/i>, Prentice Hall, 2008, by Gonzalez and Woods.) The common mathematical representation of an image is a function of two continuous\r\n      spatial coordinates: \\( f(x,y) \\). The value \\( f(x_0,y_0) \\)  is often called the image <i>intensity<\/i> at \\( (x_0,y_0) \\), although that term is used loosely because it often does not represent actual light intensity. The term <i>gray level<\/i> is also commonly used.\r\n   <\/p>\r\n   <p>You can represent a color image mathematically in a couple of different ways. One way is to use a collection of image functions,\r\n      one per color component, such as \\( r(x,y) \\), \\( g(x,y) \\), and \\( b(x,y) \\). Another way is to use a vector-valued function, \\( {\\mathbf f}(x,y) \\).\r\n   <\/p>\r\n   <p>Many functions in the Image Processing Toolbox also support higher-dimensional images. For example, \\( f \\) might be a function of three spatial variable, as in \\( f(x,y,z) \\). Image Processing Toolbox documentation calls this a <i>multidimensional image<\/i>.\r\n   <\/p>\r\n   <p>Converting the amplitude values of \\( f \\) to a set of discrete values is called <i>quantization<\/i>. Capturing those values at discrete spatial coordinates is called <i>sampling<\/i>. When \\( x \\), \\( y \\), and the values of \\( f \\) are all finite, discrete quantities, we call <i>f<\/i> a <i>digital image<\/i>.\r\n   <\/p>\r\n   <h3>Coordinate conventions<a name=\"2\"><\/a><\/h3>\r\n   <p>It's important to pay attention to different coordinate system conventions that may be used in image processing. Often the\r\n      center of the upper-left pixel is considered to be the origin, (0,0). There is more variation in the assignment of \\( x \\) and \\( y \\) axes. The coordinate system in the diagram below, with the \\( x \\)-axis pointing down and the \\( y \\)-axis pointing to the right, is used in <i>Digital Image Processing Using MATLAB<\/i> in order to be consistent with the Gonzalez and Woods book, <i>Digital Image Processing<\/i>.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/dipum_fig_2_1_a.png\"> <\/p>\r\n   <p><i>From Figure 2.1, Digital Image Processing Using MATLAB, 2nd ed. Used with permission.<\/i><\/p>\r\n   <p>When displaying images in MATLAB, the usual convention is for the center of the upper-left pixel to be at (1,1), the \\( x \\)-axis to point to the right, and the \\( y \\)-axis to point down.\r\n   <\/p>\r\n   <h3>Images as matrices and arrays<a name=\"3\"><\/a><\/h3>\r\n   <p>Digital images are very conveniently represented as matrices, which happens to be great for working with in MATLAB. A monochrome\r\n      image matrix looks like this:\r\n   <\/p><pre>   f(1,1)  f(1,2)  ...  f(1,N)\r\n   f(2,1)  f(2,2)  ...  f(2,N)\r\n     .       .            .\r\n     .       .            .\r\n     .       .            .\r\n   f(M,1)  f(M,2)  ...  f(M,N)<\/pre><p>(This happy marriage of a convenient digital image representation and the MATLAB strength at working with matrices is, more\r\n      or less, the reason I ended up working at MathWorks.)\r\n   <\/p>\r\n   <p>We represent color images in MATLAB as multidimensional arrays. For example, an RGB image (with three color components) is\r\n      represented as an M-by-N-by-3 array. A CMYK image (with four color components) would use an M-by-N-by-4 array.\r\n   <\/p>\r\n   <p>Multidimensional images are also represented in MATLAB as multidimensional arrays. Therefore we rely on context to distinguish\r\n      between an RGB image (M-by-N-by-3) and a three-dimensional image with three z-plane slices (also M-b-N-by-3). For example,\r\n      if you pass an M-by-N-by-3 array to <tt>rgb2gray<\/tt>, it is clear from the context that the input should be interpreted as an RGB color image and not as a three-dimensional image.\r\n   <\/p>\r\n   <h3>For more information<a name=\"4\"><\/a><\/h3>\r\n   <p>For more information, see Section 2.1 of <a href=\"http:\/\/imageprocessingplace.com\/DIPUM-2E\/dipum2e_main_page.htm\"> <i>Digital Image Processing Using MATLAB<\/i><\/a>. See also the section <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/images\/brcu_al-1.html\">Image Coordinate Systems<\/a> in the Image Processing Toolbox User's Guide.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/dipum-cover.png\"> <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_627752da25444349b0ef733c4708482b() {\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='627752da25444349b0ef733c4708482b ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 627752da25444349b0ef733c4708482b';\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 2011 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-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_627752da25444349b0ef733c4708482b()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.12<br><\/p>\r\n<\/div>\r\n<!--\r\n627752da25444349b0ef733c4708482b ##### SOURCE BEGIN #####\r\n%%\r\n% Today I'm starting an regular, occasional series with tutorial material\r\n% on digital image processing using MATLAB. I'm going to look at topics in\r\n% roughly the order used in the book\r\n% <http:\/\/imageprocessingplace.com\/DIPUM-2E\/dipum2e_main_page.htm _Digital\r\n% Image Processing Using MATLAB_>, Gatesmark Publishing, 2009, by Gonzalez,\r\n% Woods, and Eddins. (Yes, that's me. It was a lot of nights and weekends.)\r\n%\r\n%% Digital image representation\r\n% Let's start with digital image representation. (I do not plan to cover\r\n% image formation. For that topic, see Chapter 2 of _Digital Image\r\n% Processing_, Prentice Hall, 2008, by Gonzalez and Woods.) The common\r\n% mathematical representation of an image is a function of two continuous\r\n% spatial coordinates: $f(x,y)$. The value $f(x_0,y_0)$ is often called the\r\n% image _intensity_ at $(x_0,y_0)$, although that term is used loosely\r\n% because it often does not represent actual light intensity. The term\r\n% _gray level_ is also commonly used.\r\n%\r\n% You can represent a color image mathematically in a couple of different\r\n% ways. One way is to use a collection of image functions, one per color\r\n% component, such as $r(x,y)$, $g(x,y)$, and $b(x,y)$. Another way is to\r\n% use a vector-valued function, ${\\mathbf f}(x,y)$.\r\n%\r\n% Many functions in the Image Processing Toolbox also support\r\n% higher-dimensional images. For example, _f_ might be a function of three\r\n% spatial variable, as in $f(x,y,z)$. Image Processing Toolbox\r\n% documentation calls this a _multidimensional image_.\r\n%\r\n% Converting the amplitude values of _f_ to a set of discrete values is\r\n% called _quantization_. Capturing those values at discrete spatial\r\n% coordinates is called _sampling_. When _x_, _y_, and the values of _f_\r\n% are all finite, discrete quantities, we call _f_ a _digital image_.\r\n\r\n%% Coordinate conventions\r\n%\r\n% It's important to pay attention to different coordinate system\r\n% conventions that may be used in image processing. Often the center of the\r\n% upper-left pixel is considered to be the origin, (0,0). There is more\r\n% variation in the assignment of _x_ and _y_ axes. The coordinate system in\r\n% the diagram below, with the _x_-axis pointing down and the _y_-axis\r\n% pointing to the right, is used in _Digital Image Processing Using MATLAB_\r\n% in order to be consistent with the Gonzalez and Woods book, _Digital\r\n% Image Processing_.\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2011\/dipum_fig_2_1_a.png>>\r\n%\r\n% _From Figure 2.1, Digital Image Processing Using MATLAB, 2nd ed. Used\r\n% with permission._\r\n%\r\n% When displaying images in MATLAB, the usual convention is for the center\r\n% of the upper-left pixel to be at (1,1), the _x_-axis to point to the\r\n% right, and the _y_-axis to point down.\r\n\r\n%% Images as matrices and arrays\r\n% Digital images are very conveniently represented as matrices, which\r\n% happens to be great for working with in MATLAB. A monochrome image matrix\r\n% looks like this:\r\n%\r\n%     f(1,1)  f(1,2)  ...  f(1,N)\r\n%     f(2,1)  f(2,2)  ...  f(2,N)\r\n%       .       .            .\r\n%       .       .            .\r\n%       .       .            .\r\n%     f(M,1)  f(M,2)  ...  f(M,N)\r\n%\r\n% (This happy marriage of a convenient digital image representation and the\r\n% MATLAB strength at working with matrices is, more or less,\r\n% the reason I ended up working at MathWorks.)\r\n%\r\n% We represent color images in MATLAB as multidimensional arrays. For\r\n% example, an RGB image (with three color components) is represented as an\r\n% M-by-N-by-3 array. A CMYK image (with four color components) would use an\r\n% M-by-N-by-4 array.\r\n%\r\n% Multidimensional images are also represented in MATLAB as\r\n% multidimensional arrays. Therefore we rely on context to distinguish\r\n% between an RGB image (M-by-N-by-3) and a three-dimensional image with\r\n% three z-plane slices (also M-b-N-by-3). For example, if you pass an\r\n% M-by-N-by-3 array to |rgb2gray|, it is clear from the context that the\r\n% input should be interpreted as an RGB color image and not as a\r\n% three-dimensional image.\r\n%\r\n%% For more information\r\n% For more information, see Section 2.1 of\r\n% <http:\/\/imageprocessingplace.com\/DIPUM-2E\/dipum2e_main_page.htm\r\n%  _Digital Image Processing Using MATLAB_>. See also the\r\n% section <https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/images\/brcu_al-1.html\r\n% Image Coordinate Systems> in the Image Processing Toolbox User's Guide.\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/images\/steve\/2011\/dipum-cover.png>>\r\n##### SOURCE END ##### 627752da25444349b0ef733c4708482b\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Today I'm starting an regular, occasional series with tutorial material on digital image processing using MATLAB. I'm going\r\n         to look at topics in roughly the order used in the... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2011\/08\/26\/digital-image-processing-using-matlab-digital-image-representation\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/387"}],"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=387"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/387\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}