title: Converting normalised CIELAB image tensor to RGB image
body: <p>I trained an image to image translation model on pytorch and the input and output images are in CIELAB color space. How do I convert this to an RGB image? Simply converting the image causes some sort of clipping and produces white patches.</p>
  
  <pre><code>out=model.forward(x)
  out=torch.squeeze(out)
  out=out.permute(1,2,0)
  out=torch.from_numpy(out.data.numpy())
  plt.imshow(out)
  </code></pre>
  
  <p>This doesn't produce white patches however I cant use OpenCV and convert it to RGB as the values are in range 0-1. </p>
  
  <p><a href="https://i.stack.imgur.com/wkXZS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wkXZS.png" alt="CIELAB image in 0-1 range"></a></p>
  
  <p>Now if I convert the tensor to a PIL image and then convert to RGB(0-255) some sort of clipping occurs and produces white patches which are even visible before converting to RGB</p>
  
  <pre><code>out=model.forward(x)
  out=torch.squeeze(out)
  out=np.asarray(transforms.ToPILImage()(out))
  plt.imshow(out)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/uNgCA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uNgCA.png" alt="CIELAB with white patches"></a></p>
  
  <p>The white patches after using <code>out=cv2.cvtColor(out, cv2.COLOR_LAB2RGB)</code> to convert</p>
  
  <p><a href="https://i.stack.imgur.com/ZIHBt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZIHBt.png" alt="White patches in RGB"></a></p>
  
  <p>How can I properly convert the CIELAB image to RGB?</p>