Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading images in RGB #6

Open
ehofesmann opened this issue Jan 6, 2021 · 0 comments
Open

Reading images in RGB #6

ehofesmann opened this issue Jan 6, 2021 · 0 comments

Comments

@ehofesmann
Copy link

The example from the TF2 Model Zoo inference tutorial notebook loads images in RGB format with:

def load_image_into_numpy_array(path):
  """Load an image from file into a numpy array.

  Puts image into numpy array to feed into tensorflow graph.
  Note that by convention we put it into a numpy array with shape
  (height, width, channels), where channels=3 for RGB.

  Args:
    path: the file path to the image

  Returns:
    uint8 numpy array with shape (img_height, img_width, 3)
  """
  img_data = tf.io.gfile.GFile(path, 'rb').read()
  image = Image.open(BytesIO(img_data))
  (im_width, im_height) = image.size
  return np.array(image.getdata()).reshape(
      (im_height, im_width, 3)).astype(np.uint8)

In this tutorial you just use cv2.imread() which will produce numpy arrays in BGR format.

Not sure if this is has been accounted for and I just missed it but if not then it should be fixed. It should be as easy as adding

img = img[...,::-1]

here

im_height, im_width, _ = img.shape

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant