0

I have a basic program that simply loads an image and prints it in the matplot. I am equalizing this image by the method in "histeq" (I am aware of the skimage functions), and when I run it it gives the following "TypeError: Image data can not convert to float"

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, called Dualistic Sub-Image Histogram Equalization (DSIHE). Basically means that it will separete the image by the histogram, and make a equalization in both parts. The result is the union of the both parts.

Anyway, this error is similar to the big code, so I am just posting this one just for the sake of example. The console shows: Error message

4
  • Hello Hirosam, welcome to StackOverflow. Please specify what the "tittle message" is? If it's some error message, please provide its text. Also, it's better to specify the used function instead of writing "by one method". The clearer you make your question, the easier it is for others to provide helpful answers. Best regards. Commented Jun 14, 2016 at 0:14
  • Thank you for the feedback, and I appreciate the correction. Commented Jun 14, 2016 at 0:30
  • By the way, have you figured on which line does the error occur? Commented Jun 15, 2016 at 17:39
  • I edit it by posting the console message. Commented Jun 17, 2016 at 16:29

0

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.