{"id":477,"date":"2010-01-04T11:51:40","date_gmt":"2010-01-04T18:51:40","guid":{"rendered":"http:\/\/www.giassa.net\/?page_id=477"},"modified":"2025-08-24T08:03:52","modified_gmt":"2025-08-24T15:03:52","slug":"iv-logarithmic-transformation","status":"publish","type":"page","link":"https:\/\/www.giassa.net\/?page_id=477","title":{"rendered":"IV &#8211; Logarithmic Transformation"},"content":{"rendered":"<p>A logarithmic transformation of an image is actually a simple one. We simply take the logarithm of each pixel value, and we&#8217;re done. Well, if that were the only interesting piece of information with respect to this topic, we&#8217;d be done now. There is an interesting operation we can carry out using some simple mathematics and a logarithmic transform: segmentation. This basically allows you to take an input image, with, for example, <img src='https:\/\/s0.wp.com\/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' \/> different possible pixel values, and produce an output image with <img src='https:\/\/s0.wp.com\/latex.php?latex=y&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y' title='y' class='latex' \/> possible pixel values. Although segmentation is a topic all on its own, this special case deserves a section for itself, if for no other reason than its simplicity.<\/p>\n<p>In the case of the following images, I simply take an input image, calculate the base-2 logarithm of each pixel value, round it to the nearest integer (note the addition of a scalar <img src='https:\/\/s0.wp.com\/latex.php?latex=1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='1' title='1' class='latex' \/> to prevent a <img src='https:\/\/s0.wp.com\/latex.php?latex=log%280%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='log(0)' title='log(0)' class='latex' \/> calculation, which is NaN so far as MATLAB is concerned), and then normalize the image. While you don&#8217;t need to normalize the image (after all, the MATLAB <img src='https:\/\/s0.wp.com\/latex.php?latex=imagesc&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='imagesc' title='imagesc' class='latex' \/> command does this for you easily enough), I figured it would be a good idea anyways.<\/p>\n<p>The end result is shown below, along with the (simple) code used to generate it.<\/p>\n<div id=\"attachment_575\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.giassa.net\/wp-content\/uploads\/2010\/01\/hiddensmile-original.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-575\" class=\"size-medium wp-image-575\" title=\"hiddensmile-original\" src=\"https:\/\/www.giassa.net\/wp-content\/uploads\/2010\/01\/hiddensmile-original-300x264.png\" alt=\"\" width=\"300\" height=\"264\" srcset=\"https:\/\/www.giassa.net\/wp-content\/uploads\/2010\/01\/hiddensmile-original-300x264.png 300w, https:\/\/www.giassa.net\/wp-content\/uploads\/2010\/01\/hiddensmile-original.png 576w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-575\" class=\"wp-caption-text\">Original Grayscale Image<\/p><\/div>\n<div id=\"attachment_574\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.giassa.net\/wp-content\/uploads\/2010\/01\/hiddensmile-log-level.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-574\" class=\"size-medium wp-image-574\" title=\"hiddensmile-log-level\" src=\"https:\/\/www.giassa.net\/wp-content\/uploads\/2010\/01\/hiddensmile-log-level-300x264.png\" alt=\"\" width=\"300\" height=\"264\" srcset=\"https:\/\/www.giassa.net\/wp-content\/uploads\/2010\/01\/hiddensmile-log-level-300x264.png 300w, https:\/\/www.giassa.net\/wp-content\/uploads\/2010\/01\/hiddensmile-log-level.png 576w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-574\" class=\"wp-caption-text\">Segmented Image<\/p><\/div>\n<pre class=\"lang:matlab decode:true \">%==========================================================================\r\nfunction output_image = loglevel( input_image )\r\n%   IMNORM  -   Logarithmic normalization of input image over [0,255]\r\n%   output_image    -   The normalized image\r\n%   input_image     -   The source image data\r\n% (C) 2010 Matthew Giassa, &lt;teo@giassa.net&gt; www.giassa.net\r\n%==========================================================================\r\n%Make a grayscale copy of our input image\r\nI = double(rgb2gray(input_image));\r\n%Determine input image dimensions\r\n[j k] = size(I);\r\n%Calculate the base-2 logarithm of each input pixel value, and round to the\r\n%nearest whole integer\r\nI=round(log2(double(I+1)));\r\n%Determine the extreme intensity values for our input image\r\nin_min = double(min(min(I)));\r\nin_max = double(max(max(I)));\r\n%Determine the extreme intensity values for the output image\r\nout_min = double(intmin('uint8'));\r\nout_max = double(intmax('uint8'));\r\n%Determine the amount to \"shift\/move\" pixel intensity values by\r\nshift_val = in_min - out_min;\r\n%Determine the value to \"scale\" pixel intensity values by\r\nscale_val = (out_max)\/(in_max-in_min);\r\n%Perform the shift and scale (in that order)\r\nfor counter1 = 1:j\r\n for counter2 = 1:k\r\n I(counter1,counter2)=(I(counter1,counter2)-double(shift_val))*double(scale_val);\r\n end\r\nend\r\n%Done\r\noutput_image = I;\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A logarithmic transformation of an image is actually a simple one. We simply take the logarithm of each pixel value, and we&#8217;re done. Well, if that were the only interesting piece of information with respect to this topic, we&#8217;d be &hellip; <a href=\"https:\/\/www.giassa.net\/?page_id=477\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":411,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-477","page","type-page","status-publish","hentry"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.5 - aioseo.com -->\n\t<meta name=\"description\" content=\"A tutorial on logarithmic transformations.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.giassa.net\/?page_id=477\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.5\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"GIASSA.NET | Engineering, DIY, and Everything Else\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Image Processing - Logarithmic Transformation | GIASSA.NET\" \/>\n\t\t<meta property=\"og:description\" content=\"A tutorial on logarithmic transformations.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.giassa.net\/?page_id=477\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2010-01-04T18:51:40+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2025-08-24T15:03:52+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Image Processing - Logarithmic Transformation | GIASSA.NET\" \/>\n\t\t<meta name=\"twitter:description\" content=\"A tutorial on logarithmic transformations.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=477#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.giassa.net\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=865#listItem\",\"name\":\"Projects\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=865#listItem\",\"position\":2,\"name\":\"Projects\",\"item\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=865\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=118#listItem\",\"name\":\"Image Processing Tutorials\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=118#listItem\",\"position\":3,\"name\":\"Image Processing Tutorials\",\"item\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=118\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=411#listItem\",\"name\":\"3 \\u2013 Histograms, Statistics, &#038; Single Pixel Operations\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=865#listItem\",\"name\":\"Projects\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=411#listItem\",\"position\":4,\"name\":\"3 \\u2013 Histograms, Statistics, &#038; Single Pixel Operations\",\"item\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=411\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=477#listItem\",\"name\":\"IV &#8211; Logarithmic Transformation\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=118#listItem\",\"name\":\"Image Processing Tutorials\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=477#listItem\",\"position\":5,\"name\":\"IV &#8211; Logarithmic Transformation\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=411#listItem\",\"name\":\"3 \\u2013 Histograms, Statistics, &#038; Single Pixel Operations\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/#organization\",\"name\":\"GIASSA.NET\",\"description\":\"Engineering, DIY, and Everything Else\",\"url\":\"https:\\\/\\\/www.giassa.net\\\/\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=477#webpage\",\"url\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=477\",\"name\":\"Image Processing - Logarithmic Transformation | GIASSA.NET\",\"description\":\"A tutorial on logarithmic transformations.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.giassa.net\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.giassa.net\\\/?page_id=477#breadcrumblist\"},\"datePublished\":\"2010-01-04T11:51:40-07:00\",\"dateModified\":\"2025-08-24T08:03:52-07:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.giassa.net\\\/#website\",\"url\":\"https:\\\/\\\/www.giassa.net\\\/\",\"name\":\"GIASSA.NET\",\"description\":\"Engineering, DIY, and Everything Else\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.giassa.net\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Image Processing - Logarithmic Transformation | GIASSA.NET","description":"A tutorial on logarithmic transformations.","canonical_url":"https:\/\/www.giassa.net\/?page_id=477","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BreadcrumbList","@id":"https:\/\/www.giassa.net\/?page_id=477#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/#listItem","position":1,"name":"Home","item":"https:\/\/www.giassa.net\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=865#listItem","name":"Projects"}},{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=865#listItem","position":2,"name":"Projects","item":"https:\/\/www.giassa.net\/?page_id=865","nextItem":{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=118#listItem","name":"Image Processing Tutorials"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=118#listItem","position":3,"name":"Image Processing Tutorials","item":"https:\/\/www.giassa.net\/?page_id=118","nextItem":{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=411#listItem","name":"3 \u2013 Histograms, Statistics, &#038; Single Pixel Operations"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=865#listItem","name":"Projects"}},{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=411#listItem","position":4,"name":"3 \u2013 Histograms, Statistics, &#038; Single Pixel Operations","item":"https:\/\/www.giassa.net\/?page_id=411","nextItem":{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=477#listItem","name":"IV &#8211; Logarithmic Transformation"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=118#listItem","name":"Image Processing Tutorials"}},{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=477#listItem","position":5,"name":"IV &#8211; Logarithmic Transformation","previousItem":{"@type":"ListItem","@id":"https:\/\/www.giassa.net\/?page_id=411#listItem","name":"3 \u2013 Histograms, Statistics, &#038; Single Pixel Operations"}}]},{"@type":"Organization","@id":"https:\/\/www.giassa.net\/#organization","name":"GIASSA.NET","description":"Engineering, DIY, and Everything Else","url":"https:\/\/www.giassa.net\/"},{"@type":"WebPage","@id":"https:\/\/www.giassa.net\/?page_id=477#webpage","url":"https:\/\/www.giassa.net\/?page_id=477","name":"Image Processing - Logarithmic Transformation | GIASSA.NET","description":"A tutorial on logarithmic transformations.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.giassa.net\/#website"},"breadcrumb":{"@id":"https:\/\/www.giassa.net\/?page_id=477#breadcrumblist"},"datePublished":"2010-01-04T11:51:40-07:00","dateModified":"2025-08-24T08:03:52-07:00"},{"@type":"WebSite","@id":"https:\/\/www.giassa.net\/#website","url":"https:\/\/www.giassa.net\/","name":"GIASSA.NET","description":"Engineering, DIY, and Everything Else","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.giassa.net\/#organization"}}]},"og:locale":"en_US","og:site_name":"GIASSA.NET | Engineering, DIY, and Everything Else","og:type":"article","og:title":"Image Processing - Logarithmic Transformation | GIASSA.NET","og:description":"A tutorial on logarithmic transformations.","og:url":"https:\/\/www.giassa.net\/?page_id=477","article:published_time":"2010-01-04T18:51:40+00:00","article:modified_time":"2025-08-24T15:03:52+00:00","twitter:card":"summary","twitter:title":"Image Processing - Logarithmic Transformation | GIASSA.NET","twitter:description":"A tutorial on logarithmic transformations."},"aioseo_meta_data":{"post_id":"477","title":"Image Processing - Logarithmic Transformation | #site_title","description":"A tutorial on logarithmic transformations.","keywords":[{"label":"image processing","value":"image processing"},{"label":"histograms","value":"histograms"},{"label":"statistics","value":"statistics"},{"label":"giassa","value":"giassa"},{"label":"matthew","value":"matthew"},{"label":"sfu","value":"sfu"},{"label":"engineering","value":"engineering"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"WebPage","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-04-22 01:27:51","updated":"2025-08-24 15:30:04","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.giassa.net\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.giassa.net\/?page_id=865\" title=\"Projects\">Projects<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.giassa.net\/?page_id=118\" title=\"Image Processing Tutorials\">Image Processing Tutorials<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.giassa.net\/?page_id=411\" title=\"3 \u2013 Histograms, Statistics, &amp; Single Pixel Operations\">3 \u2013 Histograms, Statistics, &amp; Single Pixel Operations<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tIV \u2013 Logarithmic Transformation\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.giassa.net\/"},{"label":"Projects","link":"https:\/\/www.giassa.net\/?page_id=865"},{"label":"Image Processing Tutorials","link":"https:\/\/www.giassa.net\/?page_id=118"},{"label":"3 \u2013 Histograms, Statistics, &#038; Single Pixel Operations","link":"https:\/\/www.giassa.net\/?page_id=411"},{"label":"IV &#8211; Logarithmic Transformation","link":"https:\/\/www.giassa.net\/?page_id=477"}],"_links":{"self":[{"href":"https:\/\/www.giassa.net\/index.php?rest_route=\/wp\/v2\/pages\/477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.giassa.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.giassa.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.giassa.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.giassa.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=477"}],"version-history":[{"count":7,"href":"https:\/\/www.giassa.net\/index.php?rest_route=\/wp\/v2\/pages\/477\/revisions"}],"predecessor-version":[{"id":1106,"href":"https:\/\/www.giassa.net\/index.php?rest_route=\/wp\/v2\/pages\/477\/revisions\/1106"}],"up":[{"embeddable":true,"href":"https:\/\/www.giassa.net\/index.php?rest_route=\/wp\/v2\/pages\/411"}],"wp:attachment":[{"href":"https:\/\/www.giassa.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}