Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Image data can not convert to float

I am trying to create a 16-bit image like so:

import skimage  import random from random import randint                         xrow=raw_input("Enter the number of rows to be present in image.=>") row=int(xrow) ycolumn=raw_input("Enter the number of columns to be present in image.=>") column=int(ycolumn)  A={} for x in xrange(1,row):     for y in xrange(1,column):         a=randint(0,65535)         A[x,y]=a   imshow(A) 

But I get the error TypeError: Image data can not convert to float.

like image 391
Shubham Chahal Avatar asked Aug 30 '15 23:08

Shubham Chahal


Video Answer


2 Answers

This question comes up first in the Google search for this type error, but does not have a general answer about the cause of the error. The poster's unique problem was the use of an inappropriate object type as the main argument for plt.imshow(). A more general answer is that plt.imshow() wants an array of floats and if you don't specify a float, numpy, pandas, or whatever else, might infer a different data type somewhere along the line. You can avoid this by specifying a float for the dtype argument is the constructor of the object.

See the Numpy documentation here.

See the Pandas documentation here

like image 79
comet Avatar answered Oct 05 '22 19:10

comet


This happened for me when I was trying to plot an imagePath, instead of the image itself. The fix was to load the image, and plotting it.

like image 41
mastDrinkNimbuPani Avatar answered Oct 05 '22 17:10

mastDrinkNimbuPani