Esempio n. 1
0
The equalized image [2]_ has a roughly linear cumulative distribution function
for each pixel neighborhood. The local version [3]_ of the histogram
equalization emphasizes every local greylevel variations.

.. [2] http://en.wikipedia.org/wiki/Histogram_equalization
.. [3] http://en.wikipedia.org/wiki/Adaptive_histogram_equalization

"""

from skimage import exposure
from skimage.filter import rank

ima = data.camera()
# equalize globally and locally
glob = exposure.equalize(ima) * 255
loc = rank.equalize(ima, disk(20))

# extract histogram for each image
hist = np.histogram(ima, bins=np.arange(0, 256))
glob_hist = np.histogram(glob, bins=np.arange(0, 256))
loc_hist = np.histogram(loc, bins=np.arange(0, 256))

plt.figure(figsize=(10, 10))
plt.subplot(321)
plt.imshow(ima, cmap=plt.cm.gray, interpolation='nearest')
plt.axis('off')
plt.subplot(322)
plt.plot(hist[1][:-1], hist[0], lw=2)
plt.title('histogram of grey values')
plt.subplot(323)
plt.imshow(glob, cmap=plt.cm.gray, interpolation='nearest')
Esempio n. 2
0
    ax_cdf.plot(bins, img_cdf, 'r')

    return ax_img, ax_hist, ax_cdf


# Load an example image
img = img_as_ubyte(data.moon())

# Contrast stretching
p2 = np.percentile(img, 2)
p98 = np.percentile(img, 98)
img_rescale = exposure.equalize_hist(img)

# Equalization
selem = disk(30)
img_eq = rank.equalize(img, selem=selem)


# Display results
f, axes = plt.subplots(2, 3, figsize=(8, 4))

ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0])
ax_img.set_title('Low contrast image')
ax_hist.set_ylabel('Number of pixels')

ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_rescale, axes[:, 1])
ax_img.set_title('Global equalise')

ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_eq, axes[:, 2])
ax_img.set_title('Local equalize')
ax_cdf.set_ylabel('Fraction of total intensity')
    # Display cumulative distribution
    img_cdf, bins = exposure.cumulative_distribution(img, bins)
    ax_cdf.plot(bins, img_cdf, "r")

    return ax_img, ax_hist, ax_cdf


# Load an example image
img = img_as_ubyte(data.moon())

# Global equalize
img_rescale = exposure.equalize_hist(img)

# Equalization
selem = disk(30)
img_eq = rank.equalize(img, selem=selem)


# Display results
f, axes = plt.subplots(2, 3, figsize=(8, 5))

ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0])
ax_img.set_title("Low contrast image")
ax_hist.set_ylabel("Number of pixels")

ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_rescale, axes[:, 1])
ax_img.set_title("Global equalise")

ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_eq, axes[:, 2])
ax_img.set_title("Local equalize")
ax_cdf.set_ylabel("Fraction of total intensity")
for each pixel neighborhood. The local version [3]_ of the histogram
equalization emphasizes every local gray-level variations.

.. [2] http://en.wikipedia.org/wiki/Histogram_equalization
.. [3] http://en.wikipedia.org/wiki/Adaptive_histogram_equalization

"""

from skimage import exposure
from skimage.filter import rank

noisy_image = img_as_ubyte(data.camera())

# equalize globally and locally
glob = exposure.equalize(noisy_image) * 255
loc = rank.equalize(noisy_image, disk(20))

# extract histogram for each image
hist = np.histogram(noisy_image, bins=np.arange(0, 256))
glob_hist = np.histogram(glob, bins=np.arange(0, 256))
loc_hist = np.histogram(loc, bins=np.arange(0, 256))

plt.figure(figsize=(10, 10))

plt.subplot(321)
plt.imshow(noisy_image, interpolation='nearest')
plt.axis('off')

plt.subplot(322)
plt.plot(hist[1][:-1], hist[0], lw=2)
plt.title('Histogram of gray values')
The equalized image [2]_ has a roughly linear cumulative distribution function
for each pixel neighborhood. The local version [3]_ of the histogram
equalization emphasizes every local greylevel variations.

