{"id":4854,"date":"2013-10-04T09:00:22","date_gmt":"2013-10-04T13:00:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4854"},"modified":"2013-10-03T23:00:50","modified_gmt":"2013-10-04T03:00:50","slug":"easy-visualization-of-volumetric-data","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/10\/04\/easy-visualization-of-volumetric-data\/","title":{"rendered":"Easy visualization of volumetric data"},"content":{"rendered":"\r\n<div class=\"content\"><!--introduction--><!--\/introduction--><p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a>'s Pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/22940-vol3d-v2\">\"vol3d v2\"<\/a>, by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29192\">Oliver Woodford<\/a>.<\/p><p>Today's Pick is brought to you by Oliver Woodford, one of the most popular contributors to the File Exchange, and author of <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/23629-export-fig\">export_fig<\/a>, <i>the<\/i> long-time \"most-downloaded-file\" award winner--itself the recipient of a coveted :) <a href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/05\/28\/creating-and-exporting-publication-quality-graphics\/\">Pick of the Week<\/a> banner.<\/p><p>When I'm demonstrating the use of MATLAB for image processing, I often show how one can use the output of the <tt>isosurface<\/tt> command as an <i>input<\/i> to the <tt>patch<\/tt> command to create easily a rotatable model of a 3D image stack.<\/p><pre class=\"language-matlab\">&gt;&gt; whos data\r\n<\/pre><pre class=\"language-matlab\">Name       <span class=\"string\">Size<\/span>                   <span class=\"string\">Bytes<\/span>    <span class=\"string\">Class<\/span>    <span class=\"string\">Attributes<\/span>\r\ndata       <span class=\"string\">60x256x256<\/span>             <span class=\"string\">3932160<\/span>  <span class=\"string\">uint8<\/span>\r\n<\/pre><pre class=\"language-matlab\">white_vol = isosurface(data,2.5);\r\ngray_vol  = isosurface(data,1.5);\r\nfigure(<span class=\"string\">'renderer'<\/span>,<span class=\"string\">'openGL'<\/span>,<span class=\"string\">'windowstyle'<\/span>,<span class=\"string\">'normal'<\/span>,<span class=\"string\">'color'<\/span>,<span class=\"string\">'w'<\/span>);\r\npatch(white_vol,<span class=\"string\">'FaceColor'<\/span>,<span class=\"string\">'b'<\/span>,<span class=\"string\">'EdgeColor'<\/span>,<span class=\"string\">'none'<\/span>);\r\npatch(gray_vol,<span class=\"string\">'FaceColor'<\/span>,<span class=\"string\">'y'<\/span> ,<span class=\"string\">'EdgeColor'<\/span>,<span class=\"string\">'none'<\/span>, <span class=\"string\">'FaceAlpha'<\/span>,0.3);\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/rotatingBrain.gif\" alt=\"\"> <\/p><p>I recognize that that visualization could be improved--there are all kinds of options for controlling the rendering, the lighting, the smoothing, the coloration, etc. But the ease with which MATLAB can create such visualizations impresses me.<\/p><p>Oliver's \"vol_3d v2\" provides yet another approach to visualization that I will likely be incorporating into my \"3D visualization story.\" With a simple interface modified from the (quite old!) code of fellow MathWorker Joe Conti, Oliver allows us to visualize data, and manipulate its display quite easily:<\/p><pre class=\"language-matlab\">vol3d(<span class=\"string\">'cdata'<\/span>,data,<span class=\"string\">'texture'<\/span>,<span class=\"string\">'3D'<\/span>);\r\nview(45,15); daspect(1.\/voxel_size2); axis <span class=\"string\">tight<\/span>;axis <span class=\"string\">off<\/span>;\r\ncamlight; camlight(-90,-10); camlight(180,-10);lighting <span class=\"string\">phong<\/span>;\r\nalphamap(<span class=\"string\">'rampup'<\/span>);\r\nalphamap(0.05 .* alphamap);\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/rotatingBrain2.gif\" alt=\"\"> <\/p><p>Oliver writes really nice code, and has the downloads and reviews to prove it. Thanks, Oliver, for this cool submission! (And thank you, Joe, for being amenable to having your code modified and improved by others in the user community. I love to see the File Exchange utilized in this manner!)<\/p><p>As always, I welcome your <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4854#respond\">thoughts and comments<\/a>. Or leave feedback for Oliver <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/22940-vol3d-v2#comments\">here<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_9262bd406ec94b0a8ed7e12a6892bd92() {\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='9262bd406ec94b0a8ed7e12a6892bd92 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 9262bd406ec94b0a8ed7e12a6892bd92';\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        copyright = 'Copyright 2013 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 copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\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     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_9262bd406ec94b0a8ed7e12a6892bd92()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><\/div><!--\r\n9262bd406ec94b0a8ed7e12a6892bd92 ##### SOURCE BEGIN #####\r\n%% Easy visualization of volumetric data\r\n%% \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s Pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/22940-vol3d-v2 \"vol3d v2\">, by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29192 Oliver Woodford>.\r\n\r\n%%\r\n% Today's Pick is brought to you by Oliver Woodford, one of the most\r\n% popular contributors to the File Exchange, and author of \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/23629-export-fig export_fig>,\r\n% _the_ long-time \"most-downloaded-file\" award winnerREPLACE_WITH_DASH_DASHitself the recipient of a\r\n% coveted :)\r\n% <https:\/\/blogs.mathworks.com\/pick\/2010\/05\/28\/creating-and-exporting-publication-quality-graphics\/\r\n% Pick of the Week> banner.\r\n\r\n%% \r\n% When I'm demonstrating the use of MATLAB for image processing, I often\r\n% show how one can use the output of the |isosurface| command as an\r\n% _input_ to the |patch| command to create easily a rotatable model of\r\n% a 3D image stack.\r\n\r\n%%\r\n%   >> whos data\r\n%   \r\n%   Name       Size                   Bytes    Class    Attributes\r\n%   data       60x256x256             3932160  uint8    \r\n%\r\n%   white_vol = isosurface(data,2.5);\r\n%   gray_vol  = isosurface(data,1.5);\r\n%   figure('renderer','openGL','windowstyle','normal','color','w');\r\n%   patch(white_vol,'FaceColor','b','EdgeColor','none');\r\n%   patch(gray_vol,'FaceColor','y' ,'EdgeColor','none', 'FaceAlpha',0.3);\r\n\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/rotatingBrain.gif>>\r\n% \r\n% \r\n\r\n%%\r\n% I recognize that that visualization could be improvedREPLACE_WITH_DASH_DASHthere are all\r\n% kinds of options for controlling the rendering, the lighting, the\r\n% smoothing, the coloration, etc. But the ease with which MATLAB can create\r\n% such visualizations impresses me.\r\n\r\n%%\r\n% Oliver's \"vol_3d v2\" provides yet another approach to visualization that\r\n% I will likely be incorporating into my \"3D visualization story.\" With a\r\n% simple interface modified from the (quite old!) code of fellow MathWorker Joe Conti,\r\n% Oliver allows us to visualize data, and manipulate its display quite\r\n% easily:\r\n\r\n%%\r\n%   vol3d('cdata',data,'texture','3D');\r\n%   view(45,15); daspect(1.\/voxel_size2); axis tight;axis off;\r\n%   camlight; camlight(-90,-10); camlight(180,-10);lighting phong;\r\n%   alphamap('rampup');\r\n%   alphamap(0.05 .* alphamap);\r\n\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/rotatingBrain2.gif>>\r\n% \r\n\r\n%%\r\n% Oliver writes really nice code, and has the downloads and reviews to\r\n% prove it. Thanks, Oliver, for this cool submission! (And thank you, Joe,\r\n% for being amenable to having your code modified and improved by others in\r\n% the user community. I love to see the File Exchange utilized in this\r\n% manner!)\r\n\r\n%%\r\n% As always, I welcome your\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=4854#respond thoughts and comments>.\r\n% Or leave feedback for Oliver\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/22940-vol3d-v2#comments here>.\r\n##### SOURCE END ##### 9262bd406ec94b0a8ed7e12a6892bd92\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/rotatingBrain.gif\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\nBrett's Pick this week is \"vol3d v2\", by Oliver Woodford.Today's Pick is brought to you by Oliver Woodford, one of the most popular contributors to the File Exchange, and author of export_fig, the... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/10\/04\/easy-visualization-of-volumetric-data\/\">read more >><\/a><\/p>","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4854"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=4854"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4854\/revisions"}],"predecessor-version":[{"id":4860,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4854\/revisions\/4860"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}