<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Depth-Map.com</title>
    <description>The latest articles on DEV Community by Depth-Map.com (@depthmap).</description>
    <link>https://dev.to/depthmap</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4242478%2F9c04bffd-eade-455b-88bf-8a1dcfd0c9b4.png</url>
      <title>DEV Community: Depth-Map.com</title>
      <link>https://dev.to/depthmap</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/depthmap"/>
    <language>en</language>
    <item>
      <title>How to Tell If a PNG Is Really 16-bit: Read the Header, Then Count the Gray Levels</title>
      <dc:creator>Depth-Map.com</dc:creator>
      <pubDate>Fri, 20 Nov 2026 14:36:10 +0000</pubDate>
      <link>https://dev.to/depthmap/how-to-tell-if-a-png-is-really-16-bit-read-the-header-then-count-the-gray-levels-2b66</link>
      <guid>https://dev.to/depthmap/how-to-tell-if-a-png-is-really-16-bit-read-the-header-then-count-the-gray-levels-2b66</guid>
      <description>&lt;p&gt;I keep running into the same bug in depth maps and height maps: the file says it is 16-bit, and the pixels say otherwise. Image viewers will not tell you. A viewer shows you gray, and 256 grays and 65,536 grays look the same on a monitor.&lt;/p&gt;

&lt;p&gt;The difference only appears downstream, when something turns brightness into height. A CNC toolpath, a laser engraver or a displacement modifier samples that gray as a distance. If the file really holds 256 distinct values, the surface has 256 terraces however many bits the header claims.&lt;/p&gt;

&lt;p&gt;So there are two separate facts to check, and neither one is enough on its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fact 1: the bit depth in the header
&lt;/h2&gt;

&lt;p&gt;A PNG starts with an 8-byte signature, followed by chunks. The first chunk is always &lt;code&gt;IHDR&lt;/code&gt;, and it holds the width, the height, the &lt;strong&gt;bit depth&lt;/strong&gt;, the &lt;strong&gt;colour type&lt;/strong&gt; and the interlace flag. For a depth map you want colour type 0 (grayscale) and bit depth 16.&lt;/p&gt;

&lt;p&gt;That field describes the container, not the content. A 16-bit PNG can hold any 8-bit image: write each 8-bit value &lt;code&gt;v&lt;/code&gt; as &lt;code&gt;v * 257&lt;/code&gt; (so 255 becomes 65,535) and the header is honest about the container while the content is still 8-bit. Plenty of exporters, resizers and "convert to 16-bit" buttons do exactly that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fact 2: how many distinct levels are actually there
&lt;/h2&gt;

&lt;p&gt;Count the unique pixel values. A genuinely 16-bit field with a smooth surface has thousands of them. A stretched 8-bit field has at most 256, and every one is a multiple of 257. That second detail is a useful fingerprint, because a real 16-bit file would not land only on multiples of 257 by chance.&lt;/p&gt;

&lt;p&gt;Two caveats before you trust the count:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A small image caps the count.&lt;/strong&gt; A 64Ã—64 image has at most 4,096 distinct pixels, so a low count there proves nothing. Use the full-size export.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A flat scene has few levels for an honest reason.&lt;/strong&gt; A depth map of a flat plate with one small boss on it genuinely contains few values. A low count is a warning, not a verdict. Use it together with the header, and look for the multiples-of-257 pattern.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A browser-or-Node snippet
&lt;/h2&gt;

&lt;p&gt;Do not try to count levels by drawing the PNG onto a &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt; and calling &lt;code&gt;getImageData&lt;/code&gt;: by default the canvas hands back 8-bit RGBA, so a 16-bit file is flattened before you ever see it. You have to read the PNG bytes yourself.&lt;/p&gt;

