title: Why are width and height of an image are inverted when loading using PIL versus OpenCV?
body: <p>I am loading an <a href="https://i2.wp.com/kernut.com/wp-content/uploads/2017/04/20170217_162840.jpg?resize=1360%2C765" rel="nofollow noreferrer">image</a> using <em>PIL</em> and <em>OpenCV</em> packages. The height and width are reversed when loading the image using <code>PIL</code> versus when loading using <code>cv2</code>. Following is the code to print height and width of the image loaded using both the packages.</p>
  <pre class="lang-py prettyprint-override"><code>file = 'conceptual_captions/VL-BERT/data/conceptual-captions/val_image/00002725.jpg'
  # load image using PIL
  import PIL.Image
  pil = PIL.Image.open(file).convert('RGB')
  w, h = pil.size
  print(&quot;width: {}, height: {}&quot;.format(w, h))
  </code></pre>
  <p>Print output
  <code>width: 1360, height: 765</code></p>
  <pre class="lang-py prettyprint-override"><code># now using cv2
  import cv2
  im = cv2.imread(file)
  print(&quot;height, width, channels: {}&quot;.format(im.shape)) 
  </code></pre>
  <p>print output <code>height, width, channels: (1360, 765, 3)</code></p>
  <p>I downloaded the image and checked the size of the image using info option on Mac. Info has <code>width = 765</code> and <code>height = 1360</code>, which is same as reported by <code>cv2</code> method. Why is <code>PIL</code> giving wrong image dimensions?</p>
  <p>The problem occurs with very few images. The image I have linked is one such image. For rest of the images, the height and width reported by <code>PIL</code> and <code>cv2</code> are the same.</p>