title: How to save bi-level image to file in julia?
body: <p>Objective: To save image in bi-level format as demonstrated at <a href="https://memorynotfound.com/convert-image-black-white-java/" rel="nofollow noreferrer">https://memorynotfound.com/convert-image-black-white-java/</a></p>
  
  <p>Code:</p>
  
  <pre><code>using Images, ImageView;
  
  function save_as_binary_image(img_path::String, threshold::Float16)
      img_binary = load(img_path);
      img_binary = (Gray.(img_binary) .&gt; threshold);
      imshow(img_binary);
      typeof(img_binary);#=&gt;BitArray{2}
      save("/path/to/dest/image.png", img_binary);
      img_saved = load("/path/to/dest/image.png");
      imshow(img_saved);
      typeof(img_saved);#=&gt;Array{Gray{Normed{UInt8,8}},2}
  end
  
  save_as_binary_image("/path/to/image/file", convert(Float16, 0.5));
  </code></pre>
  
  <p>It saves as image of depth 8 but not of depth 1.</p>
  
  <p>Please guide me in saving bi-level image to file!</p>