mercredi 15 juin 2016

TypeError: Image data can not convert to float using matplotlib

I have a basic program, that simply loads a image, and print it in the matplot. I am equalizing this image by one method ( I am aware of the skimage functions), and when I run it it gives the tittle message

import matplotlib
import matplotlib.pyplot as plt
from numpy import histogram, cumsum, interp, array
import numpy as np
from PIL import Image
from skimage import data, img_as_float
from skimage import exposure

def histeq(im,nbr_bins=256):

   #get image histogram
   imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
   cdf = imhist.cumsum() #cumulative distribution function
   cdf = 255 * cdf / cdf[-1] #normalize

   #use linear interpolation of cdf to find new pixel values
   im2 = interp(im.flatten(),bins[:-1],cdf)
   print(cdf.size)
   return im2.reshape(im.shape), cdf

fig = plt.figure(figsize=(8, 5))

img = array (Image.open('AquaTermi_lowcontrast.jpg').convert('L'))

img = histeq(img)

#img = img_as_float(img)

axes_img = fig.add_subplot(2, 2, 2)
axes_img.set_axis_off()
axes_img.imshow(img, cmap=plt.cm.gray=-)


plt.show()

The reason i don`t use the skimage tools, is because i am doing a specific equalization, of sub-image. Anyway, this error is similar to the big code, so I am just posting this one just for the sake of example.

Aucun commentaire:

Enregistrer un commentaire