{"id":2657,"date":"2016-12-19T00:00:26","date_gmt":"2016-12-19T08:00:26","guid":{"rendered":"http:\/\/192.168.3.4\/?p=2657"},"modified":"2018-01-09T06:51:13","modified_gmt":"2018-01-09T14:51:13","slug":"netpbm-the-portable-anymap-format","status":"publish","type":"post","link":"https:\/\/www.cloudacm.com\/?p=2657","title":{"rendered":"Netpbm &#8211; The Portable Anymap Format"},"content":{"rendered":"<p>Presenting visual data readings into an image file can seem challenging.\u00a0 It need not be thanks to the Netpbm (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Netpbm_format\">https:\/\/en.wikipedia.org\/wiki\/Netpbm_format<\/a>) file formats.<\/p>\n<p>First developed by Jef Poskanzer (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Jef_Poskanzer\">https:\/\/en.wikipedia.org\/wiki\/Jef_Poskanzer<\/a>) as a means of sending image data via email.\u00a0 The early adaptations of email did not work well with data other than ASCII.\u00a0 Messages would become corrupt if binary data was included in messages.\u00a0 Today, this is not an issue.\u00a0 However, the work around for this was to use one of the Netpbm file formats.<\/p>\n<p>The Netpbm files contain plaintext ASCII information about pixels and the data they contain.\u00a0 This makes it an ideal format to use when reconstructing visual type data readings.\u00a0 Its simplicity removes much of the needed work used by other conventional file formats.\u00a0 It also removes the burden for data processing, which is needed to create the files.\u00a0 It&#8217;s a great way for the beginner to create useful data representations of data.\u00a0 Lets look at the details behind this simple yet powerful file format.<\/p>\n<p>As mentioned already, the Netpbm format is plain text.\u00a0 I&#8217;ll be covering three distinct image types within the Netpbm suite.\u00a0 These image types are defined as follows.<\/p>\n<p>Type \u00a0\u00a0 \u00a0Magic number \u00a0\u00a0 \u00a0Magic number \u00a0\u00a0 \u00a0Extension \u00a0\u00a0 \u00a0Colors<br \/>\nPortable BitMap \u00a0\u00a0 \u00a0P1 ASCII \u00a0\u00a0 \u00a0P4 binary \u00a0\u00a0 \u00a0.pbm \u00a0\u00a0 \u00a00\u20131 (black &amp; white)<br \/>\nPortable GrayMap \u00a0\u00a0 \u00a0P2 ASCII \u00a0\u00a0 \u00a0P5 binary \u00a0\u00a0 \u00a0.pgm \u00a0\u00a0 \u00a00\u2013255 (gray scale)<br \/>\nPortable PixMap \u00a0\u00a0 \u00a0P3 ASCII \u00a0\u00a0 \u00a0P6 binary \u00a0\u00a0 \u00a0.ppm \u00a0\u00a0 \u00a00\u2013255 (RGB)<\/p>\n<p>Portable BitMap images are the most simplest of all the Netpbm formats.\u00a0 Each pixel is either black or white.\u00a0 The file extension is PBM to depict this specific file format.\u00a0 The actual data that defines the file is the header information and the beginning lines of the file.\u00a0 Below is an example of a 6 x 10 pixel bitmap image.<\/p>\n<pre>P1\r\n# This is an example bitmap of the letter \"J\"\r\n6 10\r\n0 0 0 0 1 0\r\n0 0 0 0 1 0\r\n0 0 0 0 1 0\r\n0 0 0 0 1 0\r\n0 0 0 0 1 0\r\n0 0 0 0 1 0\r\n1 0 0 0 1 0\r\n0 1 1 1 0 0\r\n0 0 0 0 0 0\r\n0 0 0 0 0 0<\/pre>\n<p>The first line is referred to as the &#8220;magic number&#8221;.\u00a0 This defines the bitmap scale, P1 for black and white, P2 for gray scale, and P3 for RGB.\u00a0 The next line start with a &#8220;#&#8221; symbol and is a comment line.\u00a0 This is optional but can be useful to use with telemetry generating this data.\u00a0 The third line defines the dimensions of the image, 6 x 10 pixels.\u00a0 What follows it the meat of the file.\u00a0 These are the actual pixel values to be presented.\u00a0 A character return has been included so the visual effect can be seen.\u00a0 However, it is more common than not that the data will be one continuous string of text.<\/p>\n<p>Here are three examples of an image of Haystack Rock in the different file types.<\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2016\/12\/Haystack_PixelMap.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2662\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2016\/12\/Haystack_PixelMap.png\" alt=\"haystack_pixelmap\" width=\"163\" height=\"122\" \/><\/a><br \/>\nBlack and White Pixel Bitmap<\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2016\/12\/Haystack_GrayMap.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2663\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2016\/12\/Haystack_GrayMap.png\" alt=\"haystack_graymap\" width=\"163\" height=\"122\" \/><\/a><br \/>\nGray Scale Pixel Graymap<\/p>\n<p><a href=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2016\/12\/Haystatck_ColorMap.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2664\" src=\"http:\/\/192.168.3.4\/wp-content\/uploads\/2016\/12\/Haystatck_ColorMap.png\" alt=\"haystatck_colormap\" width=\"163\" height=\"122\" \/><\/a><br \/>\nColor Scale Pixel Pixmap<\/p>\n<p>The Gray Scale image uses the &#8220;magic number&#8221; P2.\u00a0 You can see more detail in each successive image format.\u00a0 The gray scale image has pixel values that range from 0 to 255, from darkest to lightest.\u00a0 Opening the image file in a text editor, all of the pixels appear to be a single line item.\u00a0 As mentioned before, character returns are not a requirement, only a space between the values is.<\/p>\n<p>The Color Scale image uses the &#8220;magic number&#8221; P3.\u00a0 Each pixel has three values defined for it in the red, green, and blue range.\u00a0 Like the gray scale range, each vary from 0 to 255, from darkest to lightest.<\/p>\n<p>So you might ask yourself, why not have all image formats follow this convention. The substantial reason is file size. The Netpbm file formats are extremely wasteful in regards to the data space they occupy. Binary file formats like, PNG, JPG, and GIF are more efficient. Because of this, most web content does not contain Netpbm files.<\/p>\n<p>Regardless of choice of image formats on the web, Netpbm is well suited to take raw data streams and present them visually. I&#8217;ll be using the Gray Scale Pixel Graymap, also known as PGM, for my next post. In it, I&#8217;ll take temperature readings from a Melexis MLX90620 and plot a thermal image. Using the Netpbm from this will eliminate my image processing workload. I&#8217;ll have image files native to the hardware and they&#8217;ll port easily.<\/p>\n<p>I look forward to seeing ahead, enjoy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Presenting visual data readings into an image file can seem challenging.\u00a0 It need not be thanks to the Netpbm (https:\/\/en.wikipedia.org\/wiki\/Netpbm_format) file formats. First developed by Jef Poskanzer (https:\/\/en.wikipedia.org\/wiki\/Jef_Poskanzer) as a means of sending image data via email.\u00a0 The early adaptations of email did not work well with data other than ASCII.\u00a0 Messages would become corrupt if binary data was included in messages.\u00a0 Today, this is not an issue.\u00a0 However, the work around for this was to use one of the&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.cloudacm.com\/?p=2657\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,10,3],"tags":[],"class_list":["post-2657","post","type-post","status-publish","format-standard","hentry","category-computer-vision","category-data-mining","category-rd"],"_links":{"self":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2657"}],"version-history":[{"count":7,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2657\/revisions"}],"predecessor-version":[{"id":2671,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=\/wp\/v2\/posts\/2657\/revisions\/2671"}],"wp:attachment":[{"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudacm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}