skidjoe
skidjoe

Reputation: 659

How to deal with different types of images for image classification (Black & White & RGB) ImageNet

I'm trying to perform classification on some images from Tiny ImageNet dataset. I'm creating a training dataset and test dataset where the features are the numpy representation of the image. However, it seems like there are RGB images which are of shape (64x64x3) and black & white images which are only one channel (64x64); so I can't simply flatten the collection of images into a 1d array as they give different sizes. What's the standard way of dealing with this discrepancy? Do I pad with 0's?

Upvotes: 0

Views: 544

Answers (1)

code-lukas
code-lukas

Reputation: 1651

Two simple approaches come to mind:

  1. You can either convert all RGB images to grayscale
  2. You can also convert all grayscale images to RGB

You then have a uniform shape for your input.

In any case, OpenCV can handle both operations using cv2.cvtColor() and either cv2.COLOR_RGB2GRAY or cv2.COLOR_GRAY2RGB.

I'm certain there are more complex ways to represent an image independent of its color space, but I'd start with either of the two above.

Edit: Bear in mind that if you convert a RGB image to grayscale and then back to RGB that they will differ. However, if you plan on using image augmentation there's a good chance it won't impact the model too much.

Upvotes: 1

Related Questions