title: cv2.imwrite changes color when saving from np.array to JPG
body: <p>I am currently working on an edge detection program for a class (concretely I am detecting street lines).</p>
  <p>I read in an image and detect some edges (via hough). The detected edges are then laid onto the original image. In the process, image data is stored as numpy.ndarry.
  At the very end, i want to save the image to disc (as jpg).</p>
  <p>If I write the images to disc via scipy.misc.imsave, everything works fine.
  If I do it via cv2.imwrite, the colors get distorted into a sort of thermal picture.</p>
  <p>I have read several topics on different color channels and necessary scaling / conversion, but I cannot find a solution from numpy.ndarray to .jpg.
  I know that .jpg may only have 8bit or 16bit color channels, but don't know where to go from there. In any case i have blindly tried to divide by 255 (--&gt; image almost black) and multiply by 255 (--&gt; whitish thermal picture :-) ).</p>
  <p>Any ideas? These are the relevant sections of code:</p>
  <p>Reading the image (function is later called in a loop):</p>
  <pre><code>def read(img):
      image = mpimg.imread(img)
      return image
  </code></pre>
  <p>Draw function to be called in a loop to draw all lines defined in an array:</p>
  <pre><code>def draw_lines(img, line_coordinates, color=[255, 0, 0], thickness=4):
      for line in line_coordinates:
          for x1, y1, x2, y2 in line:
              cv2.line(img, (x1, y1), (x2, y2), color, thickness)
  </code></pre>
  <p>This function calls the draw function and returns an image with all lines drawn</p>
  <pre class="lang-py prettyprint-override"><code>def depict_lines(img, array_of_coordinates): 
      line_img = np.zeros((img.shape[0], img.shape[1], 3), dtype=np.uint8)
      draw_lines(line_img, array_of_coordinates)
      return line_img
  </code></pre>
  <p>Next, I combine the original image and the one containing the edges:</p>
  <pre class="lang-py prettyprint-override"><code>def weighted_img(line_img, initial_img, α=0.95, β=1., λ=0.):
      return cv2.addWeighted(initial_img, α, line_img, β, λ)
  
  combined_images = weighted_img(depicted_lines, original_image)
  </code></pre>
  <p>Finally, I save the image to disc. This call produces weird colors:</p>
  <pre class="lang-py prettyprint-override"><code>cv2.imwrite(new_file_name, combined_images)
  </code></pre>
  <p>whereas this one works fine:</p>
  <pre class="lang-py prettyprint-override"><code>scipy.misc.imsave('outfile.jpg', combined_images)
  </code></pre>
  <p>This is an unprocessed image:
  <a href="https://i.stack.imgur.com/vWpwD.jpg" rel="nofollow noreferrer">natural colors</a></p>
  <p>And a processed one:
  <a href="https://i.stack.imgur.com/781dF.jpg" rel="nofollow noreferrer">distorted colors</a></p>
  <p>Your help would be appreciated!</p>