I am trying to create a 16-bit image like so:
import skimage
import random
from random import randint
xrow=raw_input("Enter the
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
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()
Try this
plt.imshow(im.reshape(im.shape[0], im.shape[1]), cmap=plt.cm.Greys)
It would help in some cases.
From what I understand of the scikit-image docs (http://scikit-image.org/docs/dev/index.html), imshow() takes a ndarray as an argument, and not a dictionary:
http://scikit-image.org/docs/dev/api/skimage.io.html?highlight=imshow#skimage.io.imshow
Maybe if you post the whole stack trace, we could see that the TypeError comes somewhere deep from imshow().
First read the image as an array
image = plt.imread(//image_path)
plt.imshow(image)
The error occurred when I unknowingly tried plotting the image path instead of the image.
My code :
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)
Correction:
img = cv.imread("fitting.png")
--->THIS IS THE RIGHT USAGE"