merge entropy examples+add description

This commit is contained in:
odebeir
2015-08-29 13:27:16 +02:00
parent f8afc07d80
commit 35341bed13
2 changed files with 42 additions and 41 deletions
+42 -3
View File
@@ -3,17 +3,56 @@
Entropy
=======
Image entropy is a quantity which is used to describe the amount of information
coded in an image.
In information theory, information entropy is the log-base-2 of the number of possible outcomes
for a message.
For an image, local entropy is related to the complexity contained in a given neighborhood, typically defined by a
structuring element. A large number of various gray levels has a higher entropy than an homogeneous neighborhood.
Entropy filter can detect subtle variations of local gray level distribution, in the example, the
image is composed of two surfaces with two slightly different distributions.
Image center has a random distribution in the range [-14,+14] centered on 128, while the borders has a
random distribution in the range [-15,+15] centered on 128.
We apply the local entropy measure using a circular structuring element of radius 10. As a result, one can
detect the central square. Radius should be big enough to efficiently sample the local gray level distribution.
In the second example, the local entropy is used to detect image texture.
"""
import matplotlib.pyplot as plt
import numpy as np
from skimage import data
from skimage.util import img_as_ubyte
from skimage.filters.rank import entropy
from skimage.morphology import disk
from skimage.util import img_as_ubyte
noise_mask = 28*np.ones((128, 128), dtype=np.uint8)
noise_mask[32:-32, 32:-32] = 30
noise = (noise_mask*np.random.random(noise_mask.shape)-.5*noise_mask).astype(np.uint8)
img = noise + 128
radius = 10
e = entropy(img, disk(radius))
plt.figure(figsize=[15, 5])
plt.subplot(1, 3, 1)
plt.imshow(noise_mask, cmap=plt.cm.gray)
plt.xlabel('noise mask')
plt.colorbar()
plt.subplot(1, 3, 2)
plt.imshow(img, cmap=plt.cm.gray)
plt.xlabel('noised image')
plt.colorbar()
plt.subplot(1, 3, 3)
plt.imshow(e)
plt.xlabel('image local entropy ($r=%d$)' % radius)
plt.colorbar()
#second example: texture detection
image = img_as_ubyte(data.camera())
-38
View File
@@ -1,38 +0,0 @@
"""
=======
Entropy
=======
The following example applies the local entropy measure to a noised image with a variable noise.
"""
import matplotlib.pyplot as plt
import numpy as np
from skimage.filters.rank import entropy
from skimage.morphology import disk
noise_mask = 28*np.ones((128, 128), dtype=np.uint8)
noise_mask[32:-32, 32:-32] = 30
noise = (noise_mask*np.random.random(noise_mask.shape)-.5*noise_mask).astype(np.uint8)
img = noise + 128
radius = 10
e = entropy(img, disk(radius))
plt.figure(figsize=[15, 5])
plt.subplot(1, 3, 1)
plt.imshow(noise_mask, cmap=plt.cm.gray)
plt.xlabel('noise mask')
plt.colorbar()
plt.subplot(1, 3, 2)
plt.imshow(img, cmap=plt.cm.gray)
plt.xlabel('noised image')
plt.colorbar()
plt.subplot(1, 3, 3)
plt.imshow(e)
plt.xlabel('image local entropy ($r=%d$)' % radius)
plt.colorbar()
plt.show()