TypeError: image data cannot be converted to float

I want to create a 16 bit image. So I wrote the code.

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 whenever I run this code, I get the error "TypeError: image data cannot convert to float". Is there any solution for this.

I apologize for the errors in my entry, as this is my first question I asked above.

+21
source share
7 answers

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

See the Numpy documentation here .

See the Pandas documentation here

+20
source

This happened to me when I tried to build imagePath instead of the image itself. Fixed error loading the image and its creation.

+14
source

The error occurred when I, not knowing, tried to build an image path instead of an image.

My code is:

 import cv2 as cv from matplotlib import pyplot as plt import pytesseract from resizeimage import resizeimage img = cv.imread("D:\TemplateMatch\\fitting.png") ------>"THIS IS THE WRONG USAGE" #cv.rectangle(img,(29,2496),(604,2992),(255,0,0),5) plt.imshow(img) 

Bugfix: img = cv.imread("fitting.png") ---> THIS IS THE CORRECT USE "

+3
source

From what I understand in the scikit-image docs ( http://scikit-image.org/docs/dev/index.html ), imshow () takes ndarray as an argument, not a dictionary:

http://scikit-image.org/docs/dev/api/skimage.io.html?highlight=imshow#skimage.io.imshow

Perhaps if you place the entire stack trace, we will see that TypeError is somewhere deep from imshow ().

+2
source

try it

 >>> plt.imshow(im.reshape(im.shape[0], im.shape[1]), cmap=plt.cm.Greys) 
+2
source

try

 import skimage import random from random import randint import numpy as np import matplotlib.pyplot as plt 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 = np.zeros((row,column)) for x in xrange(1, row): for y in xrange(1, column): a = randint(0, 65535) A[x, y] = a plt.imshow(A) plt.show() 
+1
source

Try using this, plt.imshow (numpy.real (A)) plt.show ()

instead of plt.imshow(A)

0
source

All Articles