aditya9211/Blur-and-Clear-Classification

Runtime Error: array type not supported...

vdsprakash opened this issue ยท 7 comments

combined_img = nd.median_filter(combined_img,radius)

Hi,

Can you check the shape & type of combined_img shape when concatenated?
As this clear the shape and type of combined_img variable.

code snippet

## Concatenate the array of Good & Bad images
combined_img = np.concatenate((good_img, bad_img))  
labels = np.concatenate((np.ones(good_img.shape[0]), 
                        np.zeros(bad_img.shape[0])))

## Filtering the combined images to Reduce the Noise present
combined_img = nd.median_filter(combined_img, radius)

As I got no response, so closing this issue
And I tested the code it is working fine!!

mnutt commented

I'm running into the same issue, on both python 2.7.15 and python 3.7. I see that combined_img is an array of all of the images, read from ms.imread. But from what I can tell, my nd.median_filter() only expects to receive a single image, rather than an array of images?

I'm also running into the same problem.

Pre-Processsing the Data...........

Traceback (most recent call last):
  File "train.py", line 564, in <module>
    main()
  File "train.py", line 515, in main
    imgs, labels = data_preprocess(GOOD_IMG_PATH, BAD_IMG_PATH, radius=RADIUS)
  File "train.py", line 74, in data_preprocess
    combined_img = nd.median_filter(combined_img, radius)
  File "/home/claudio/.local/lib/python2.7/site-packages/scipy/ndimage/filters.py", line 1309, in median_filter
    origin, 'median')
  File "/home/claudio/.local/lib/python2.7/site-packages/scipy/ndimage/filters.py", line 1230, in _rank_filter
    origins)
RuntimeError: array type not supported

EDIT: Solved it by making sure input images were all the same size.

I'm running into the same issue, on both python 2.7.15 and python 3.7. I see that combined_img is an array of all of the images, read from ms.imread. But from what I can tell, my nd.median_filter() only expects to receive a single image, rather than an array of images?

@mnutt Can you check that if the shape/size of all input images is the same.

please try this code, it will resize all the images before feeding it to the code

# Here PIL is Python Imaging Library is a free library for the Python programming language, install it by the following command  
# pip install Pillow 
from PIL import Image
import os, sys

# define your images directory here 
path = "bad_images/"
dirs = os.listdir( path )

def resize():
    for item in dirs:
        if os.path.isfile(path+item):
            im = Image.open(path+item)
            f, e = os.path.splitext(path+item)
           # here 400x400 is resolution you can change it according to your requirement
            imResize = im.resize((400,400), Image.ANTIALIAS)
            imResize.save(f + '.jpg', 'JPEG', quality=90)
            
resize()

You can solve this issue by resizing the image in the data_preprocess() function in train.py. Just add the following code snippet in both the for loops (taking care of good and bad images path) for reading images from directory:

for filename in os.listdir(GOOD_IMG_PATH):            
      image_read = ms.imread(GOOD_IMG_PATH+filename, mode='L')    # for reading file and converting it into grayscale
      image_resize = ms.imresize(image_read, (400, 400))   # resizing the image. You can choose any pixel dimension
      good_img.append(image_resize)   # appending the information to the list
good_img = np.asarray(good_img)      # converting it into array
print("good image array: ",good_img.shape)     

I hope this solves the problem.