&lt;p&gt;This version reads the header, then inflates the pixel data and undoes the PNG row filters, for plain non-interlaced grayscale files in 8 or 16 bit. It uses &lt;code&gt;DecompressionStream&lt;/code&gt;, which exists in Node 18+ and in current browsers (I ran it only in Node 24 for this article; in a browser, pass it &lt;code&gt;new Uint8Array(await file.arrayBuffer())&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// inspect_png.mjs  -  node inspect_png.mjs file.png&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;readFileSync&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"node:fs"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;inspectPng&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;dv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DataView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;byteOffset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;byteLength&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hdr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;idat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUint32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pos&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromCharCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subarray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subarray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"IHDR"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;hdr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;dv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUint32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;dv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUint32&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="n"&gt;bitDepth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;colorType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;interlace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"IDAT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;idat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hdr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;colorType&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;hdr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;interlace&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hdr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bitDepth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;hdr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;idat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipeThrough&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DecompressionStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"deflate"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arrayBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bpp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hdr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bitDepth&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stride&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hdr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;bpp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stride&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stride&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;hdr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stride&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subarray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stride&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stride&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;stride&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;bpp&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bpp&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;bpp&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;bpp&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pa&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pa&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;pb&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;pa&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;pc&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pb&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;pc&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;hdr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bpp&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cur&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hdr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;uniqueLevels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;inspectPng&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It deliberately returns only the header for RGB, palette, interlaced or low-bit-depth files rather than guessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same check in Python
&lt;/h2&gt;

&lt;p&gt;If you already have numpy and Pillow, it is much shorter. The header is read straight from the file, so you see what the file itself declares rather than what Pillow decided to hand you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="no"&gt;PIL&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"rb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;fh&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;bit_depth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;       &lt;span class="c1"&gt;# IHDR fields&lt;/span&gt;
    &lt;span class="n"&gt;px&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;levels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{path}: header {bit_depth}-bit, colour type {color_type}, "&lt;/span&gt;
          &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{levels.size} unique levels, min {px.min()}, max {px.max()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;bit_depth&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"  all values multiples of 257:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;levels&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;257&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I generated three synthetic test scenes (a dome, a ramp and a coin-like medallion), saved each as a true 16-bit PNG, as an 8-bit image stretched into a 16-bit container, and as a plain 8-bit PNG. This is what the Python script printed for the dome, with the same counts from the JavaScript version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dome-true-16bit.png: header 16-bit, colour type 0, 12240 unique levels, min 0, max 65535
  all values multiples of 257: False
dome-stretched-8bit-in-16bit.png: header 16-bit, colour type 0, 253 unique levels, min 0, max 65535
  all values multiples of 257: True
dome-plain-8bit.png: header 8-bit, colour type 0, 253 unique levels, min 0, max 255
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first two files have identical headers and look nearly identical on screen. Only the count separates them: 12,240 against 253. (The stretched file has 253 rather than 256 because the dome never visits three of the 256 possible levels. That is normal.)&lt;/p&gt;

&lt;h2&gt;
  
  
  A public lion sample, on a 10 mm scale
&lt;/h2&gt;

&lt;p&gt;The dome figures above are from synthetic files that used the full &lt;code&gt;0…65,535&lt;/code&gt; range. A manufacturing depth map may not. I also re-counted a public lion-medallion set on 24 November 2026, from the &lt;a href="https://huggingface.co/datasets/depthmap/16bit-vs-8bit-depth-maps" rel="noopener noreferrer"&gt;16-bit vs 8-bit depth map dataset&lt;/a&gt; on Hugging Face. That set is a second case, not a replacement for the dome test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://depth-map.com/guides/16-bit-vs-8-bit-depth-maps" rel="noopener noreferrer"&gt;Depth-Map.com's 16-bit vs 8-bit guide&lt;/a&gt; describes this lion export as a 3 mm relief on a 1.5 mm base, Invert on, written on a 10 mm full scale (&lt;code&gt;65,535&lt;/code&gt; maps to 10 mm). The guide therefore expects the brightest pixel to be 19,661, not 65,535. &lt;strong&gt;65,536 is how many distinct codes a 16-bit grayscale PNG can hold.&lt;/strong&gt; It is not the unique-level count this sample should be expected to reach.&lt;/p&gt;

&lt;p&gt;I read the PNG &lt;code&gt;IHDR&lt;/code&gt; from the file bytes and counted unique samples with Pillow 13.0.0 on local copies of the dataset files. ImageMagick was not installed in that environment, so these counts are not &lt;code&gt;identify&lt;/code&gt; results. All three files are 1024×1024 grayscale. The 8-bit and upscaled files were derived in the dataset from the genuine 16-bit PNG (&lt;code&gt;value // 257&lt;/code&gt;, then &lt;code&gt;value * 257&lt;/code&gt;); they are not extra downloads from the site.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;Header&lt;/th&gt;
&lt;th&gt;Unique levels&lt;/th&gt;
&lt;th&gt;Min / max&lt;/th&gt;
&lt;th&gt;All multiples of 257?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;lion-depth-16bit.png&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;16-bit, colour type 0&lt;/td&gt;
&lt;td&gt;19,662&lt;/td&gt;
&lt;td&gt;0 / 19,661&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;lion-depth-8bit.png&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;8-bit, colour type 0&lt;/td&gt;
&lt;td&gt;77&lt;/td&gt;
&lt;td&gt;0 / 76&lt;/td&gt;
&lt;td&gt;No (8-bit codes)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;lion-depth-8bit-upscaled-to-16bit.png&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;16-bit, colour type 0&lt;/td&gt;
&lt;td&gt;77&lt;/td&gt;
&lt;td&gt;0 / 19,532&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The true 16-bit file uses every integer from &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;19,661&lt;/code&gt; inclusive (&lt;code&gt;19,661 − 0 + 1 = 19,662&lt;/code&gt;). The packed file's maximum is &lt;code&gt;76 × 257 = 19,532&lt;/code&gt;. Both 16-bit files have the same kind of header; only the counts, and the 257 fingerprint, separate them. A peak of 19,661 is expected on this scale. It does not mean the file is fake.&lt;/p&gt;

&lt;h2&gt;
  
  
  The one-liner, if you have ImageMagick
&lt;/h2&gt;

&lt;p&gt;With ImageMagick 7 installed, &lt;code&gt;identify&lt;/code&gt; can print both facts for a grayscale file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;identify -format &lt;span class="s2"&gt;"%z-bit | %k unique levels\n"&lt;/span&gt; file.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the same dome files it printed &lt;code&gt;16-bit | 12240 unique levels&lt;/code&gt;, &lt;code&gt;16-bit | 253 unique levels&lt;/code&gt; and &lt;code&gt;8-bit | 253 unique levels&lt;/code&gt;, matching the Python counts. I ran this on ImageMagick 7.1.2 in a Q16 build. Two things to watch: a Q8 build reads at 8 bits, and &lt;code&gt;%k&lt;/code&gt; counts unique colours, so it only means "gray levels" for a grayscale file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Skip the code if you only need an answer
&lt;/h2&gt;

&lt;p&gt;If you only have one file to check and do not want to run anything, the &lt;a href="https://depth-map.com/tools/16-bit-depth-map-checker?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=fake_16bit_check" rel="noopener noreferrer"&gt;16-bit depth map checker&lt;/a&gt; does the same two things in the browser: it compares the header bit depth with the measured unique level count and flags a 16-bit file with 256 or fewer levels. The page says it decodes the PNG locally and does not upload it. I work on Depth-Map.com, the site that hosts it, so weigh that accordingly. The scripts above are the better choice for batch checks and CI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it matters for 3D printing and CNC
&lt;/h2&gt;

&lt;p&gt;Height is range divided by levels. A 3 mm relief written with 256 levels has steps of about 3 mm / 256 â‰ˆ 11.7 Âµm. The same range with 65,536 levels is about 46 nm per step, far finer than any printer or cutter can resolve. You rarely need all of that precision, but you do want enough levels that the steps disappear below the machine's own resolution, and a stretched 8-bit file never gets there.&lt;/p&gt;

&lt;p&gt;Those 11.7 µm and 46 nm figures assume the 3 mm relief uses the entire 8-bit or 16-bit range, which is the situation in the dome files. The lion export is different: only about three tenths of the 10 mm scale is used. On that scale, the packed file has 77 levels, so the file-side step is &lt;code&gt;3 mm / 77 ≈ 0.039 mm&lt;/code&gt;, about 39 µm per terrace. The true 16-bit file uses codes &lt;code&gt;0…19,661&lt;/code&gt; contiguously, so the spacing is &lt;code&gt;10 mm / 65,535 ≈ 0.000153 mm&lt;/code&gt;, about 0.153 µm per code — the same as &lt;code&gt;3 mm / 19,661&lt;/code&gt;. These are file-side figures, not machine measurements.&lt;/p&gt;

&lt;p&gt;If you want published fiber-laser starting points after the file has passed this check, the page of &lt;a href="https://depth-map.com/for/lightburn-3d-sliced?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=fake_16bit_check" rel="noopener noreferrer"&gt;LightBurn 3D Sliced starting values&lt;/a&gt; lists a matrix for a 50 W JPT MOPA fiber source. I am pointing to that page, not reporting a test I ran on a laser. The page itself calls these starting values and says a corner test is still required.&lt;/p&gt;

&lt;p&gt;Also note that &lt;code&gt;v * 257&lt;/code&gt; is only one way a file ends up like this. A file saved through an 8-bit step anywhere in the pipeline (a screenshot, a JPEG, an editor in 8-bit mode) loses the extra levels for good, and re-saving it as 16-bit does not bring them back.&lt;/p&gt;

&lt;p&gt;A short checklist for a pipeline:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check the &lt;code&gt;IHDR&lt;/code&gt; bit depth is 16 and the colour type is 0.&lt;/li&gt;
&lt;li&gt;Count unique levels on the full-size file and compare with what the scene should contain.&lt;/li&gt;
&lt;li&gt;Check whether every value is a multiple of 257.&lt;/li&gt;
&lt;li&gt;Never round-trip the file through an 8-bit editor or a canvas.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Fail any of these and the fix is upstream, in whatever produced the file.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>3dprinting</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Judge and Clean a Depth Map Before You Displace It in Blender</title>
      <dc:creator>Depth-Map.com</dc:creator>
      <pubDate>Mon, 16 Nov 2026 12:30:44 +0000</pubDate>
      <link>https://dev.to/depthmap/how-to-judge-and-clean-a-depth-map-before-you-displace-it-in-blender-1d6i</link>
      <guid>https://dev.to/depthmap/how-to-judge-and-clean-a-depth-map-before-you-displace-it-in-blender-1d6i</guid>
      <description>&lt;p&gt;A depth map can look fine as a thumbnail and still fail on a Blender Displacement modifier: the relief comes out inverted, the background ripples, or a shallow face turns into a staircase. That is usually the height field, or a mesh too coarse to sample it.&lt;/p&gt;

&lt;p&gt;Before I render or export, I confirm the file is real 16-bit grayscale, look at the height field, clean what I can without a new generate, and only then set up the modifier.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Blender is sampling
&lt;/h2&gt;

&lt;p&gt;In this workflow a depth map, a height map, and a displacement map are the same thing: a single-channel grayscale image whose brightness is a height per pixel. Bright raises the surface; dark stays low. Blender's Displacement modifier reads that image as a texture and moves vertices. A Displace or Bump node in a shader only fakes lighting and leaves the silhouette flat. For a portrait that casts a real shadow, or geometry you can export to USD, FBX, or a slicer, use the modifier.&lt;/p&gt;

&lt;p&gt;The modifier can only move vertices that already exist. A plane with four corners gives you four samples, and the relief reads as a flat tile. In Edit Mode, subdivide the plane six times, or leave it low-poly and add a Subdivision Surface modifier (viewport 3 / render 6 is a workable starting point). That geometry is what the texture is sampled against.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the file, not the browser preview
&lt;/h2&gt;

&lt;p&gt;Browsers are a poor place to judge a manufacturing PNG. When depth is written on a 10 mm full scale, a 3 mm relief peaks well below the brightest possible gray, so the real file can look almost black even when the data is fine.&lt;/p&gt;

&lt;p&gt;First confirm bit depth. Some tools write an 8-bit map and upscale it into a 16-bit container, which does not invent the missing steps. ImageMagick is enough:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;identify -verbose your-depth-map.png &lt;span class="o"&gt;|&lt;/span&gt; grep -E &lt;span class="s2"&gt;"Depth|Statistics"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You want &lt;code&gt;Depth: 16-bit&lt;/code&gt;. On a 10 mm scale, a 3 mm export should peak around 19,661, not 65,535 — a lower max is expected. A file with 256 or fewer distinct grays, or values on multiples of 257, is an 8-bit field in a 16-bit wrapper.&lt;/p&gt;

&lt;p&gt;The difference shows up once a process samples the height. In an 8-bit PNG, a 3 mm relief on that same 10 mm scale has 77 height steps; in a 16-bit PNG it has 19,661. Shaded, the 8-bit steps read as terraces, and in Blender they show up on a dense mesh even if a preview looked smooth. Keep the import as 16-bit grayscale: do not save a JPEG, and do not let the texture slot treat it as sRGB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Look at the height field itself
&lt;/h2&gt;

&lt;p&gt;Before you touch Strength, flip between the photo and the grayscale.&lt;/p&gt;

&lt;p&gt;Is the subject one clear object? Single faces, emblems, and coin-style objects usually give a clean occlusion boundary. Group shots tend to flatten. Glass, water, and polished chrome often invent false near-far edges. Front light helps; side light can etch a cheek shadow as fake depth, and backlight can collapse the subject into mid-gray.&lt;/p&gt;

&lt;p&gt;Is high actually high? If a coin or medallion comes back hollow, the model has read the recessed field as closer than the rim — swap high and low before you displace. Watch the background too: a busy wall or textured table will rise and fall with the subject, and that noise later looks like a rippling floor around the portrait.&lt;/p&gt;

&lt;p&gt;I used a &lt;a href="https://depth-map.com/" rel="noopener noreferrer"&gt;depth map generator&lt;/a&gt; to get a 16-bit PNG from one photograph, then judged the field with those questions before I opened Blender. Generate is one model call; invert, gamma, flatten, and crop should be decided against the preview, not a first render.&lt;/p&gt;

&lt;h2&gt;
  
  
  Clean what you can without a new generate
&lt;/h2&gt;

&lt;p&gt;If the estimate is roughly right, you usually do not need another photograph through the model. These sliders rewrite the same field:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Flatten background&lt;/strong&gt; (0 to 0.80) pulls a textured backdrop down toward a constant height.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Crop&lt;/strong&gt; (0 to 35%) trims an edge that is stealing attention.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gamma&lt;/strong&gt; (0.30 to 3.00) compresses highlights or lifts shadows when the relief feels too harsh or too soft.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Invert&lt;/strong&gt; swaps near and far when the direction is wrong.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A new photo spends a credit; moving these controls does not. If the subject is still a group shot, a backlight silhouette, or a mirrored surface, no slider will invent a depth the model did not see. Reshoot with front light and one subject, then generate again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Then set Strength and modifier order
&lt;/h2&gt;

&lt;p&gt;With a clean 16-bit PNG, add a Displacement modifier, create a new Image or Movie texture, and open the file. Strength is a multiplier on the gray range, not a millimetre setting. A useful rule of thumb is Strength ≈ maximum relief depth divided by the plane's width in Blender units: on a 1-metre plane, 0.03–0.08 reads as subtle relief, 0.1–0.2 as a printed bas-relief, and 0.3 or more as a stylised exaggeration. Start at 0.1 and adjust after the first render.&lt;/p&gt;

&lt;p&gt;Optionally stack a Subdivision Surface modifier above Displacement so it smooths already-displaced geometry and keeps portrait detail from stair-stepping on a sparse mesh. Subsurf below densifies the plane first, but uses more memory. Cycles and Eevee both render the displaced mesh. If you need the geometry outside Blender, Apply the modifier first; a modifier stack does not travel out in a USD or FBX.&lt;/p&gt;

&lt;p&gt;This photo-to-height workflow is not a procedural terrain generator, and it does not export a normal map or a vector-displacement EXR. Blender reads the 16-bit PNG natively; if you need EXR or a tangent-space VDM, use a different tool.&lt;/p&gt;

&lt;p&gt;Do not debug Strength until you have checked bit depth, invert, background, and mesh density. Most bad displacements were already visible in the grayscale.&lt;/p&gt;

</description>
      <category>blender</category>
      <category>3d</category>
      <category>tutorial</category>
      <category>photography</category>
    </item>
    <item>
      <title>How to Turn a Photo into a 16-bit Depth Map and STL for 3D Printing, Laser Engraving, and CNC</title>
      <dc:creator>Depth-Map.com</dc:creator>
      <pubDate>Sun, 15 Nov 2026 05:45:45 +0000</pubDate>
      <link>https://dev.to/depthmap/how-to-turn-a-photo-into-a-16-bit-depth-map-and-stl-for-3d-printing-laser-engraving-and-cnc-a0j</link>
      <guid>https://dev.to/depthmap/how-to-turn-a-photo-into-a-16-bit-depth-map-and-stl-for-3d-printing-laser-engraving-and-cnc-a0j</guid>
      <description>&lt;p&gt;A single photograph will not give you a dimensionally accurate CAD solid, and it is not a substitute for photogrammetry when you have a ring of overlapping shots. What it &lt;em&gt;can&lt;/em&gt; give you is a height field: a grayscale image in which every pixel's brightness stands for a physical height, plus a mesh you can slice, engrave, or cut.&lt;/p&gt;

&lt;p&gt;That is the file a lithophane, a LightBurn 3D Sliced job, or a CNC bas-relief actually needs. This tutorial walks through how to get one — a real 16-bit PNG and a closed STL — from one photo, and how to send those files into the tools you already use.&lt;/p&gt;

&lt;p&gt;The workflow below uses &lt;a href="https://depth-map.com/" rel="noopener noreferrer"&gt;Depth-Map.com&lt;/a&gt;, a free online generator. Product details here are taken from the site itself (home, About, and Pricing) as of 14 November 2026.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you are making
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;depth map&lt;/strong&gt; is a grayscale image. Bright pixels are closer to the camera; dark pixels are further away. In the workshop that same file is also called a height map or a displacement map — Blender, a laser controller, and a lithophane slicer are reading the same gray values under different names.&lt;/p&gt;

&lt;p&gt;The setting that usually changes is &lt;strong&gt;invert&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bright means high when you carve or print a relief.&lt;/li&gt;
&lt;li&gt;Bright means thin when you print a lithophane and light it from behind.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Depth-Map.com returns two files from one photograph:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a &lt;strong&gt;16-bit grayscale PNG&lt;/strong&gt; (65,536 height values, mapped onto a 10 mm full scale)&lt;/li&gt;
&lt;li&gt;a &lt;strong&gt;closed, manifold STL&lt;/strong&gt;: a displaced top surface, a flat floor at &lt;code&gt;z = 0&lt;/code&gt;, and four straight walls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The STL is a sealed solid. Bambu Studio, PrusaSlicer, Cura, and Lychee are all described as slicing it without a repair step. The same PNG drops into LightBurn 3D Sliced, or into Blender's Displacement modifier and ZBrush as an alpha. There is no EXR export in the current version.&lt;/p&gt;

&lt;p&gt;This is not a procedural, tileable terrain generator for a game engine. It starts from a photograph and returns the depth it can estimate from that photograph.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1 — Upload a photo
&lt;/h2&gt;

&lt;p&gt;Open &lt;a href="https://depth-map.com/" rel="noopener noreferrer"&gt;Depth-Map.com&lt;/a&gt;. The workbench is on the homepage.&lt;/p&gt;

&lt;p&gt;A well-lit photo of a single subject works better than a busy wide scene. Medallions, portraits, and coin-style objects are a natural fit; the site's own homepage sample is a lion medallion, and you can download that sample's 16-bit PNG and closed STL without logging in if you just want to inspect the file format first.&lt;/p&gt;

&lt;p&gt;Presets on the workbench include General, Laser engraving, Challenge coin, Lithophane, and 3D print &amp;amp; CNC. General is described as balanced depth estimation, with a 16-bit PNG at 3 mm max depth, and as a starting point for almost every workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 — Generate once
&lt;/h2&gt;

&lt;p&gt;Press &lt;strong&gt;Generate&lt;/strong&gt;. That is the only moment the photograph is uploaded.&lt;/p&gt;

&lt;p&gt;A metric Depth Anything V3 model runs on the server, once, in one model size. The reply is a 16-bit grayscale PNG plus the near and far distances of the scene in metres. The site states that the photograph is then discarded on the server; the copy that remains is in your browser tab, and closing the tab clears it. Reloading the page without pressing Generate sends nothing at all.&lt;/p&gt;

&lt;p&gt;One Generate costs &lt;strong&gt;one credit&lt;/strong&gt;. A new photograph is what spends the credit. Everything in the next step does not.&lt;/p&gt;

&lt;p&gt;Without an account you get 3 Generates a day. A signed-in account with an empty balance receives 3 fresh credits each UTC day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 — Tune in the browser
&lt;/h2&gt;

&lt;p&gt;After Generate, every slider rewrites the preview and the mesh locally. The photograph is not uploaded a second time. The site lists these controls (ranges as shown on the homepage workbench):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Control&lt;/th&gt;
&lt;th&gt;Range on the workbench&lt;/th&gt;
&lt;th&gt;What it is for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Max depth&lt;/td&gt;
&lt;td&gt;0.3–10.0 mm&lt;/td&gt;
&lt;td&gt;Height of the relief itself&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Base thickness&lt;/td&gt;
&lt;td&gt;0.3–5.0 mm&lt;/td&gt;
&lt;td&gt;Floor under the relief&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Long side&lt;/td&gt;
&lt;td&gt;10–200 mm (starts at 40 mm)&lt;/td&gt;
&lt;td&gt;Overall XY size of the STL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Invert&lt;/td&gt;
&lt;td&gt;on/off&lt;/td&gt;
&lt;td&gt;Swap high and low — use it for backlit lithophanes, or when a coin comes back hollow&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gamma&lt;/td&gt;
&lt;td&gt;0.30–3.00&lt;/td&gt;
&lt;td&gt;Contrast of the height field&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Flatten background&lt;/td&gt;
&lt;td&gt;0.00–0.80&lt;/td&gt;
&lt;td&gt;Pull the background down&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Crop&lt;/td&gt;
&lt;td&gt;0–35%&lt;/td&gt;
&lt;td&gt;Trim the edges&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Overall height of the tallest point is &lt;strong&gt;base plus max depth&lt;/strong&gt;. A 2 mm base with a 5 mm relief therefore peaks at 7 mm.&lt;/p&gt;

&lt;p&gt;Because this step stays in the browser, changing your mind about depth, invert, or crop does not spend another credit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the file is 16-bit
&lt;/h2&gt;

&lt;p&gt;This is the part that shows up in the metal and in the print.&lt;/p&gt;

&lt;p&gt;The site writes depth on a 10 mm scale: the raw model file can reach 65,535, which maps to that 10 mm span. A 3 mm relief therefore uses less than a third of the gray range.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In an &lt;strong&gt;8-bit&lt;/strong&gt; PNG, that 3 mm relief has &lt;strong&gt;77&lt;/strong&gt; height steps.&lt;/li&gt;
&lt;li&gt;In this &lt;strong&gt;16-bit&lt;/strong&gt; PNG, the same relief has &lt;strong&gt;19,661&lt;/strong&gt; steps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Shaded, the 8-bit version shows terraces along every curve. On a shallow fiber-laser engrave, those steps can burn as visible topography lines.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://depth-map.com/about" rel="noopener noreferrer"&gt;About page&lt;/a&gt; notes that several competing tools write an 8-bit depth map and upscale to 16-bit on export — that does not invent the missing steps. They describe checking the problem with ImageMagick (&lt;code&gt;identify -verbose&lt;/code&gt;) and with side-by-side engraves. A longer comparison lives on the site's &lt;a href="https://depth-map.com/guides/16-bit-vs-8-bit-depth-maps" rel="noopener noreferrer"&gt;16-bit vs 8-bit guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 — Export into the tool you already have
&lt;/h2&gt;

&lt;p&gt;Download the 16-bit PNG, the closed STL, or both. Then pick the workshop path.&lt;/p&gt;

&lt;h3&gt;
  
  
  Laser engraving (LightBurn 3D Sliced)
&lt;/h3&gt;

&lt;p&gt;Drop the 16-bit PNG onto a LightBurn image layer and set the image mode to &lt;strong&gt;3D Sliced&lt;/strong&gt;. The height field maps to laser power automatically. The site does not ship a LightBurn project file; it publishes a starting table of power, frequency, and feed for brass, silver, stainless, aluminum, and copper on the &lt;a href="https://depth-map.com/for/lightburn-3d-sliced" rel="noopener noreferrer"&gt;LightBurn 3D Sliced page&lt;/a&gt;. Treat that table as a first test burn, not a finished recipe for your machine and your stock.&lt;/p&gt;

&lt;h3&gt;
  
  
  3D printing (lithophane or bas-relief)
&lt;/h3&gt;

&lt;p&gt;Import the closed STL into Bambu Studio, PrusaSlicer, Cura, or Lychee. For a lithophane, the homepage's starting point is &lt;strong&gt;inverted&lt;/strong&gt; depth, &lt;strong&gt;2.8 mm of relief on a 0.6 mm floor&lt;/strong&gt;. The mesh is a flat closed STL, not a curved shade. For a printed relief, leave invert off unless the preview looks inside-out, and size the long side with the slider (it starts at 40 mm and does not call the model again).&lt;/p&gt;

&lt;h3&gt;
  
  
  CNC bas-relief (Carveco, ArtCAM, VCarve)
&lt;/h3&gt;

&lt;p&gt;Import the closed STL into your CAM tool. The homepage's portrait example is a &lt;strong&gt;5 mm relief on a 2 mm base&lt;/strong&gt;, with the long side starting at 40 mm. Because the mesh already has a floor and four walls, you are starting from a solid, not an open displacement surface.&lt;/p&gt;

&lt;p&gt;If you would rather displace a mesh in software instead of machining one, import the same 16-bit PNG on a Blender Displacement modifier or as a ZBrush alpha.&lt;/p&gt;

&lt;h2&gt;
  
  
  Credits and what is — and is not — in this version
&lt;/h2&gt;

&lt;p&gt;The 16-bit PNG and the closed STL are the same files on every tier. From the &lt;a href="https://depth-map.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt; as of 14 November 2026:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Free:&lt;/strong&gt; $0. 3 new photos a day with no account; 3 credits each UTC day when you are signed in and the balance is empty. Sliders do not spend a credit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pro:&lt;/strong&gt; $19 a month for 300 credits (about $0.063 per Generate), or $182 a year ($15.17 a month effective, 3,600 credits per year).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Studio:&lt;/strong&gt; $49 a month for 2,000 credits (about $0.025 per Generate), or $468 a year ($39 a month effective, 24,000 credits per year).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Credit packs&lt;/strong&gt; (one-time, no subscription): 20 credits for $9 (90-day validity), 100 for $29 (180 days), 500 for $99 (365 days).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not in this version: batch upload, a public API, a separate commercial export format, or EXR. There is one model size.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Start with a well-lit photo of one subject.&lt;/li&gt;
&lt;li&gt;Upload it at &lt;a href="https://depth-map.com/" rel="noopener noreferrer"&gt;Depth-Map.com&lt;/a&gt; and press Generate once.&lt;/li&gt;
&lt;li&gt;Tune max depth, base, long side, invert, gamma, flatten, and crop in the browser until the preview matches the part.&lt;/li&gt;
&lt;li&gt;Download the 16-bit PNG and the closed STL.&lt;/li&gt;
&lt;li&gt;Send the PNG to LightBurn 3D Sliced, or the STL to your slicer or CAM tool, and run a small test before a finished piece.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you need a full 360° mesh from many photos, use photogrammetry. If you need a mechanical part with exact dimensions, model it in CAD and keep the photo as a reference. If you need the height inside one photograph as a file you can engrave, slice, or mill, a 16-bit depth map is the more direct route — and you can generate the first three from a photo today without creating an account.&lt;/p&gt;

</description>
      <category>3dprinting</category>
      <category>tutorial</category>
      <category>laser</category>
      <category>cnc</category>
    </item>
    <item>
      <title>Turn a Photo into a 16-bit Depth Map and a Printable STL</title>
      <dc:creator>Depth-Map.com</dc:creator>
      <pubDate>Sat, 14 Nov 2026 02:41:45 +0000</pubDate>
      <link>https://dev.to/depthmap/turn-a-photo-into-a-16-bit-depth-map-and-a-printable-stl-1im8</link>
      <guid>https://dev.to/depthmap/turn-a-photo-into-a-16-bit-depth-map-and-a-printable-stl-1im8</guid>
      <description>&lt;p&gt;A lot of “photo to 3D” tools try to invent a full object from one picture. That is a hard, often messy problem. A more reliable maker workflow is narrower: estimate depth from the photo, write that depth as a grayscale image and as a closed mesh, then cut, engrave, or print the relief.&lt;/p&gt;

&lt;p&gt;That is the path I use with &lt;a href="https://depth-map.com/" rel="noopener noreferrer"&gt;Depth-Map.com&lt;/a&gt;, a free online generator that turns one photo into a 16-bit PNG and a closed STL. This article walks through when that workflow fits, how the generate-then-tune loop works, and why the bit depth of the file actually shows up in the part.&lt;/p&gt;

&lt;h2&gt;
  
  
  When a depth map is the right tool
&lt;/h2&gt;

&lt;p&gt;Use a depth-from-image workflow when you have &lt;strong&gt;one photograph&lt;/strong&gt; and you want a relief-style surface:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a fiber-laser engrave in LightBurn 3D Sliced&lt;/li&gt;
&lt;li&gt;a lithophane or bas-relief on a 3D printer&lt;/li&gt;
&lt;li&gt;a CNC bas-relief in a tool such as Carveco, ArtCAM, or VCarve&lt;/li&gt;
&lt;li&gt;a displacement or alpha in Blender or ZBrush&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have many overlapping photos of a real object, photogrammetry (Meshroom, Metashape, RealityCapture) is still the more accurate way to get a full 3D mesh. If you need a mechanical part with exact dimensions and clean CAD topology, model it in Fusion 360 or similar and treat the photo as a reference. A single-image depth map will not replace either of those.&lt;/p&gt;

&lt;p&gt;Depth-Map.com also is not a procedural terrain generator for game engines. It starts from a photograph and returns the depth it can estimate from that photograph.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you get from one generate
&lt;/h2&gt;

&lt;p&gt;The flow on the site is four steps: upload a photo, press Generate, tune sliders, export.&lt;/p&gt;

&lt;p&gt;Generate runs a metric Depth Anything V3 model on the server, once. The response is a 16-bit grayscale PNG, plus the near and far distances of the scene in metres. After that reply comes back, the site says the photograph is discarded on the server; the copy that remains is in your browser tab.&lt;/p&gt;

&lt;p&gt;Everything after that is local. These sliders rewrite the preview and the mesh in the browser and do &lt;strong&gt;not&lt;/strong&gt; spend another credit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;max depth (mm)&lt;/li&gt;
&lt;li&gt;base thickness (mm)&lt;/li&gt;
&lt;li&gt;long side (mm)&lt;/li&gt;
&lt;li&gt;invert&lt;/li&gt;
&lt;li&gt;gamma&lt;/li&gt;
&lt;li&gt;flatten background&lt;/li&gt;
&lt;li&gt;crop&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One Generate costs one credit. A new photograph is what consumes the credit — changing your mind about depth, invert, or crop on the current photo does not.&lt;/p&gt;

&lt;p&gt;The downloads are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a real &lt;strong&gt;16-bit PNG&lt;/strong&gt; (65,536 grayscale levels, mapped on a 10 mm full scale)&lt;/li&gt;
&lt;li&gt;a &lt;strong&gt;closed, manifold STL&lt;/strong&gt;: a displaced top, a flat floor at z = 0, and four walls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The same 16-bit PNG is what some programs call a height map or a displacement map. Invert is the setting that usually changes: bright means high when you carve or print a relief; bright means thin when you print a lithophane and light it from behind. The &lt;a href="https://depth-map.com/guides/what-is-bas-relief-depth-map" rel="noopener noreferrer"&gt;bas-relief depth map guide&lt;/a&gt; goes into that distinction at more length.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why 16-bit is not a cosmetic upgrade
&lt;/h2&gt;

&lt;p&gt;This is the part that is easy to skip and then see in the metal or the print.&lt;/p&gt;

&lt;p&gt;The site writes depth on a 10 mm scale. A 3 mm relief therefore uses less than a third of the gray range. In an 8-bit PNG that is 77 height steps. In a 16-bit PNG it is 19,661 steps for the same relief. On a shallow engrave, those 8-bit steps show up as terraces or topography lines.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://depth-map.com/about" rel="noopener noreferrer"&gt;About page&lt;/a&gt; notes that some competing tools write an 8-bit depth map and upscale to 16-bit on export — that does not invent the missing steps. They also describe checking the files with ImageMagick (&lt;code&gt;identify -verbose&lt;/code&gt;) and with side-by-side engraves. There is a longer comparison in &lt;a href="https://depth-map.com/guides/16-bit-vs-8-bit-depth-maps" rel="noopener noreferrer"&gt;16-bit vs 8-bit depth maps&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exporting into tools you already have
&lt;/h2&gt;

&lt;p&gt;The files are meant to open without a mesh-repair step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LightBurn 3D Sliced for fiber-laser engraving&lt;/li&gt;
&lt;li&gt;Bambu Studio, PrusaSlicer, Cura, or Lychee for printing&lt;/li&gt;
&lt;li&gt;Carveco, ArtCAM, or VCarve for CNC relief&lt;/li&gt;
&lt;li&gt;Blender or ZBrush for displacement / alpha work (the site does not export EXR)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Practical starting points from the product pages, which you should still test on your own machine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lithophanes: inverted depth, about 2.8 mm of relief on a 0.6 mm floor; the mesh is a flat closed STL, not a curved shade&lt;/li&gt;
&lt;li&gt;challenge coins: about 0.8 mm depth on a 1.2 mm base, with the long side starting at 40 mm&lt;/li&gt;
&lt;li&gt;CNC portraits: a deeper relief, for example 5 mm on a 2 mm base, is a common starting range&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The About page says the published samples were printed or engraved on a Bambu Lab X1C, a Prusa MK4, and a 50 W JPT MOPA fiber laser, and checked in Bambu Studio 2.1, PrusaSlicer 2.8, and Cura 5.7. Treat those as the author’s test bench, not a guarantee for your stock or your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Credits and pricing
&lt;/h2&gt;

&lt;p&gt;As published on the &lt;a href="https://depth-map.com/pricing" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt; today:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;no account: 3 new photos a day&lt;/li&gt;
&lt;li&gt;signed in with an empty balance: 3 credits each UTC day&lt;/li&gt;
&lt;li&gt;sliders do not spend a credit&lt;/li&gt;
&lt;li&gt;Pro: $19/month for 300 credits (about $0.063 per Generate), or $182/year&lt;/li&gt;
&lt;li&gt;Studio: $49/month for 2,000 credits (about $0.025 per Generate), or $468/year&lt;/li&gt;
&lt;li&gt;optional one-time credit packs: 20 for $9 (90 days), 100 for $29 (180 days), 500 for $99 (365 days)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The free and paid tiers download the same 16-bit PNG and closed STL. The current version does not include batch upload, a public API, or a separate commercial export format.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Start with a well-lit photo. A medallion, a portrait, or a coin-style object works better than a busy wide scene.&lt;/li&gt;
&lt;li&gt;Upload it at &lt;a href="https://depth-map.com/" rel="noopener noreferrer"&gt;Depth-Map.com&lt;/a&gt; and press Generate once.&lt;/li&gt;
&lt;li&gt;Tune max depth, base, long side, invert, gamma, flatten, and crop in the browser until the preview matches the part you want.&lt;/li&gt;
&lt;li&gt;Download the 16-bit PNG and the STL.&lt;/li&gt;
&lt;li&gt;Send the PNG to LightBurn 3D Sliced, or the STL to your slicer or CAM tool, and run a small test before a finished piece.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you want a full 360° mesh from many photos, or a dimensionally accurate CAD solid, use a tool built for that job. If you want the height inside one photograph as a file you can engrave, slice, or displace, a 16-bit depth map is the more direct route.&lt;/p&gt;

</description>
      <category>stl</category>
      <category>3dprinting</category>
      <category>tutorial</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