.. [2] http://en.wikipedia.org/wiki/Histogram_equalization
.. [3] http://en.wikipedia.org/wiki/Adaptive_histogram_equalization

"""

from skimage import exposure
from skimage.filter import rank

ima = data.camera()
# equalize globally and locally
glob = exposure.equalize(ima) * 255
loc = rank.equalize(ima, disk(20))

# extract histogram for each image
hist = np.histogram(ima, bins=np.arange(0, 256))
glob_hist = np.histogram(glob, bins=np.arange(0, 256))
loc_hist = np.histogram(loc, bins=np.arange(0, 256))

plt.figure(figsize=(10, 10))
plt.subplot(321)
plt.imshow(ima, cmap=plt.cm.gray, interpolation='nearest')
plt.axis('off')
plt.subplot(322)
plt.plot(hist[1][:-1], hist[0], lw=2)
plt.title('histogram of grey values')
plt.subplot(323)
plt.imshow(glob, cmap=plt.cm.gray, interpolation='nearest')
#load the image
image = nh.getImage(image_source)
image = nh.RGBtoGray(image)
image = image.astype(np.uint8)

#blur image to get rid of most of the noise
blur_kernel = (blur, blur)
image = cv2.blur(image, blur_kernel)

#image = np.where(image > 100, 255,1)

#image = threshold_adaptive(image, 21,offset=0)

#perform local histogram equalization to emphasize edges
selem = disk(histogram_equalization)
image_eq = rank.equalize(image, selem=selem)

#add half of the processed and half of the original image to further separate
#regions where there is structure from the background
image = ratio * image_eq + (1 - ratio) * image

#find a favorable threshold using otsu thresholding and modify it by t_mod
threshold = nh.otsuThreshold(image) - offset

#threshold and save image
image = np.where(image > threshold, 1.0, 0.0)
image = np.where(image > 0, 0, 1)
#image = opening(image,disk(3))
#image = closing(image,disk(4))

image = remove_small_objects(image.astype(bool),\
for each pixel neighborhood. The local version [3]_ of the histogram
equalization emphasizes every local gray-level variations.

.. [2] http://en.wikipedia.org/wiki/Histogram_equalization
.. [3] http://en.wikipedia.org/wiki/Adaptive_histogram_equalization

"""

from skimage import exposure
from skimage.filter import rank

noisy_image = img_as_ubyte(data.camera())

# equalize globally and locally
glob = exposure.equalize(noisy_image) * 255
loc = rank.equalize(noisy_image, disk(20))

# extract histogram for each image
hist = np.histogram(noisy_image, bins=np.arange(0, 256))
glob_hist = np.histogram(glob, bins=np.arange(0, 256))
loc_hist = np.histogram(loc, bins=np.arange(0, 256))

plt.figure(figsize=(10, 10))

plt.subplot(321)
plt.imshow(noisy_image, interpolation='nearest')
plt.axis('off')

plt.subplot(322)
plt.plot(hist[1][:-1], hist[0], lw=2)
plt.title('Histogram of gray values')
image = nh.getImage(image_source)
image = nh.RGBtoGray(image)
image = image.astype(np.uint8)
					
#blur image to get rid of most of the noise
blur_kernel = (blur,blur)
image = cv2.blur(image, blur_kernel)

#image = np.where(image > 100, 255,1)

#image = threshold_adaptive(image, 21,offset=0)


#perform local histogram equalization to emphasize edges
selem = disk(histogram_equalization)
image_eq = rank.equalize(image, selem=selem)

#add half of the processed and half of the original image to further separate
#regions where there is structure from the background
image = ratio*image_eq + (1-ratio)*image


#find a favorable threshold using otsu thresholding and modify it by t_mod
threshold = nh.otsuThreshold(image)-offset

#threshold and save image
image = np.where(image > threshold,1.0,0.0)
image = np.where(image > 0,0,1)
#image = opening(image,disk(3))
#image = closing(image,disk(4))