{"id":191,"date":"2008-01-15T15:53:32","date_gmt":"2008-01-15T20:53:32","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2008\/01\/15\/linkaxes\/"},"modified":"2019-10-24T13:52:27","modified_gmt":"2019-10-24T17:52:27","slug":"linkaxes","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2008\/01\/15\/linkaxes\/","title":{"rendered":"linkaxes"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>Toward the end of last year, it occurred to me that I had accumulated enough material on this blog to construct a \"master\r\n      class\" on image processing in MATLAB.  The response to my suggestion was \"Sounds good - here's a list of places we want you\r\n      to go!\"\r\n   <\/p>\r\n   <p>So in a perverse way, it's the blog's fault that I've been slow posting recently.  I've been frantically preparing a new image\r\n      processing seminar, which I'll be presenting at the University of Illinois at Urbana-Champaign and at MIT later this week.\r\n       (Please, no more snow storms for a few days!)\r\n   <\/p>\r\n   <p>Have you ever heard of the <tt>linkaxes<\/tt> function?  We introduced it to MATLAB several releases ago, sometime around version 7.0. It lets you plot into two different\r\n      axes objects and then keep those axes automatically synchronized with each other.  For example, as you zoom and pan in one\r\n      axes, the other axes zooms and pans the same way.  This is really useful for comparing input and output images.\r\n   <\/p>\r\n   <p>Here's an example using linkaxes to examine closely the output of the <tt>edge<\/tt> function.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">I = imread(<span style=\"color: #A020F0\">'rice.png'<\/span>);\r\nimshow(I)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/191\/linkaxes_example_01.png\"> <pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">bw = edge(I, <span style=\"color: #A020F0\">'canny'<\/span>);\r\nimshow(bw)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/191\/linkaxes_example_02.png\"> <p>Let's use <tt>subplot<\/tt> to create two axes in the same figure, and then we'll link them together.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">% Call subplot with an output argument to capture the axes<\/span>\r\n<span style=\"color: #228B22\">% handles, because we'll need the handles in the call to<\/span>\r\n<span style=\"color: #228B22\">% linkaxes.<\/span>\r\nax1 = subplot(1, 2, 1);\r\nimshow(I)\r\n\r\nax2 = subplot(1, 2, 2);\r\nimshow(bw)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/191\/linkaxes_example_03.png\"> <p>Now pass <tt>linkaxes<\/tt> a vector containing both axes handles.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">linkaxes([ax1 ax2]);<\/pre><p>If you then pan and zoom using the mouse in one image, the other image follows along.  The linking also works if you change\r\n      the axes limits from the command line, like this:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">axis([50 90 200 240])<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/191\/linkaxes_example_04.png\"> <p>There's your quick tip for the week.  I hope to pick up the blogging pace again starting next week.<\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_3a966a9694754bbea7f1261abe808da9() {\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='3a966a9694754bbea7f1261abe808da9 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 3a966a9694754bbea7f1261abe808da9';\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 2008 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_3a966a9694754bbea7f1261abe808da9()\"><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.5<br><\/p>\r\n<\/div>\r\n<!--\r\n3a966a9694754bbea7f1261abe808da9 ##### SOURCE BEGIN #####\r\n%%\r\n% Toward the end of last year, it occurred to me that I had\r\n% accumulated enough material on this blog to construct a \"master\r\n% class\" on image processing in MATLAB.  The response to my\r\n% suggestion was \"Sounds good - here's a list of places we want\r\n% you to go!\"\r\n%\r\n% So in a perverse way, it's the blog's fault that I've been slow\r\n% posting recently.  I've been frantically preparing a new\r\n% image processing seminar, which I'll be presenting it at the\r\n% University of Illinois at Urbana-Champaign and at MIT later\r\n% this week.  (Please, no more snow storms for a few days!)\r\n%\r\n% Have you ever heard of the |linkaxes| function?  We introduced\r\n% it to MATLAB several releases ago, sometime around version 7.0.\r\n% It lets you plot into two different axes objects and then keep\r\n% those axes automatically synchronized with each other.  For\r\n% example, as you zoom and pan in one axes, the other axes zooms\r\n% and pans the same way.  This is really useful for comparing\r\n% input and output images.\r\n%\r\n% Here's an example using linkaxes to examine closely the output\r\n% of the |edge| function.\r\n\r\nI = imread('rice.png');\r\nimshow(I)\r\n\r\n%%\r\n\r\nbw = edge(I, 'canny');\r\nimshow(bw)\r\n\r\n%%\r\n% Let's use |subplot| to create two axes in the same figure, and\r\n% then we'll link them together.\r\n\r\n% Call subplot with an output argument to capture the axes\r\n% handles, because we'll need the handles in the call to\r\n% linkaxes.\r\nax1 = subplot(1, 2, 1);\r\nimshow(I)\r\n\r\nax2 = subplot(1, 2, 2);\r\nimshow(bw)\r\n\r\n%%\r\n% Now pass |linkaxes| a vector containing both axes handles.\r\n\r\nlinkaxes([ax1 ax2]);\r\n\r\n%%\r\n% If you then pan and zoom using the mouse in one image, the\r\n% other image follows along.  The linking also works if you\r\n% change the axes limits from the command line, like this:\r\n\r\naxis([50 90 200 240])\r\n\r\n%%\r\n% There's your quick tip for the week.  I hope to pick up the\r\n% blogging pace again starting next week.\r\n##### SOURCE END ##### 3a966a9694754bbea7f1261abe808da9\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Toward the end of last year, it occurred to me that I had accumulated enough material on this blog to construct a \"master\r\n      class\" on image processing in MATLAB.  The response to my... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2008\/01\/15\/linkaxes\/\">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":[50,228,76,36,458,72],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/191"}],"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=191"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":3584,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/191\/revisions\/3584"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}