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