3

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?

Alex
  • 159
  • 3
  • 16

2 Answers2

3

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

Alex
  • 159
  • 3
  • 16
1

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.

Grzegorz Bokota
  • 1,736
  • 11
  • 19