{"id":4500,"date":"2021-05-13T17:09:40","date_gmt":"2021-05-13T21:09:40","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=4500"},"modified":"2021-05-13T17:19:54","modified_gmt":"2021-05-13T21:19:54","slug":"how-to-use-a-custom-interpolation-kernel-with-imresize","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2021\/05\/13\/how-to-use-a-custom-interpolation-kernel-with-imresize\/","title":{"rendered":"How to Use a Custom Interpolation Kernel with imresize"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Recently, I was talking with MathWorks writer Jessica Bernier about the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/ref\/imresize.html\"><span>reference page for the imresize function<\/span><\/a><span>.  Jessica pointed out that we don't have an example that shows how to use your own interpolation kernel. In today's post, I'll compare the supported interpolation kernels on a sample image, and then I'll show you how to use your own kernel.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The different methods supported by <\/span><span style=' font-family: monospace;'>imresize<\/span><span>, including <\/span><span style=' font-family: monospace;'>'bilinear'<\/span><span>, <\/span><span style=' font-family: monospace;'>'bicubic'<\/span><span>, <\/span><span style=' font-family: monospace;'>'lanczos2'<\/span><span>, and <\/span><span style=' font-family: monospace;'>'lanczos3'<\/span><span>, correspond to using different <\/span><span style=' font-style: italic;'>interpolation kernels<\/span><span>, also known as <\/span><span style=' font-style: italic;'>interpolants.<\/span><span> The bilinear method uses a triangular interpolation kernel, which is defined as:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span mathmlencoding=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;block&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;f&lt;\/mi&gt;&lt;mrow&gt;&lt;mo&gt;(&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;)&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mrow&gt;&lt;mo&gt;{&lt;\/mo&gt;&lt;mtable columnalign=&quot;left&quot;&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mo&gt;\u2264&lt;\/mo&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;otherwise&lt;\/mi&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;\/mtable&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;\/math&gt;\" style=\"vertical-align:-14px\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"block\"><mrow><mi mathvariant=\"italic\">f<\/mi><mrow><mo>(<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>)<\/mo><\/mrow><mo>=<\/mo><mrow><mo>{<\/mo><mtable columnalign=\"left\"><mtr><mtd><mrow><mn>1<\/mn><mo>-<\/mo><mrow><mo>|<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>|<\/mo><\/mrow><\/mrow><\/mtd><mtd><mrow><mrow><mo>|<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>|<\/mo><\/mrow><mo>\u2264<\/mo><mn>1<\/mn><\/mrow><\/mtd><\/mtr><mtr><mtd><mrow><mn>0<\/mn><\/mrow><\/mtd><mtd><mrow><mi mathvariant=\"normal\">otherwise<\/mi><\/mrow><\/mtd><\/mtr><\/mtable><\/mrow><\/mrow><\/math><\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >fplot(@triangle,[-3.5 3.5])<\/span><\/span><\/div><div  style = 'color: rgb(64, 64, 64); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper embeddedOutputsFigure\" uid=\"599E9B4D\" data-testid=\"output_0\" style=\"width: 1158px;\"><div class=\"figureElement\"><img decoding=\"async\" class=\"figureImage figureContainingNode\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/custom_kernel_example_osc_1.png\" style=\"width: 560px;\"><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>(The function <\/span><span style=' font-family: monospace;'>triangle<\/span><span>, as well as the other interpolation kernel functions used in this post, are at the end.)<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The bicubic method uses this piecewise cubic interpolation kernel:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span mathmlencoding=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;block&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;f&lt;\/mi&gt;&lt;mrow&gt;&lt;mo&gt;(&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;)&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mrow&gt;&lt;mo&gt;{&lt;\/mo&gt;&lt;mtable columnalign=&quot;left&quot;&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;5&lt;\/mn&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;3&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msup&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;5&lt;\/mn&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msup&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mo&gt;\u2264&lt;\/mo&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;5&lt;\/mn&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;3&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msup&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;5&lt;\/mn&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msup&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mn&gt;4&lt;\/mn&gt;&lt;mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;mo&gt;\u2264&lt;\/mo&gt;&lt;mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mo&gt;\u2264&lt;\/mo&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;otherwise&lt;\/mi&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;\/mtable&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;\/math&gt;\" style=\"vertical-align:-25px\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"block\"><mrow><mi mathvariant=\"italic\">f<\/mi><mrow><mo>(<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>)<\/mo><\/mrow><mo>=<\/mo><mrow><mo>{<\/mo><mtable columnalign=\"left\"><mtr><mtd><mrow><mn>1<\/mn><mo>.<\/mo><mn>5<\/mn><msup><mrow><mrow><mo>|<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>|<\/mo><\/mrow><\/mrow><mrow><mn>3<\/mn><\/mrow><\/msup><mo>-<\/mo><mn>2<\/mn><mo>.<\/mo><mn>5<\/mn><msup><mrow><mrow><mo>|<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>|<\/mo><\/mrow><\/mrow><mrow><mn>2<\/mn><\/mrow><\/msup><mo>+<\/mo><mn>1<\/mn><\/mrow><\/mtd><mtd><mrow><mrow><mo>|<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>|<\/mo><\/mrow><mo>\u2264<\/mo><mn>1<\/mn><\/mrow><\/mtd><\/mtr><mtr><mtd><mrow><mo>-<\/mo><mn>0<\/mn><mo>.<\/mo><mn>5<\/mn><msup><mrow><mrow><mo>|<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>|<\/mo><\/mrow><\/mrow><mrow><mn>3<\/mn><\/mrow><\/msup><mo>+<\/mo><mn>2<\/mn><mo>.<\/mo><mn>5<\/mn><msup><mrow><mrow><mo>|<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>|<\/mo><\/mrow><\/mrow><mrow><mn>2<\/mn><\/mrow><\/msup><mo>-<\/mo><mn>4<\/mn><mrow><mo>|<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>|<\/mo><\/mrow><mo>+<\/mo><mn>2<\/mn><\/mrow><\/mtd><mtd><mrow><mn>1<\/mn><mo>\u2264<\/mo><mrow><mo>|<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>|<\/mo><\/mrow><mo>\u2264<\/mo><mn>2<\/mn><\/mrow><\/mtd><\/mtr><mtr><mtd><mrow><mn>0<\/mn><\/mrow><\/mtd><mtd><mrow><mi mathvariant=\"normal\">otherwise<\/mi><\/mrow><\/mtd><\/mtr><\/mtable><\/mrow><\/mrow><\/math><\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >fplot(@cubic,[-3.5 3.5])<\/span><\/span><\/div><div  style = 'color: rgb(64, 64, 64); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper embeddedOutputsFigure\" uid=\"805B6F38\" data-testid=\"output_1\" style=\"width: 1158px;\"><div class=\"figureElement\"><img decoding=\"async\" class=\"figureImage figureContainingNode\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/custom_kernel_example_osc_2.png\" style=\"width: 560px;\"><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The lanczos2 and lanczos3 methods are based on the <\/span><a href = \"https:\/\/en.wikipedia.org\/wiki\/Lanczos_resampling\"><span>Lanczos family of interpolation kernels<\/span><\/a><span>, which are defined as follows (with <\/span><span mathmlencoding=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;inline&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;a&lt;\/mi&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/math&gt;\" style=\"vertical-align:-5px\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"inline\"><mrow><mi mathvariant=\"italic\">a<\/mi><mo>=<\/mo><mn>2<\/mn><\/mrow><\/math><\/span><span> or <\/span><span mathmlencoding=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;inline&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;a&lt;\/mi&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mn&gt;3&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/math&gt;\" style=\"vertical-align:-5px\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"inline\"><mrow><mi mathvariant=\"italic\">a<\/mi><mo>=<\/mo><mn>3<\/mn><\/mrow><\/math><\/span><span>):<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span mathmlencoding=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;block&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;f&lt;\/mi&gt;&lt;mrow&gt;&lt;mo&gt;(&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;)&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mrow&gt;&lt;mo&gt;{&lt;\/mo&gt;&lt;mtable columnalign=&quot;left&quot;&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;sinc&lt;\/mi&gt;&lt;mrow&gt;&lt;mo&gt;(&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;)&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;sinc&lt;\/mi&gt;&lt;mrow&gt;&lt;mo&gt;(&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo&gt;\/&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;a&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;)&lt;\/mo&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mo&gt;\u2264&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;a&lt;\/mi&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;otherwise&lt;\/mi&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;\/mtable&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;\/math&gt;\" style=\"vertical-align:-14px\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"block\"><mrow><mi mathvariant=\"italic\">f<\/mi><mrow><mo>(<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>)<\/mo><\/mrow><mo>=<\/mo><mrow><mo>{<\/mo><mtable columnalign=\"left\"><mtr><mtd><mrow><mi mathvariant=\"normal\">sinc<\/mi><mrow><mo>(<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>)<\/mo><\/mrow><mi mathvariant=\"normal\">sinc<\/mi><mrow><mo>(<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><mo>\/<\/mo><mi mathvariant=\"italic\">a<\/mi><\/mrow><mo>)<\/mo><\/mrow><\/mrow><\/mtd><mtd><mrow><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><mo>\u2264<\/mo><mi mathvariant=\"italic\">a<\/mi><\/mrow><\/mtd><\/mtr><mtr><mtd><mrow><mn>0<\/mn><\/mrow><\/mtd><mtd><mrow><mi mathvariant=\"normal\">otherwise<\/mi><\/mrow><\/mtd><\/mtr><\/mtable><\/mrow><\/mrow><\/math><\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 0px none rgb(0, 0, 0); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >lanczos2 = @(x) lanczos(x,2);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >lanczos3 = @(x) lanczos(x,3);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >fplot(lanczos2,[-3.5 3.5])<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >hold <\/span><span style=\"color: rgb(170, 4, 249);\">on<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >fplot(lanczos3,[-3.5 3.5])<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >hold <\/span><span style=\"color: rgb(170, 4, 249);\">off<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >legend([<\/span><span style=\"color: rgb(170, 4, 249);\">\"Lanczos 2\"<\/span><span >, <\/span><span style=\"color: rgb(170, 4, 249);\">\"Lanczos 3\"<\/span><span >])<\/span><\/span><\/div><div  style = 'color: rgb(64, 64, 64); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper embeddedOutputsFigure\" uid=\"F5857647\" data-testid=\"output_2\" style=\"width: 1158px;\"><div class=\"figureElement\"><img decoding=\"async\" class=\"figureImage figureContainingNode\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/custom_kernel_example_osc_3.png\" style=\"width: 560px;\"><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Interpolation kernels are often tested and compared by resizing a very small image to be several times larger. Here is a small icon image:<\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 0px none rgb(0, 0, 0); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >image_url = <\/span><span style=\"color: rgb(170, 4, 249);\">\"https:\/\/blogs.mathworks.com\/steve\/files\/region-analyzer-icon.png\"<\/span><span >;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >A = imread(image_url);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >imshow(A,<\/span><span style=\"color: rgb(170, 4, 249);\">\"InitialMagnification\"<\/span><span >,100)<\/span><\/span><\/div><div  style = 'color: rgb(64, 64, 64); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper embeddedOutputsFigure\" uid=\"F8548976\" data-testid=\"output_3\" style=\"width: 1158px;\"><div class=\"figureElement\"><img decoding=\"async\" class=\"figureImage figureContainingNode\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/custom_kernel_example_osc_4.png\" style=\"width: 145px;\"><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Let's scale this image up by a factor of 10 using the various interpolation methods and compare the results.<\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 0px none rgb(0, 0, 0); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >B_nearest = imresize(A,10,<\/span><span style=\"color: rgb(170, 4, 249);\">'nearest'<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >B_bilinear = imresize(A,10,<\/span><span style=\"color: rgb(170, 4, 249);\">'bilinear'<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >B_bicubic = imresize(A,10,<\/span><span style=\"color: rgb(170, 4, 249);\">'bicubic'<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >B_lanczos2 = imresize(A,10,<\/span><span style=\"color: rgb(170, 4, 249);\">'lanczos2'<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >B_lanczos3 = imresize(A,10,<\/span><span style=\"color: rgb(170, 4, 249);\">'lanczos3'<\/span><span >);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >montage({B_nearest, B_bilinear, B_bicubic, B_lanczos2, B_lanczos3},<\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    <\/span><span style=\"color: rgb(170, 4, 249);\">\"BackgroundColor\"<\/span><span >,<\/span><span style=\"color: rgb(170, 4, 249);\">\"white\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(64, 64, 64); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper embeddedOutputsFigure\" uid=\"DD95FE71\" data-testid=\"output_4\" style=\"width: 1158px;\"><div class=\"figureElement\"><img decoding=\"async\" class=\"figureImage figureContainingNode\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/custom_kernel_example_osc_5.png\" style=\"width: 800px;\"><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The nearest-neighbor result, at the upper left, appears quite blocky. In the early years of the Image Processing Toolbox, bilinear (the upper middle result) was the default method. It is better in most respects than the nearest-neighbor result, but it does look a little blurry.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The bicubic result (upper right) and lanczos2 result (lower left) appear very similar. Both interpolation kernels have a nonzero width of 4 (from <\/span><span mathmlencoding=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;inline&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/math&gt;\" style=\"vertical-align:-5px\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"inline\"><mrow><mi mathvariant=\"italic\">x<\/mi><mo>=<\/mo><mo>-<\/mo><mn>2<\/mn><\/mrow><\/math><\/span><span> to <\/span><span mathmlencoding=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;inline&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/math&gt;\" style=\"vertical-align:-5px\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"inline\"><mrow><mi mathvariant=\"italic\">x<\/mi><mo>=<\/mo><mn>2<\/mn><\/mrow><\/math><\/span><span>) and have one negative side lobe on each side. These results are sharper than the bilinear result. For example, look closely at the digits \"3\" and \"8\" near the top of the image.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>The lanczos3 kernel has a nonzero width of 6, with a negative and positive lobe on each side. The lanczos3 result (lower middle) is sharper than the bicubic and lanczos2 results, but it suffers from a visible \"ringing\" effect. You can see this by looking for the faint echo outside the gray boundary, or by looking just to the left and right of the thick black stripe running down the middle of the image.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>For this image, I prefer the bicubic method (today's <\/span><span style=' font-family: monospace;'>imresize<\/span><span> default) or the lanczos2 method.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>There have been a variety of research experiments with different types of interpolation kernels for image processing. For example, a paper by Min Hu and Jieqing Tan (\"Adaptive Osculatory Rational Interpolation for Image Processing,\" <\/span><span style=' font-style: italic;'>Journal of Computational and Applied Mathematics<\/span><span> 195 (2006) 46-53) explores the use of a piecewise rational function:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span mathmlencoding=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;block&quot;&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;f&lt;\/mi&gt;&lt;mrow&gt;&lt;mo&gt;(&lt;\/mo&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mo&gt;)&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mo&gt;=&lt;\/mo&gt;&lt;mrow&gt;&lt;mo&gt;{&lt;\/mo&gt;&lt;mtable columnalign=&quot;left&quot;&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;168&lt;\/mn&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msup&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;9129&lt;\/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;0808&lt;\/mn&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msup&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;8319&lt;\/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;0808&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mfrac&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mo&gt;\u2264&lt;\/mo&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;1953&lt;\/mn&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msup&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;5858&lt;\/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;3905&lt;\/mn&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;msup&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msup&gt;&lt;mo&gt;-&lt;\/mo&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;4402&lt;\/mn&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mo&gt;+&lt;\/mo&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;mo&gt;.&lt;\/mo&gt;&lt;mn&gt;7676&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mfrac&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;mo&gt;&amp;lt;&lt;\/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mo&gt;\u2264&lt;\/mo&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;mtr&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;mtd&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;\/mn&gt;&lt;mo&gt;&amp;lt;&lt;\/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;mi mathvariant=&quot;italic&quot;&gt;x&lt;\/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;|&lt;\/mo&gt;&lt;\/mrow&gt;&lt;\/mtd&gt;&lt;\/mtr&gt;&lt;\/mtable&gt;&lt;\/mrow&gt;&lt;\/mrow&gt;&lt;\/math&gt;\" style=\"vertical-align:-44px\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"block\"><mrow><mi mathvariant=\"italic\">f<\/mi><mrow><mo>(<\/mo><mrow><mi mathvariant=\"italic\">x<\/mi><\/mrow><mo>)<\/mo><\/mrow><mo>=<\/mo><mrow><mo>{<\/mo><mtable columnalign=\"left\"><mtr><mtd><mrow><mfrac><mrow><mo>-<\/mo><mn>0<\/mn><mo>.<\/mo><mn>168<\/mn><msup><mrow><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><\/mrow><mrow><mn>2<\/mn><\/mrow><\/msup><mo>-<\/mo><mn>0<\/mn><mo>.<\/mo><mn>9129<\/mn><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><mo>+<\/mo><mn>1<\/mn><mo>.<\/mo><mn>0808<\/mn><\/mrow><mrow><msup><mrow><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><\/mrow><mrow><mn>2<\/mn><\/mrow><\/msup><mo>-<\/mo><mn>0<\/mn><mo>.<\/mo><mn>8319<\/mn><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><mo>+<\/mo><mn>1<\/mn><mo>.<\/mo><mn>0808<\/mn><\/mrow><\/mfrac><\/mrow><\/mtd><mtd><mrow><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><mo>\u2264<\/mo><mn>1<\/mn><\/mrow><\/mtd><\/mtr><mtr><mtd><mrow><mfrac><mrow><mn>0<\/mn><mo>.<\/mo><mn>1953<\/mn><msup><mrow><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><\/mrow><mrow><mn>2<\/mn><\/mrow><\/msup><mo>-<\/mo><mn>0<\/mn><mo>.<\/mo><mn>5858<\/mn><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><mo>+<\/mo><mn>0<\/mn><mo>.<\/mo><mn>3905<\/mn><\/mrow><mrow><msup><mrow><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><\/mrow><mrow><mn>2<\/mn><\/mrow><\/msup><mo>-<\/mo><mn>2<\/mn><mo>.<\/mo><mn>4402<\/mn><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><mo>+<\/mo><mn>1<\/mn><mo>.<\/mo><mn>7676<\/mn><\/mrow><\/mfrac><\/mrow><\/mtd><mtd><mrow><mn>1<\/mn><mo>&lt;<\/mo><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><mo>\u2264<\/mo><mn>2<\/mn><\/mrow><\/mtd><\/mtr><mtr><mtd><mrow><mn>0<\/mn><\/mrow><\/mtd><mtd><mrow><mn>2<\/mn><mo>&lt;<\/mo><mo stretchy=\"false\">|<\/mo><mi mathvariant=\"italic\">x<\/mi><mo stretchy=\"false\">|<\/mo><\/mrow><\/mtd><\/mtr><\/mtable><\/mrow><\/mrow><\/math><\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Here's what that looks like:<\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >fplot(@osc,[-3.5 3.5])<\/span><\/span><\/div><div  style = 'color: rgb(64, 64, 64); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper embeddedOutputsFigure\" uid=\"439EF3CA\" data-testid=\"output_5\" style=\"width: 1158px;\"><div class=\"figureElement\"><img decoding=\"async\" class=\"figureImage figureContainingNode\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/custom_kernel_example_osc_6.png\" style=\"width: 800px;\"><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>To resize the image using this kernel, specify the function handle and the nonzero kernel width (4, in this case) as the method for <\/span><span style=' font-family: monospace;'>imresize<\/span><span>:<\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 4px; padding: 6px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >B_osc = imresize(A,10,{@osc,4});<\/span><\/span><\/div><\/div><\/div><div  style = 'margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Now compare this result with the others.<\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 0px none rgb(0, 0, 0); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >montage({B_nearest, B_bilinear, B_bicubic, B_lanczos2, B_lanczos3, B_osc},<\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    <\/span><span style=\"color: rgb(170, 4, 249);\">\"BackgroundColor\"<\/span><span >,<\/span><span style=\"color: rgb(170, 4, 249);\">\"white\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(64, 64, 64); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper embeddedOutputsFigure\" uid=\"F2B13BAA\" data-testid=\"output_6\" style=\"width: 1158px;\"><div class=\"figureElement\"><img decoding=\"async\" class=\"figureImage figureContainingNode\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/custom_kernel_example_osc_7.png\" style=\"width: 800px;\"><\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>To my eye, this newer interpolation kernel produces the best result of the bunch. It is slightly sharper than the bicubic and lanczos2 results, with slightly smoother diagonal edges, but without the ringing of the lanczos3 result. Fully assessing the performance of this kernel, though, would require examining a variety of different images and scale factors.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Have you ever used a custom interpolation kernel with <\/span><span style=' font-family: monospace;'>imresize<\/span><span>? What did you use? Leave a comment and let us know.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Thanks, Jessica, for prompting me to look at this.<\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 0px none rgb(0, 0, 0); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">function <\/span><span >f = triangle(x)<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >f = (1 - abs(x)) .* (abs(x) &lt;= 1);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">end<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">function <\/span><span >f = cubic(x)<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >absx = abs(x);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >absx2 = absx.^2;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >absx3 = absx.^3;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >f = (1.5*absx3 - 2.5*absx2 + 1) .* (absx &lt;= 1) + <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    (-0.5*absx3 + 2.5*absx2 - 4*absx + 2) .* <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    ((1 &lt; absx) &amp; (absx &lt;= 2));<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">end<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">function <\/span><span >f = lanczos(x,a)<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >f = a*sin(pi*x) .* sin(pi*x\/a) .\/ <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    (pi^2 * x.^2);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >f(abs(x) &gt; a) = 0;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >f(x == 0) = 1;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">end<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">function <\/span><span >f = osc(x)<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >absx = abs(x);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >absx2 = absx.^2;<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >f = (absx &lt;= 1) .* <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    ((-0.168*absx2 - 0.9129*absx + 1.0808) .\/ (absx2 - 0.8319*absx + 1.0808)) <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    + <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    ((1 &lt; absx) &amp; (absx &lt;= 2)) .* <\/span><span style=\"color: rgb(14, 0, 255);\">...<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >    ((0.1953*absx2 - 0.5858*absx + 0.3905) .\/ (absx2 - 2.4402*absx + 1.7676));<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span style=\"color: rgb(14, 0, 255);\">end<\/span><\/span><\/div><\/div><\/div>\r\n<\/div><script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script><a href=\"https:\/\/blogs.mathworks.com\/steve\/files\/custom_kernel_example_osc.mlx\"><button class=\"btn btn-sm btn_color_blue pull-right add_margin_10\">Download Live Script<\/button><\/a><div class=\"pull-right\"><div class=\"col-xs-12 containing-block\"><a href=\"#\" class=\"btn btn-sm btn_color_blue add_margin_20  hidden-xs try_live_editor_example\" data-liveeditorexample=\"{\n  &quot;repository&quot; : &quot;Blogs&quot;,\n  &quot;id&quot; : &quot;\/steve\/files\/custom_kernel_example_osc.mlx&quot;\n}\"><span class=\"icon-edit icon_16\"><\/span>Run in your browser<span style=\"color:grey\" class=\"series\"><\/span><\/a><\/div><\/div>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/steve\/files\/custom_kernel_example_osc_7.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Recently, I was talking with MathWorks writer Jessica Bernier about the reference page for the imresize function.  Jessica pointed out that we don't have an example that shows how to use your own... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2021\/05\/13\/how-to-use-a-custom-interpolation-kernel-with-imresize\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":4496,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/4500"}],"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=4500"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/4500\/revisions"}],"predecessor-version":[{"id":4504,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/4500\/revisions\/4504"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media\/4496"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=4500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=4500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=4500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}