{"id":114,"date":"2007-02-06T16:30:49","date_gmt":"2007-02-06T21:30:49","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=114"},"modified":"2019-10-23T08:40:19","modified_gmt":"2019-10-23T12:40:19","slug":"antialiased-polygon-scan-conversion","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2007\/02\/06\/antialiased-polygon-scan-conversion\/","title":{"rendered":"Antialiased polygon scan conversion: Are you interested?"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>In December I wrote <a href=\"https:\/\/blogs.mathworks.com\/steve\/?p=108\">several blogs<\/a> about the algorithm underlying the <tt>poly2mask<\/tt> function.  Basically, the algorithm uses a 5-by-5 subpixel grid and lays out the polygon along the edges of the grid, like\r\n      this:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/108\/roipoly3_05.png\"> <\/p>\r\n   <p>The algorithm then makes a binary decision (inside or outside) for each pixel.  A given pixel is inside the polygon if and\r\n      only if the center subpixel square is inside the polygon.\r\n   <\/p>\r\n   <p>A very similar procedure could be used to compute an approximate fractional coverage for each pixel.  In other words, approximately\r\n      what fraction of each pixel is inside the polygon?  It might look like this:\r\n   <\/p>\r\n\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/114\/antialiased_scan_conversion_01.png\"> <p>For each pixel, you just divide the number of gray squares by 25 to get the approximate fractional coverage. This computation\r\n      could be used to do antialiased polygon scan conversion.  For example, compare the left and right images below.  The left\r\n      image is a binary image containing the output of <tt>poly2mask<\/tt>.  You can see the \"jaggies\" along the edges.  The right image is a grayscale image containing the fractional coverage of\r\n      each pixel.  The edges in this image appear smoother.\r\n   <\/p>\r\n\r\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/114\/antialiased_scan_conversion_02.png\"> <p>Readers: Would you like to see this functionality in the Image Processing Toolbox?  If so, what do you think you might use\r\n      it for?\r\n   <\/p><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\">\r\n      Published with MATLAB&reg; 7.3<br><\/p>\r\n<\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>\r\n   In December I wrote several blogs about the algorithm underlying the poly2mask function.  Basically, the algorithm uses a 5-by-5 subpixel grid and lays out the polygon along the edges of the... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2007\/02\/06\/antialiased-polygon-scan-conversion\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[296],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/114"}],"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=114"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":3516,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/114\/revisions\/3516"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}