title: Python: Displaying a binary array as image
body: <p>I have a mask image which is technically a matrix full of True/False values. I would like to view this as an image. First, I converted it into a binary array with (<code>astype(np.uint8)</code>) </p>
  
  <pre><code>print('Part Mask', p['masks'][class_id].astype(np.uint8))
  </code></pre>
  
  <p>but I still can't view it as an image under Python notebook. OpenCV goes crazy and crashes the kernel. </p>
  
  <p>Does anyone know how to view such a structure as an image on Python notebook without crashing the kernel?</p>
  
  <pre><code>    [[0 0 0 ... 0 0 0]
       [0 0 0 ... 0 0 0]
       [0 0 0 ... 0 0 0]
       ...
       [0 0 0 ... 0 0 0]
       [0 0 0 ... 0 0 0]
       [0 0 0 ... 0 0 0]]
  </code></pre>
  
  <p>or this would work as well ():</p>
  
  <pre><code>[[False False False ... False False False]
   [False False False ... False False False]
   [False False False ... False False False]
   ...
   [False False False ... False False False]
   [False False False ... False False False]
   [False False False ... False False False]]
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: I cannot copy paste the whole code here but basically I have a prediction tensor <code>p</code>, and <code>p[masks][class_id]</code> is what I want to visualize (showing the mask of each class).</p>
  
  <pre><code>enumerator = 0
  # run through the instances
  for class_id in p['class_ids']:
      #print('Image:', image) # the original input image
      #print('Mask:', merged_mask) # whole masked image
      print('ID: ', class_names[class_id] + str(enumerator))
      #print('Outline Poses: ', ) # mask boundary coordinates
      #print('Pose:',) # mask center coordinates
      print('Part Mask', p['masks'][class_id].astype(np.uint8)) # how to visualize this as an image?
      print('Confidence: ', p['scores'][class_id])
      print('BB: ', p['rois'][class_id]) # get the BB
      print('--------------------------')
      enumerator = enumerator + 1
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/CVb1h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CVb1h.png" alt="enter image description here"></a></p>
  
  <p>P.S: Matplotlib does not work either. This is the kind of image I get when I try to print:</p>
  
  <p><a href="https://i.stack.imgur.com/4cKhQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4cKhQ.png" alt="enter image description here"></a></p>