title: raw image display in qt with python
body: <p>I'm using a python program to acquire an image from a scientific camera. This part is okay, I can get the 16 bits image in an array. The problem comes when I want to display the image in the qt window (I'm using a QGraphicsWindow), the way the image is displayed is very strange. To display the image, I convert the 2d array to a pixmap which is then dislpayed. I tried different things but the best results are obtained for the following codes :</p>
  
  <pre><code>def array2Pixmap(arr):
  arr_uint8 = arr.view(dtype=numpy.uint8)
  im8 = Image.fromarray(arr_uint8)
  imQt = QtGui.QImage(ImageQt.ImageQt(im8))
  pix = QtGui.QPixmap.fromImage(imQt)
  return pix
  </code></pre>
  
  <p>which gives the following result :<a href="https://i.stack.imgur.com/pgNNe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pgNNe.png" alt="enter image description here"></a></p>
  
  <p>and this one:</p>
  
  <pre><code>def array2Pixmap(arr):
  arr_uint8 = arr.astype(numpy.uint8)
  im8 = Image.fromarray(arr_uint8)
  imQt = QtGui.QImage(ImageQt.ImageQt(im8))
  pix = QtGui.QPixmap.fromImage(imQt)
  return pix
  </code></pre>
  
  <p>which gives this for the exact same capture conditions (camera exposure time, light intensity, etc ...):
  <a href="https://i.stack.imgur.com/UHAQ5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UHAQ5.png" alt="enter image description here"></a></p>
  
  <p>So now I'm looking for a way to display the image the correct way. Do you have any idea of what I'm doing wrong ?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is an exemple of what is the arr. The command <code>print(arr)</code> returns </p>
  
  <pre><code>[[100  94  94 ...  97  98  98]
  [ 97 100  98 ...  98 101  99]
  [100  95  98 ... 104  98 102]
  ...
  [ 98  98  98 ...  96  98 100]
  [ 94 100 102 ...  92  98 104]
  [ 97  90  96 ...  96  97 100]]
  </code></pre>
  
  <p>and a <code>print(type(arr))</code> returns </p>
  
  <pre><code>&lt;class 'numpy.ndarray'&gt;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok I have some news.
  I changed my code so that now the conversion to 8 bits array id done like this :</p>
  
  <pre><code>arr = numpy.around(arr*(2^8-1)/(2^16-1))
  arr_uint8 = arr.astype(numpy.uint8)
  </code></pre>
  
  <p>If I display the image using <code>matplotlib.pyplot.imshow(arr, cmap='gray')</code> it works and the image is diplayed like this in the editor :</p>
  
  <p><a href="https://i.stack.imgur.com/5bqM2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5bqM2.png" alt="enter image description here"></a></p>
  
  <p>but when I convert it into a QPixmap, the result is the same as before.</p>
  
  <p>What is strange is that when I use <code>arr_uint8 = arr.view(dtype=numpy.uint8)</code> to convert to 8-bits, the result is an array of 2048*4096 instead of 2048*2048. I don't understand why...</p>