def test_compare_autolevels(): # compare autolevel and percentile autolevel with p0=0.0 and p1=1.0 # should returns the same arrays image = data.camera() selem = disk(20) loc_autolevel = rank.autolevel(image, selem=selem) loc_perc_autolevel = rank.percentile_autolevel(image, selem=selem, p0=.0, p1=1.) assert_array_equal(loc_autolevel, loc_perc_autolevel)
def test_compare_autolevels_16bit(): # compare autolevel(16-bit) and percentile autolevel(16-bit) with p0=0.0 and # p1=1.0 should returns the same arrays image = data.camera().astype(np.uint16) * 4 selem = disk(20) loc_autolevel = rank.autolevel(image, selem=selem) loc_perc_autolevel = rank.percentile_autolevel(image, selem=selem, p0=.0, p1=1.) assert_array_equal(loc_autolevel, loc_perc_autolevel)
def test_compare_autolevels_16bit(): # compare autolevel(16-bit) and percentile autolevel(16-bit) with p0=0.0 # and p1=1.0 should returns the same arrays image = data.camera().astype(np.uint16) * 4 selem = disk(20) loc_autolevel = rank.autolevel(image, selem=selem) loc_perc_autolevel = rank.autolevel_percentile(image, selem=selem, p0=.0, p1=1.) assert_array_equal(loc_autolevel, loc_perc_autolevel)
def test_compare_autolevels(): # compare autolevel and percentile autolevel with p0=0.0 and p1=1.0 # should returns the same arrays image = util.img_as_ubyte(data.camera()) selem = disk(20) loc_autolevel = rank.autolevel(image, selem=selem) loc_perc_autolevel = rank.autolevel_percentile(image, selem=selem, p0=.0, p1=1.) assert_array_equal(loc_autolevel, loc_perc_autolevel)
.. image:: PLOT2RST.current_figure another way to maximize the number of greylevels used for an image is to apply a local autoleveling, i.e. here a pixel greylevel is proportionally remapped between local minimum and local maximum. The following example shows how local autolevel enhances the camara man picture. """ from skimage.filter.rank import autolevel ima = data.camera() selem = disk(10) auto = autolevel(ima.astype(np.uint16), disk(20)) # display results fig = plt.figure(figsize=[10, 7]) plt.subplot(1, 2, 1) plt.imshow(ima, cmap=plt.cm.gray) plt.xlabel('original') plt.subplot(1, 2, 2) plt.imshow(auto, cmap=plt.cm.gray) plt.xlabel('local autolevel') """ .. image:: PLOT2RST.current_figure This filter is very sensitive to local outlayers, see the little white spot in the sky left part. This is due to a local maximum which is very high comparing
.. image:: PLOT2RST.current_figure another way to maximize the number of greylevels used for an image is to apply a local autoleveling, i.e. here a pixel greylevel is proportionally remapped between local minimum and local maximum. The following example shows how local autolevel enhances the camara man picture. """ from skimage.filter.rank import autolevel ima = data.camera() selem = disk(10) auto = autolevel(ima.astype(np.uint16), disk(20)) # display results fig = plt.figure(figsize=[10, 7]) plt.subplot(1, 2, 1) plt.imshow(ima, cmap=plt.cm.gray) plt.xlabel('original') plt.subplot(1, 2, 2) plt.imshow(auto, cmap=plt.cm.gray) plt.xlabel('local autolevel') """ .. image:: PLOT2RST.current_figure This filter is very sensitive to local outlayers, see the little white spot in
def autolevel(image, disk_size): return rank.autolevel(image, disk(disk_size))
glob_hist = np.histogram(glob, bins=np.arange(0, 256)) loc_hist = np.histogram(loc, bins=np.arange(0, 256)) fig, ax = plt.subplots(4, 2, figsize=(10, 10)) fig.suptitle('George O. Barros - Alguns Filtros (scikit-image)') ax1, ax2, ax3, ax4, ax5, ax6, ax7, ax8 = ax.ravel() ax1.imshow(noisy_image, interpolation='nearest', cmap=plt.cm.gray) ax1.set_title('imagens') ax1.axis('off') ax2.plot(hist[1][:-1], hist[0], lw=2) ax2.set_title('Histogram') ax3.imshow(glob, interpolation='nearest', cmap=plt.cm.gray) ax3.axis('off') ax4.plot(glob_hist[1][:-1], glob_hist[0], lw=2) ax5.imshow(loc, interpolation='nearest', cmap=plt.cm.gray) ax5.axis('off') ax6.plot(loc_hist[1][:-1], loc_hist[0], lw=2) auto = autolevel(noisy_image.astype(np.uint16), disk(20)) ax7.imshow(auto, cmap=plt.cm.gray) ax7.axis('off') histAutoLevel= np.histogram(auto, bins=np.arange(0, 256)) ax8.plot(histAutoLevel[1][:-1], histAutoLevel[0], lw=2) plt.show()