{"id":50,"date":"2006-04-01T07:00:03","date_gmt":"2006-04-01T12:00:03","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=50"},"modified":"2019-10-22T09:12:31","modified_gmt":"2019-10-22T13:12:31","slug":"upcoming-optimizations-in-the-image-processing-toolbox","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2006\/04\/01\/upcoming-optimizations-in-the-image-processing-toolbox\/","title":{"rendered":"Upcoming optimizations in the Image Processing Toolbox"},"content":{"rendered":"<p>The MathWorks does not normally preview unreleased features, but I thought this might be a good time to make an exception. We are very excited about a set of new performance optimizations we are planning for the next release of the Image Processing Toolbox.<\/p>\n<h3>Key idea: Precomputed results<\/h3>\n<p>The key technology involves precomputed algorithmic results for a single, general-purpose image. For both practical and historical reasons, we chose to use the \"trees\" image that already ships with the toolbox:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/50\/trees.jpg\" \/><br \/>\n<small><small><small>Image courtesy of Susan Cohen<\/small><\/small><\/small><\/p>\n<p>We are computing the output of almost every toolbox function on this image. For example, consider the following procedure:<\/p>\n<ol>\n<li>Convert the image to grayscale using <tt>rgb2gray<\/tt>.<\/li>\n<li>Threshold the image automatically using <tt>graythresh<\/tt> and <tt>im2bw<\/tt>.<\/li>\n<li>Apply a morphological opening using a diamond-shaped structuring element of width 5 (<tt>strel<\/tt>, <tt>imopen<\/tt>).<\/li>\n<li>Compute the Euclidean distance transform (<tt>bwdist<\/tt>).<\/li>\n<\/ol>\n<p>The result is shown below. You'll get the answer virtually instantaneously using the new release, since everything is precomputed.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/50\/trees_dist.jpg\" \/><\/p>\n<h3>Using your own images<\/h3>\n<p>None of this helps you, of course, unless you can use your own images. Here's how. Basically, you use a combination of spatial and color transformations to modify your image to look just like the trees image. For example, suppose you were starting with this image:<\/p>\n<p><a href=\"https:\/\/blogs.mathworks.com\/loren\"><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/50\/pout.jpg\" \/><\/a><\/p>\n<p>I'd probably start with a conformal mapping. Then it's a simple matter of using control points, <tt>cp2tform<\/tt> (with the 'LWM' option, of course), and <tt>tformarray<\/tt> to complete the spatial part. You may find the dimensional remapping syntaxes of <tt>tformarray<\/tt> to be particularly helpful.<\/p>\n<p>Now you still have to make your image colors match the trees image. Use toolbox functions <tt>makecform<\/tt> and <tt>applycform<\/tt> to do this. These functions give you access to color capabilities standardized by the International Color Consortium (ICC). See the <a href=\"http:\/\/www.color.org\">ICC web site<\/a> for lots more information about color, as well as some information about colour.<\/p>\n<p>Here's the result, which you can clearly see is identical (except for a little floating-point round-off error) to the trees image.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/50\/trees.jpg\" \/><\/p>\n<p>Finally, just call the desired toolbox functions, invert your spatial and color transformations, and you're done!<\/p>\n<h3>Issues<\/h3>\n<p>There are a few issues you should be aware of:<\/p>\n<ul>\n<li>We can't distribute alpha or beta versions of the new toolbox release, because it depends on MATLAB language features that haven't shipped yet. See Loren's <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=29\">Art of MATLAB blog posting<\/a> for more information.<\/li>\n<li>The next toolbox release will ship on 17 DVDs. The increased media space is required to store all the precomputed images.<\/li>\n<li>Despite our best efforts, a few toolbox functions aren't yet supported. We promise to add precomputed support for these functions just as soon as we can. The affected functions include <tt>imarock<\/tt>, <tt>imanisland<\/tt>, and <a href=\"http:\/\/en.wikipedia.org\/wiki\/April_fools\"><tt>imajoke<\/tt><\/a>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The MathWorks does not normally preview unreleased features, but I thought this might be a good time to make an exception. We are very excited about a set of new performance optimizations we are... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2006\/04\/01\/upcoming-optimizations-in-the-image-processing-toolbox\/\">read more >><\/a><\/p>\n","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[114,98,82,84,108,112,104,106,110],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/50"}],"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=50"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":2390,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/50\/revisions\/2390"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}