title: Image resizing problem with Python using Cat and Dog data
body: <p>I'm a newbei at Data Visualization, Machine Learning and Deep Learning topics. I'm trying to improve myself, but I stucked a topic when I try to implement a visualization. </p>
  
  <p>In details, I tried to implement a kernel on 'Kaggle', my data is Cat and Dog images. I have train and test datas. The problem is that my train data has too many pictures that are different size, pixels and shapes. I want to make all of them in a 1 shape type.(For example, I want to make all of the pictures as 64x64 pixels, or 128x128 etc.)</p>
  
  <pre><code>""" I tried different codes to adjust its shapes and create plot:
  I tried to reach 2 goals:
  1. Convert the dog and cat images from RGB to Grayscale
  2. Make all of the images 128x128, or 64x64 """
  
  
  # One of the codes I've tried
  img_size = 128
  basewidth = 128
  for image in tqdm(os.listdir(train_cat)): 
      path = os.path.join(train_cat, image)
      img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
      try:
         wpercent = (basewidth / float(img.size[0]))
         hsize = int((float(img.size[1]) * float(wpercent)))
         img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
      except:
          pass
      np_img=np.asarray(img)
  
  for image2 in tqdm(os.listdir(train_dog)): 
      path = os.path.join(train_dog, image2)
      img2 = cv2.imread(path, cv2.IMREAD_GRAYSCALE) 
      try:
          wpercent = (basewidth / float(img2.size[0]))
          hsize = int((float(img2.size[1]) * float(wpercent)))
          img2 = img2.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
  
      except:
          pass
      np_img2=np.asarray(img2) 
  
  plt.figure(figsize=(10,10))
  plt.subplot(1, 2, 1)
  plt.imshow(np_img.reshape(img_size, img_size))
  plt.axis('off')
  plt.subplot(1, 2, 2)
  plt.imshow(np_img2.reshape(img_size, img_size))
  plt.axis('off')
  
  
  # ---------------------------------------------------------------------
  # Another way:
  
  image_size = 128
  for image in tqdm(os.listdir(train_dog)): 
      path = os.path.join(train_dog, image)
      img = cv2.imread(path, cv2.IMREAD_GRAYSCALE) 
      img = cv2.resize(img, (image_size, image_size)).flatten()   
      np_img=np.asarray(img)
  
  for image2 in tqdm(os.listdir(train_cat)): 
      path = os.path.join(train_cat, image2)
      img2 = cv2.imread(path, cv2.IMREAD_GRAYSCALE) 
      img2 = cv2.resize(img2, (image_size, image_size)).flatten() 
      np_img2=np.asarray(img2)
  
  plt.figure(figsize=(10,10))
  plt.subplot(1, 2, 1)
  plt.imshow(np_img.reshape(image_size, image_size))
  plt.axis('off')
  plt.subplot(1, 2, 2)
  plt.imshow(np_img2.reshape(image_size, image_size))
  plt.axis('off')
  plt.title("Cat and Dogs in GrayScale")
  </code></pre>
  
  <h1>Output for first one</h1>
  
  <pre><code>ValueError         Traceback (most recent call last)
  &lt;ipython-input-47-0984b7467972&gt; in &lt;module&gt;
       28 plt.figure(figsize=(10,10))
       29 plt.subplot(1, 2, 1)
  ---&gt; 30 plt.imshow(np_img.reshape(img_size, img_size))
       31 plt.axis('off')
       32 plt.subplot(1, 2, 2)
  
  
  ValueError: cannot reshape array of size 76964 into shape (300,300)
  </code></pre>
  
  <h1>Output for second one</h1>
  
  <pre><code>error    Traceback (most recent call last)
  &lt;ipython-input-67-99d190c6fd41&gt; in &lt;module&gt;
        4     path = os.path.join(train_dog, image)
        5     img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
  ----&gt; 6     img = cv2.resize(img, (image_size, image_size)).flatten()
        7     np_img=np.asarray(img)
        8 
  
  error: OpenCV(4.1.0) /io/opencv/modules/imgproc/src/resize.cpp:3718:     error: (-215:Assertion failed) !ssize.empty() in function 'resize'
  </code></pre>
  
  <p><strong>As I mentioned above, I tried to make a convertion from RGB to Grayscale, and make the images' size 1 type(128x128 optionally). I believed there is no mistake to convertion but resize is a problem that I can't solve for 2-3 days, eventhough I made tons of researches. I'm not sure but it could be a simple problem, like a said, I'm a beginner for now.</strong> </p>
  
  <p>Note: I added 2 way of codes because there are the codes I understood best. I hope, you can help me, or teach me a new way, thank you in advance :)</p>
  
  <pre><code>#Appendixes:
  </code></pre>
  
  <p><a href="https://www.kaggle.com/tongpython/cat-and-dog" rel="nofollow noreferrer">Cat and Dog Dataset:</a>
  <a href="https://www.kaggle.com/tongpython/cat-and-dog" rel="nofollow noreferrer">https://www.kaggle.com/tongpython/cat-and-dog</a></p>
  
  <p><a href="https://www.kaggle.com/gulsahdemiryurek/image-classification-with-logistic-regression" rel="nofollow noreferrer">The resizes and grayscale codes I've tried to implement are taken from: 
   (In[5])</a> </p>
  
  <p><a href="https://www.kaggle.com/kanncaa1/deep-learning-tutorial-for-beginners" rel="nofollow noreferrer">Base kaggle I'm saw in order to data that has images (In<a href="https://www.kaggle.com/gulsahdemiryurek/image-classification-with-logistic-regression" rel="nofollow noreferrer">2</a>)</a></p>