{"id":351,"date":"2013-09-14T12:24:00","date_gmt":"2013-09-14T12:24:00","guid":{"rendered":"http:\/\/ahay.org\/blog\/?p=351"},"modified":"2015-08-30T20:57:56","modified_gmt":"2015-08-30T20:57:56","slug":"program-of-the-month-sfpatch","status":"publish","type":"post","link":"https:\/\/ahay.org\/blog\/2013\/09\/14\/program-of-the-month-sfpatch\/","title":{"rendered":"Program of the month: sfpatch"},"content":{"rendered":"<p><a href=\"\/RSF\/sfpatch.html\">sfpatch<\/a> breaks the input data into local windows or &#8220;patches&#8221;, possibly with overlap. <\/p>\n<p>The patching technique is explained by Jon Claerbout in <a href=\"\/RSF\/book\/gee\/pch\/paper_html\/\">Nonstationarity: patching<\/a> chapter from <em>Image Estimation by Example<\/em>. <\/p>\n<p><img decoding=\"async\" src=\"\/RSF\/book\/gee\/pch\/XFig\/Fig\/antoine.png\" alt=\"\" title=\"\" \/> <\/p>\n<p>Suppose you have a 1-D signal with 10 samples: <\/p>\n<div class=\"code-box\"><div class=\"code-title\"><i class=\"fa fa-code\"><\/i> <div class=\"pull-right\"><a href=\"#\" class=\"btn btn-default btn-xs toggle-code\" data-toggle=\"tooltip\" title=\"Toggle code\"><i class=\"fa fa-toggle-up\"><\/i><\/a><\/div><\/div><pre ><code>bash$ sfmath n1=10 output=x1 &gt; data.rsf\n<\/code><\/pre><\/div>\n<p>You can divide it, for example, into two patches with 5 samples each: <\/p>\n<div class=\"code-box\"><div class=\"code-title\"><i class=\"fa fa-code\"><\/i> <div class=\"pull-right\"><a href=\"#\" class=\"btn btn-default btn-xs toggle-code\" data-toggle=\"tooltip\" title=\"Toggle code\"><i class=\"fa fa-toggle-up\"><\/i><\/a><\/div><\/div><pre ><code>bash$ &lt; data.rsf sfpatch p=2 w=5 &gt; patch.rsf\nbash$ sfget n1 n2 &lt; patch.rsf \nn1=5\nn2=2\n<\/code><\/pre><\/div>\n<p>or into 5 overlapping patches with 3 samples each: <\/p>\n<div class=\"code-box\"><div class=\"code-title\"><i class=\"fa fa-code\"><\/i> <div class=\"pull-right\"><a href=\"#\" class=\"btn btn-default btn-xs toggle-code\" data-toggle=\"tooltip\" title=\"Toggle code\"><i class=\"fa fa-toggle-up\"><\/i><\/a><\/div><\/div><pre ><code>bash$ &lt; data.rsf sfpatch p=5 w=3 &gt; patch.rsf\nbash$ sfget n1 n2 &lt; patch.rsf \nn1=3\nn2=5\n<\/code><\/pre><\/div>\n<p>If you specify only the patch size (<strong>w=<\/strong> parameter), <strong>sfpatch<\/strong> tries to select the number of patches to achieve a good overlap: <\/p>\n<div class=\"code-box\"><div class=\"code-title\"><i class=\"fa fa-code\"><\/i> <div class=\"pull-right\"><a href=\"#\" class=\"btn btn-default btn-xs toggle-code\" data-toggle=\"tooltip\" title=\"Toggle code\"><i class=\"fa fa-toggle-up\"><\/i><\/a><\/div><\/div><pre ><code>bash$ &lt; data.rsf sfpatch w=3 &gt; patch.rsf\nbash$ sfget n1 n2 &lt; patch.rsf \nn1=3\nn2=6\n<\/code><\/pre><\/div>\n<p>If you put overlapped patches back together, their amplitudes add in the overlapped regions: <\/p>\n<div class=\"code-box\"><div class=\"code-title\"><i class=\"fa fa-code\"><\/i> <div class=\"pull-right\"><a href=\"#\" class=\"btn btn-default btn-xs toggle-code\" data-toggle=\"tooltip\" title=\"Toggle code\"><i class=\"fa fa-toggle-up\"><\/i><\/a><\/div><\/div><pre ><code>bash$ &lt; data.rsf sfdd type=int | sfdisfil \n   0:    0    1    2    3    4    5    6    7    8    9\nbash$&lt; patch.rsf sfpatch inv=y | sfdd type=int | sfdisfil\n   0:    0    2    6    6    8   10   12   14    8    9\n<\/code><\/pre><\/div>\n<p>unless you use the weight option: <\/p>\n<div class=\"code-box\"><div class=\"code-title\"><i class=\"fa fa-code\"><\/i> <div class=\"pull-right\"><a href=\"#\" class=\"btn btn-default btn-xs toggle-code\" data-toggle=\"tooltip\" title=\"Toggle code\"><i class=\"fa fa-toggle-up\"><\/i><\/a><\/div><\/div><pre ><code>bash$ &lt; patch.rsf sfpatch inv=y weight=y | sfdd type=int | sfdisfil\n   0:    0    1    2    3    4    5    6    7    8    9\n<\/code><\/pre><\/div>\n<p>bash$ <strong>sfpatch<\/strong> easily handles multidimensional data: <strong>w=<\/strong> and <strong>p=<\/strong> become lists of dimensions, and the number of dimensions in the output effectively doubles. <strong>sfpatch<\/strong> is useful in two applications: <\/p>\n<ol>\n<li>crude handling of non-stationarity when processing non-stationary signals with locally stationary filters,<\/li>\n<li>making non-parallel tasks data-parallel.<\/li>\n<\/ol>\n<p>A simple example from <a href=\"\/RSF\/book\/rsf\/rsf\/mona.html\">rsf\/rsf\/mona<\/a> illustrates the second use. <\/p>\n<p><img decoding=\"async\" src=\"\/RSF\/book\/rsf\/rsf\/mona\/Fig\/mona2.png\" alt=\"\" title=\"\" \/> <img decoding=\"async\" src=\"\/RSF\/book\/rsf\/rsf\/mona\/Fig\/pmona2.png\" alt=\"\" title=\"\" \/><\/p>\n<p>Anisotropic diffusion, implemented by <a href=\"\/RSF\/sfimpl2.html\">sfimpl2<\/a>, is an effective but relatively slow process. By breaking the input 512&#215;512 image into nine 200&#215;200 overlapping patches and by processing them in parallel on a multi-core computer, we can achieve a significant speed-up without rewriting the original program. <\/p>\n<h3 id=\"10previousprogramsofthemonth\">10 previous programs of the month<\/h3>\n<ul>\n<li><a href=\"\/blog\/2013\/08\/02\/program-of-the-month-sfai2refl\/\">sfai2refl<\/a><\/li>\n<li><a href=\"\/blog\/2013\/07\/01\/program-of-the-month-sftime2depth\/\">sftime2depth<\/a><\/li>\n<li><a href=\"\/blog\/2013\/06\/12\/program-of-the-month-sfwiggle\/\">sfwiggle<\/a><\/li>\n<li><a href=\"\/blog\/2013\/05\/04\/program-of-the-month-sfvscan\/\">sfvscan<\/a><\/li>\n<li><a href=\"\/blog\/2013\/04\/08\/program-of-the-month-sfnmo\/\">sfnmo<\/a><\/li>\n<li><a href=\"\/blog\/2013\/03\/10\/program-of-the-month-sfpow\/\">sfpow<\/a><\/li>\n<li><a href=\"\/blog\/2013\/02\/09\/program-of-the-month-sfpwd\/\">sfpwd<\/a><\/li>\n<li><a href=\"\/blog\/2013\/01\/08\/program-of-the-month-sfricker1\/\">sfricker1<\/a><\/li>\n<li><a href=\"\/blog\/2012\/12\/23\/program-of-the-month-sfhalfint\/\">sfhalfint<\/a><\/li>\n<li><a href=\"\/blog\/2012\/11\/03\/program-of-the-month-sfbandpass\/\">sfbandpass<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>sfpatch breaks the input data into local windows or &#8220;patches&#8221;, possibly with overlap. The patching technique is explained by Jon Claerbout in Nonstationarity: patching chapter from Image Estimation by Example. Suppose you have a 1-D signal with 10 samples: bash$ sfmath n1=10 output=x1 &gt; data.rsf You can divide it, for example, into two patches with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","activitypub_content_warning":"","activitypub_content_visibility":"local","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-351","post","type-post","status-publish","format-standard","hentry","category-programs"],"_links":{"self":[{"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/posts\/351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/comments?post=351"}],"version-history":[{"count":3,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/posts\/351\/revisions"}],"predecessor-version":[{"id":15565,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/posts\/351\/revisions\/15565"}],"wp:attachment":[{"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/media?parent=351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/categories?post=351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/tags?post=351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}