{"id":10476,"date":"2019-02-01T09:00:17","date_gmt":"2019-02-01T14:00:17","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=10476"},"modified":"2019-02-01T10:05:27","modified_gmt":"2019-02-01T15:05:27","slug":"comprehensive-easy-to-use-particle-image-velocimetry-tool","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2019\/02\/01\/comprehensive-easy-to-use-particle-image-velocimetry-tool\/","title":{"rendered":"Comprehensive, easy-to-use particle image velocimetry tool"},"content":{"rendered":"<div class=\"content\"><!--introduction--><\/p>\n<p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a>&#8216;s Pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27659\"><tt>PIVLab<\/tt><\/a>, by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/1377529\">William Thielicke<\/a>.<\/p>\n<p><!--\/introduction--><\/p>\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#bbcb5e72-b322-4b6e-bf6d-a7b3a4f11068\">A Particle Velocimetry Suite of Tools!<\/a><\/li>\n<li><a href=\"#edf42bb1-d018-4627-bd56-223ce9b0609f\">A video tutorial!<\/a><\/li>\n<li><a href=\"#51e884f7-db3d-41db-bd8f-5afc92fad19b\">One suggestion<\/a><\/li>\n<\/ul>\n<\/div>\n<h4>A Particle Velocimetry Suite of Tools!<a name=\"bbcb5e72-b322-4b6e-bf6d-a7b3a4f11068\"><\/a><\/h4>\n<p>Many years ago, as a postdoc at the National Institutes of Health, I was working on a problem with a colleague characterizing the (spiral) shape of the cochlea. Armed with my knowledge of the Image Processing Toolbox, I pretty quickly calculated <a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/edge.html\">edges<\/a> in an image of the structure, and then called <a href=\"https:\/\/www.mathworks.com\/help\/images\/ref\/bwtraceboundary.html\"><tt>bwtraceboundary<\/tt><\/a> to direct a path along the edge.<\/p>\n<p><i>My colleague&#8217;s eyes glazed over as she informed me that I had just recreated a significant part of her dissertation&#8211;one that took her a very long time to implement.<\/i><\/p>\n<p>For <i>my<\/i> dissertation, I implemented from scratch a particle image velocimetry (PIV)-based approach to measuring retinal blood flow by tracking fluorescent particles in the ocular circulation. Coming up with the PIV algorithm constituted a significant portion of my effort. Today, I feel a bit like my colleague did, looking at William&#8217;s PIVLab! With a very nicely implemented, MATLAB-built app, William facilitated nearly everything I needed to do to track those particles. But his code is light-years nicer and faster than mine was. (This goes back 25 years!)<\/p>\n<p>With PIVLab, I can simply load the images in my video sequence, set some parameters, and start tracking:<\/p>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/PIVLabScreenshotSmall.png\" alt=\"\"> <\/p>\n<p>In truth, I haven&#8217;t (yet!) been able to recreate with PIVLab the results from my dissertation. But one thing is sure&#8211;this would have been a very useful starting point, and it would have saved me countless weeks of effort! (The flexibility and customizability of MATLAB code&#8211;including that on the File Exchange&#8211;is truly what makes it so useful.)<\/p>\n<h4>A video tutorial!<a name=\"edf42bb1-d018-4627-bd56-223ce9b0609f\"><\/a><\/h4>\n<p>I love that William took the trouble of recording a twelve-minute video to get you started using his tool.<\/p>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/PIVLabTutorial.png\" alt=\"\"> <\/p>\n<p>The tool is richly featured, and includes many different visualizations and processing functions for looking at particle flows:<\/p>\n<p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/flowVisualization.png\" alt=\"\"> <\/p>\n<h4>One suggestion<a name=\"51e884f7-db3d-41db-bd8f-5afc92fad19b\"><\/a><\/h4>\n<p>I had to convert my video files to sequences of images to get them to work in PIVLab. It&#8217;s not very difficult to make your app support video files&#8211;using VideoReader, for instance! But creating an image sequence from a video is a minor task, too:<\/p>\n<pre>vid = VideoReader('C:\\Sample Data\\ONH_PIV_10.avi');\r\nframe = readFrame(vid);\r\nimgh = imshow(frame);\r\nindex = 1;\r\nwhile hasFrame(vid)\r\n   imwrite(frame,['C:\\Sample Data\\ONHFramewise\\','Frame_',sprintf('%03i',index),'.tif']);\r\n   index = index + 1;\r\n   set(imgh,'cdata',frame)\r\n   frame = readFrame(vid);\r\n   drawnow\r\nend<\/pre>\n<p>It&#8217;s worth noting that William is among the top 100 most-downloaded authors on the File Exchange&#8211;largely on the strength of PIVLab. It is current (the last update was January 2019); it has 80 user reviews hovering, on average, around 5\/5 stars; and has been downloaded thousands of times. This file is long overdue for Pick-of-the-Week recognition! William, I appreciate the effort it took to create this fine tool. And I greatly appreciate your sharing it with the MATLAB community!<\/p>\n<p>As always, I welcome your <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=10476#respond\">thoughts and comments<\/a>.<\/p>\n<p><script language=\"JavaScript\"> <!-- \n    function grabCode_267de97c52984015849979ba1601c411() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='267de97c52984015849979ba1601c411 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 267de97c52984015849979ba1601c411';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        copyright = 'Copyright 2019 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n<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\n\\n');\n\n        d.title = title + ' (MATLAB code)';\n        d.close();\n    }   \n     --> <\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><a href=\"javascript:grabCode_267de97c52984015849979ba1601c411()\"><span style=\"font-size: x-small;        font-style: italic;\">Get<br \/>\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>      Published with MATLAB&reg; R2018b<\/p>\n<\/div>\n<p><!--\n267de97c52984015849979ba1601c411 ##### SOURCE BEGIN #####\n%% Comprehensive, easy-to-use particle image velocimetry tool\n%\n% <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s\n% Pick this week is\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27659 |PIVLab|>,\n% by <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/1377529 William Thielicke>.\n%\n\n%% A Particle Velocimetry Suite of Tools!\n% Many years ago, as a postdoc at the National Institutes of Health, I was\n% working on a problem with a colleague characterizing the (spiral) shape\n% of the cochlea. Armed with my knowledge of the Image Processing Toolbox,\n% I pretty quickly calculated <https:\/\/www.mathworks.com\/help\/images\/ref\/edge.html edges> in\n% an image of the structure, and then called\n% <https:\/\/www.mathworks.com\/help\/images\/ref\/bwtraceboundary.html\n% |bwtraceboundary|> to direct a path along the edge.\n\n%%\n% _My colleague's eyes glazed over as she informed me that I had just\n% recreated a significant part of her dissertationREPLACE_WITH_DASH_DASHone that took her a\n% very long time to implement._\n\n%% \n% For _my_ dissertation, I implemented from scratch a particle image\n% velocimetry (PIV)-based approach to measuring retinal blood flow by tracking\n% fluorescent particles in the ocular circulation. Coming up with the PIV\n% algorithm constituted a significant portion of my effort. Today, I feel a\n% bit like my colleague did, looking at William's PIVLab! With a very\n% nicely implemented, MATLAB-built app, William facilitated nearly\n% everything I needed to do to track those particles. But his code is\n% light-years nicer and faster than mine was. (This goes back 25 years!)\n\n%%\n% With PIVLab, I can simply load the images in my video sequence, set some\n% parameters, and start tracking:\n\n%%\n% \n% <<https:\/\/blogs.mathworks.com\/pick\/files\/PIVLabScreenshotSmall.png>>\n% \n\n%%\n% In truth, I haven't (yet!) been able to recreate with PIVLab the results from\n% my dissertation. But one thing is sureREPLACE_WITH_DASH_DASHthis would have been a very\n% useful starting point, and it would have saved me countless weeks of\n% effort! (The flexibility and customizability of MATLAB codeREPLACE_WITH_DASH_DASHincluding\n% that on the File ExchangeREPLACE_WITH_DASH_DASHis truly what makes it so useful.)\n\n%% A video tutorial!\n% I love that William took the trouble of recording a twelve-minute video\n% to get you started using his tool.\n%%\n% \n% <<https:\/\/blogs.mathworks.com\/pick\/files\/PIVLabTutorial.png>>\n% \n\n%% \n% The tool is richly featured, and includes many different visualizations\n% and processing functions for looking at particle flows:\n\n%%\n% \n% <<https:\/\/blogs.mathworks.com\/pick\/files\/flowVisualization.png>>\n\n%% One suggestion\n% I had to convert my video files to sequences of images to get them to\n% work in PIVLab. It's not very difficult to make your app support video\n% filesREPLACE_WITH_DASH_DASHusing VideoReader, for instance! But creating an image sequence\n% from a video is a minor task, too:\n\n%%\n%  vid = VideoReader('C:\\Sample Data\\ONH_PIV_10.avi');\n%  frame = readFrame(vid);\n%  imgh = imshow(frame);\n%  index = 1;\n%  while hasFrame(vid)\n%     imwrite(frame,['C:\\Sample Data\\ONHFramewise\\','Frame_',sprintf('%03i',index),'.tif']);\n%     index = index + 1;\n%     set(imgh,'cdata',frame)\n%     frame = readFrame(vid);\n%     drawnow\n%  end\n%%\n% It's worth noting that William is among the top 100 most-downloaded\n% authors on the File ExchangeREPLACE_WITH_DASH_DASHlargely on the strength of PIVLab. It is\n% current (the last update was January 2019); it has 80 user reviews\n% hovering, on average, around 5\/5 stars; and has been downloaded thousands\n% of times. This file is long overdue for Pick-of-the-Week recognition!\n% William, I appreciate the effort it took to create this fine tool. And I\n% greatly appreciate your sharing it with the MATLAB community!\n%%\n% As always, I welcome your\n% <http:\/\/blogs.mathworks.com\/pick\/?p=10476#respond thoughts and comments>.\n##### SOURCE END ##### 267de97c52984015849979ba1601c411\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/PIVLabScreenshotSmall.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>\nBrett&#8216;s Pick this week is PIVLab, by William Thielicke.<\/p>\n<p>Contents<\/p>\n<p>A Particle Velocimetry Suite of Tools!<br \/>\nA video tutorial!<br \/>\nOne suggestion<\/p>\n<p>A Particle Velocimetry Suite of Tools!<br \/>\nMany years&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2019\/02\/01\/comprehensive-easy-to-use-particle-image-velocimetry-tool\/\">read more >><\/a><\/p>\n","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\/10476"}],"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=10476"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10476\/revisions"}],"predecessor-version":[{"id":10494,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10476\/revisions\/10494"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=10476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=10476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=10476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}