Alex
Alex

Reputation: 159

ValueError: Image is not numeric, but ndarray

I'm trying to save a sci-kit image, but I'm getting the error:

ValueError: Image is not numeric, but ndarray.

Code:

from skimage import *
import skimage.io
import skimage.morphology as morphology

def loadImage(f):
    return skimage.img_as_float(skimage.io.imread(f))

img = img_as_bool(loadImage("images/metric_map_processed.PNG"))

imgSk = morphology.medial_axis(img)
skimage.io.imsave("medial.png", imgSk)

According to the docs, the passed in array should be a ndarray, so why am I getting an error?

Upvotes: 3

Views: 5657

Answers (2)

Grzegorz Bokota
Grzegorz Bokota

Reputation: 1804

The problem is that pixel type in png is uint8. And when you apply img_as_bool you get boolean array. And this mismatch of type generate error.

You need to convert it to uint8. As suggest Alex use img_as_uint function.

Upvotes: 1

Alex
Alex

Reputation: 159

Just realised that my image was being converted to binary

Replacing

skimage.io.imsave("medial.png", imgSk)

with

skimage.io.imsave("medial.png", img_as_uint(imgSk))

worked for me

Upvotes: 3

Related Questions