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?

4
  • At which line is the error? Commented Aug 2, 2019 at 6:36
  • @Divakar Line 10, the one where I try to save it Commented Aug 2, 2019 at 6:38
  • Could you put that error against the code where you are getting the error? We can't see line numbers here. Commented Aug 2, 2019 at 6:39
  • @Divakar Hi, just realised the issue was due to the image being converted to binary. Commented Aug 2, 2019 at 6:45

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.