mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-27 18:25:32 +08:00
DOC: refactor axes with lists
This commit is contained in:
@@ -28,22 +28,22 @@ ihc_hed = rgb2hed(ihc_rgb)
|
||||
|
||||
fig, axes = plt.subplots(2, 2, figsize=(7, 6), sharex=True, sharey=True,
|
||||
subplot_kw={'adjustable': 'box-forced'})
|
||||
ax0, ax1, ax2, ax3 = axes.ravel()
|
||||
ax = axes.ravel()
|
||||
|
||||
ax0.imshow(ihc_rgb)
|
||||
ax0.set_title("Original image")
|
||||
ax[0].imshow(ihc_rgb)
|
||||
ax[0].set_title("Original image")
|
||||
|
||||
ax1.imshow(ihc_hed[:, :, 0], cmap=plt.cm.gray)
|
||||
ax1.set_title("Hematoxylin")
|
||||
ax[1].imshow(ihc_hed[:, :, 0], cmap=plt.cm.gray)
|
||||
ax[1].set_title("Hematoxylin")
|
||||
|
||||
ax2.imshow(ihc_hed[:, :, 1], cmap=plt.cm.gray)
|
||||
ax2.set_title("Eosin")
|
||||
ax[2].imshow(ihc_hed[:, :, 1], cmap=plt.cm.gray)
|
||||
ax[2].set_title("Eosin")
|
||||
|
||||
ax3.imshow(ihc_hed[:, :, 2], cmap=plt.cm.gray)
|
||||
ax3.set_title("DAB")
|
||||
ax[3].imshow(ihc_hed[:, :, 2], cmap=plt.cm.gray)
|
||||
ax[3].set_title("DAB")
|
||||
|
||||
for ax in axes.ravel():
|
||||
ax.axis('off')
|
||||
for a in ax.ravel():
|
||||
a.axis('off')
|
||||
|
||||
fig.tight_layout()
|
||||
|
||||
@@ -61,9 +61,9 @@ d = rescale_intensity(ihc_hed[:, :, 2], out_range=(0, 1))
|
||||
zdh = np.dstack((np.zeros_like(h), d, h))
|
||||
|
||||
fig = plt.figure()
|
||||
ax = plt.subplot(1, 1, 1, sharex=ax0, sharey=ax0, adjustable='box-forced')
|
||||
ax.imshow(zdh)
|
||||
ax.set_title("Stain separated image (rescaled)")
|
||||
ax.axis('off')
|
||||
axis = plt.subplot(1, 1, 1, sharex=ax[0], sharey=ax[0], adjustable='box-forced')
|
||||
axis.imshow(zdh)
|
||||
axis.set_title("Stain separated image (rescaled)")
|
||||
axis.axis('off')
|
||||
plt.show()
|
||||
|
||||
|
||||
@@ -70,22 +70,22 @@ fb2_montage = montage2d(fb2, rescale_intensity=True)
|
||||
|
||||
# --
|
||||
fig, axes = plt.subplots(2, 2, figsize=(7, 6))
|
||||
ax0, ax1, ax2, ax3 = axes.ravel()
|
||||
ax = axes.ravel()
|
||||
|
||||
ax0.imshow(astro, cmap=plt.cm.gray)
|
||||
ax0.set_title("Image (original)")
|
||||
ax[0].imshow(astro, cmap=plt.cm.gray)
|
||||
ax[0].set_title("Image (original)")
|
||||
|
||||
ax1.imshow(fb1_montage, cmap=plt.cm.gray, interpolation='nearest')
|
||||
ax1.set_title("K-means filterbank (codebook)\non original image")
|
||||
ax[1].imshow(fb1_montage, cmap=plt.cm.gray, interpolation='nearest')
|
||||
ax[1].set_title("K-means filterbank (codebook)\non original image")
|
||||
|
||||
ax2.imshow(astro_dog, cmap=plt.cm.gray)
|
||||
ax2.set_title("Image (LGN-like DoG)")
|
||||
ax[2].imshow(astro_dog, cmap=plt.cm.gray)
|
||||
ax[2].set_title("Image (LGN-like DoG)")
|
||||
|
||||
ax3.imshow(fb2_montage, cmap=plt.cm.gray, interpolation='nearest')
|
||||
ax3.set_title("K-means filterbank (codebook)\non LGN-like DoG image")
|
||||
ax[3].imshow(fb2_montage, cmap=plt.cm.gray, interpolation='nearest')
|
||||
ax[3].set_title("K-means filterbank (codebook)\non LGN-like DoG image")
|
||||
|
||||
for ax in axes.ravel():
|
||||
ax.axis('off')
|
||||
for a in ax.ravel():
|
||||
a.axis('off')
|
||||
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
|
||||
@@ -42,23 +42,22 @@ for layer in range(image_defect.shape[-1]):
|
||||
image_result = inpaint.inpaint_biharmonic(image_defect, mask, multichannel=True)
|
||||
|
||||
fig, axes = plt.subplots(ncols=2, nrows=2)
|
||||
ax0, ax1, ax2, ax3 = axes.ravel()
|
||||
ax = axes.ravel()
|
||||
|
||||
ax0.set_title('Original image')
|
||||
ax0.imshow(image_orig)
|
||||
ax0.axis('off')
|
||||
ax[0].set_title('Original image')
|
||||
ax[0].imshow(image_orig)
|
||||
|
||||
ax1.set_title('Mask')
|
||||
ax1.imshow(mask, cmap=plt.cm.gray)
|
||||
ax1.axis('off')
|
||||
ax[1].set_title('Mask')
|
||||
ax[1].imshow(mask, cmap=plt.cm.gray)
|
||||
|
||||
ax2.set_title('Defected image')
|
||||
ax2.imshow(image_defect)
|
||||
ax2.axis('off')
|
||||
ax[2].set_title('Defected image')
|
||||
ax[2].imshow(image_defect)
|
||||
|
||||
ax3.set_title('Inpainted image')
|
||||
ax3.imshow(image_result)
|
||||
ax3.axis('off')
|
||||
ax[3].set_title('Inpainted image')
|
||||
ax[3].imshow(image_result)
|
||||
|
||||
for a in ax:
|
||||
a.axis('off')
|
||||
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
|
||||
@@ -45,26 +45,24 @@ median_view = np.median(flatten_view, axis=2)
|
||||
|
||||
# -- display resampled images
|
||||
fig, axes = plt.subplots(2, 2, figsize=(8, 8), sharex=True, sharey=True)
|
||||
ax0, ax1, ax2, ax3 = axes.ravel()
|
||||
ax = axes.ravel()
|
||||
|
||||
ax0.set_title("Original rescaled with\n spline interpolation (order=3)")
|
||||
l_resized = ndi.zoom(l, 2, order=3)
|
||||
|
||||
ax0.imshow(l_resized, extent=(0, 128, 128, 0), interpolation='nearest',
|
||||
ax[0].set_title("Original rescaled with\n spline interpolation (order=3)")
|
||||
ax[0].imshow(l_resized, extent=(0, 128, 128, 0), interpolation='nearest',
|
||||
cmap=cm.Greys_r)
|
||||
ax0.set_axis_off()
|
||||
|
||||
ax1.set_title("Block view with\n local mean pooling")
|
||||
ax1.imshow(mean_view, interpolation='nearest', cmap=cm.Greys_r)
|
||||
ax1.set_axis_off()
|
||||
ax[1].set_title("Block view with\n local mean pooling")
|
||||
ax[1].imshow(mean_view, interpolation='nearest', cmap=cm.Greys_r)
|
||||
|
||||
ax2.set_title("Block view with\n local max pooling")
|
||||
ax2.imshow(max_view, interpolation='nearest', cmap=cm.Greys_r)
|
||||
ax2.set_axis_off()
|
||||
ax[2].set_title("Block view with\n local max pooling")
|
||||
ax[2].imshow(max_view, interpolation='nearest', cmap=cm.Greys_r)
|
||||
|
||||
ax3.set_title("Block view with\n local median pooling")
|
||||
ax3.imshow(median_view, interpolation='nearest', cmap=cm.Greys_r)
|
||||
ax3.set_axis_off()
|
||||
ax[3].set_title("Block view with\n local median pooling")
|
||||
ax[3].imshow(median_view, interpolation='nearest', cmap=cm.Greys_r)
|
||||
|
||||
for a in ax:
|
||||
a.set_axis_off()
|
||||
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
|
||||
@@ -46,21 +46,23 @@ labels = watershed(gradient, markers)
|
||||
|
||||
# display results
|
||||
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(8, 8), sharex=True, sharey=True, subplot_kw={'adjustable':'box-forced'})
|
||||
axes = axes.ravel()
|
||||
ax0, ax1, ax2, ax3 = axes
|
||||
ax = axes.ravel()
|
||||
|
||||
ax0.imshow(image, cmap=plt.cm.gray, interpolation='nearest')
|
||||
ax0.set_title("Original")
|
||||
ax1.imshow(gradient, cmap=plt.cm.spectral, interpolation='nearest')
|
||||
ax1.set_title("Local Gradient")
|
||||
ax2.imshow(markers, cmap=plt.cm.spectral, interpolation='nearest')
|
||||
ax2.set_title("Markers")
|
||||
ax3.imshow(image, cmap=plt.cm.gray, interpolation='nearest')
|
||||
ax3.imshow(labels, cmap=plt.cm.spectral, interpolation='nearest', alpha=.7)
|
||||
ax3.set_title("Segmented")
|
||||
ax[0].imshow(image, cmap=plt.cm.gray, interpolation='nearest')
|
||||
ax[0].set_title("Original")
|
||||
|
||||
for ax in axes:
|
||||
ax.axis('off')
|
||||
ax[1].imshow(gradient, cmap=plt.cm.spectral, interpolation='nearest')
|
||||
ax[1].set_title("Local Gradient")
|
||||
|
||||
ax[2].imshow(markers, cmap=plt.cm.spectral, interpolation='nearest')
|
||||
ax[2].set_title("Markers")
|
||||
|
||||
ax[3].imshow(image, cmap=plt.cm.gray, interpolation='nearest')
|
||||
ax[3].imshow(labels, cmap=plt.cm.spectral, interpolation='nearest', alpha=.7)
|
||||
ax[3].set_title("Segmented")
|
||||
|
||||
for a in ax:
|
||||
a.axis('off')
|
||||
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
|
||||
@@ -25,22 +25,22 @@ image_max = ndi.maximum_filter(im, size=20, mode='constant')
|
||||
coordinates = peak_local_max(im, min_distance=20)
|
||||
|
||||
# display results
|
||||
fig, ax = plt.subplots(1, 3, figsize=(8, 3), sharex=True, sharey=True,
|
||||
subplot_kw={'adjustable': 'box-forced'})
|
||||
ax1, ax2, ax3 = ax.ravel()
|
||||
ax1.imshow(im, cmap=plt.cm.gray)
|
||||
ax1.axis('off')
|
||||
ax1.set_title('Original')
|
||||
fig, axes = plt.subplots(1, 3, figsize=(8, 3), sharex=True, sharey=True,
|
||||
subplot_kw={'adjustable': 'box-forced'})
|
||||
ax = axes.ravel()
|
||||
ax[0].imshow(im, cmap=plt.cm.gray)
|
||||
ax[0].axis('off')
|
||||
ax[0].set_title('Original')
|
||||
|
||||
ax2.imshow(image_max, cmap=plt.cm.gray)
|
||||
ax2.axis('off')
|
||||
ax2.set_title('Maximum filter')
|
||||
ax[1].imshow(image_max, cmap=plt.cm.gray)
|
||||
ax[1].axis('off')
|
||||
ax[1].set_title('Maximum filter')
|
||||
|
||||
ax3.imshow(im, cmap=plt.cm.gray)
|
||||
ax3.autoscale(False)
|
||||
ax3.plot(coordinates[:, 1], coordinates[:, 0], 'r.')
|
||||
ax3.axis('off')
|
||||
ax3.set_title('Peak local max')
|
||||
ax[2].imshow(im, cmap=plt.cm.gray)
|
||||
ax[2].autoscale(False)
|
||||
ax[2].plot(coordinates[:, 1], coordinates[:, 0], 'r.')
|
||||
ax[2].axis('off')
|
||||
ax[2].set_title('Peak local max')
|
||||
|
||||
fig.tight_layout()
|
||||
|
||||
|
||||
@@ -148,13 +148,15 @@ error = reconstruction_sart - image
|
||||
print('SART (1 iteration) rms reconstruction error: %.3g'
|
||||
% np.sqrt(np.mean(error**2)))
|
||||
|
||||
fig, ax = plt.subplots(2, 2, figsize=(8, 8.5), sharex=True, sharey=True,
|
||||
subplot_kw={'adjustable': 'box-forced'})
|
||||
ax1, ax2, ax3, ax4 = ax.ravel()
|
||||
ax1.set_title("Reconstruction\nSART")
|
||||
ax1.imshow(reconstruction_sart, cmap=plt.cm.Greys_r)
|
||||
ax2.set_title("Reconstruction error\nSART")
|
||||
ax2.imshow(reconstruction_sart - image, cmap=plt.cm.Greys_r, **imkwargs)
|
||||
fig, axes = plt.subplots(2, 2, figsize=(8, 8.5), sharex=True, sharey=True,
|
||||
subplot_kw={'adjustable': 'box-forced'})
|
||||
ax = axes.ravel()
|
||||
|
||||
ax[0].set_title("Reconstruction\nSART")
|
||||
ax[0].imshow(reconstruction_sart, cmap=plt.cm.Greys_r)
|
||||
|
||||
ax[1].set_title("Reconstruction error\nSART")
|
||||
ax[1].imshow(reconstruction_sart - image, cmap=plt.cm.Greys_r, **imkwargs)
|
||||
|
||||
# Run a second iteration of SART by supplying the reconstruction
|
||||
# from the first iteration as an initial estimate
|
||||
@@ -164,10 +166,11 @@ error = reconstruction_sart2 - image
|
||||
print('SART (2 iterations) rms reconstruction error: %.3g'
|
||||
% np.sqrt(np.mean(error**2)))
|
||||
|
||||
ax3.set_title("Reconstruction\nSART, 2 iterations")
|
||||
ax3.imshow(reconstruction_sart2, cmap=plt.cm.Greys_r)
|
||||
ax4.set_title("Reconstruction error\nSART, 2 iterations")
|
||||
ax4.imshow(reconstruction_sart2 - image, cmap=plt.cm.Greys_r, **imkwargs)
|
||||
ax[2].set_title("Reconstruction\nSART, 2 iterations")
|
||||
ax[2].imshow(reconstruction_sart2, cmap=plt.cm.Greys_r)
|
||||
|
||||
ax[3].set_title("Reconstruction error\nSART, 2 iterations")
|
||||
ax[3].imshow(reconstruction_sart2 - image, cmap=plt.cm.Greys_r, **imkwargs)
|
||||
plt.show()
|
||||
|
||||
######################################################################
|
||||
|
||||
@@ -67,30 +67,30 @@ noisy_image = img_as_ubyte(data.camera())
|
||||
noisy_image[noise > 0.99] = 255
|
||||
noisy_image[noise < 0.01] = 0
|
||||
|
||||
fig, ax = plt.subplots(2, 2, figsize=(10, 7), sharex=True, sharey=True)
|
||||
ax1, ax2, ax3, ax4 = ax.ravel()
|
||||
fig, axes = plt.subplots(2, 2, figsize=(10, 7), sharex=True, sharey=True)
|
||||
ax = axes.ravel()
|
||||
|
||||
ax1.imshow(noisy_image, vmin=0, vmax=255, cmap=plt.cm.gray)
|
||||
ax1.set_title('Noisy image')
|
||||
ax1.axis('off')
|
||||
ax1.set_adjustable('box-forced')
|
||||
ax[0].imshow(noisy_image, vmin=0, vmax=255, cmap=plt.cm.gray)
|
||||
ax[0].set_title('Noisy image')
|
||||
ax[0].axis('off')
|
||||
ax[0].set_adjustable('box-forced')
|
||||
|
||||
ax2.imshow(median(noisy_image, disk(1)), vmin=0, vmax=255, cmap=plt.cm.gray)
|
||||
ax2.set_title('Median $r=1$')
|
||||
ax2.axis('off')
|
||||
ax2.set_adjustable('box-forced')
|
||||
ax[1].imshow(median(noisy_image, disk(1)), vmin=0, vmax=255, cmap=plt.cm.gray)
|
||||
ax[1].set_title('Median $r=1$')
|
||||
ax[1].axis('off')
|
||||
ax[1].set_adjustable('box-forced')
|
||||
|
||||
|
||||
ax3.imshow(median(noisy_image, disk(5)), vmin=0, vmax=255, cmap=plt.cm.gray)
|
||||
ax3.set_title('Median $r=5$')
|
||||
ax3.axis('off')
|
||||
ax3.set_adjustable('box-forced')
|
||||
ax[2].imshow(median(noisy_image, disk(5)), vmin=0, vmax=255, cmap=plt.cm.gray)
|
||||
ax[2].set_title('Median $r=5$')
|
||||
ax[2].axis('off')
|
||||
ax[2].set_adjustable('box-forced')
|
||||
|
||||
|
||||
ax4.imshow(median(noisy_image, disk(20)), vmin=0, vmax=255, cmap=plt.cm.gray)
|
||||
ax4.set_title('Median $r=20$')
|
||||
ax4.axis('off')
|
||||
ax4.set_adjustable('box-forced')
|
||||
ax[3].imshow(median(noisy_image, disk(20)), vmin=0, vmax=255, cmap=plt.cm.gray)
|
||||
ax[3].set_title('Median $r=20$')
|
||||
ax[3].axis('off')
|
||||
ax[3].set_adjustable('box-forced')
|
||||
|
||||
|
||||
######################################################################
|
||||
@@ -142,26 +142,26 @@ noisy_image = img_as_ubyte(data.camera())
|
||||
|
||||
bilat = mean_bilateral(noisy_image.astype(np.uint16), disk(20), s0=10, s1=10)
|
||||
|
||||
fig, ax = plt.subplots(2, 2, figsize=(10, 7), sharex='row', sharey='row')
|
||||
ax1, ax2, ax3, ax4 = ax.ravel()
|
||||
fig, axes = plt.subplots(2, 2, figsize=(10, 7), sharex='row', sharey='row')
|
||||
ax = axes.ravel()
|
||||
|
||||
ax1.imshow(noisy_image, cmap=plt.cm.gray)
|
||||
ax1.set_title('Original')
|
||||
ax1.axis('off')
|
||||
ax1.set_adjustable('box-forced')
|
||||
ax[0].imshow(noisy_image, cmap=plt.cm.gray)
|
||||
ax[0].set_title('Original')
|
||||
ax[0].axis('off')
|
||||
ax[0].set_adjustable('box-forced')
|
||||
|
||||
ax2.imshow(bilat, cmap=plt.cm.gray)
|
||||
ax2.set_title('Bilateral mean')
|
||||
ax2.axis('off')
|
||||
ax2.set_adjustable('box-forced')
|
||||
ax[1].imshow(bilat, cmap=plt.cm.gray)
|
||||
ax[1].set_title('Bilateral mean')
|
||||
ax[1].axis('off')
|
||||
ax[1].set_adjustable('box-forced')
|
||||
|
||||
ax3.imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax3.axis('off')
|
||||
ax3.set_adjustable('box-forced')
|
||||
ax[2].imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax[2].axis('off')
|
||||
ax[2].set_adjustable('box-forced')
|
||||
|
||||
ax4.imshow(bilat[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax4.axis('off')
|
||||
ax4.set_adjustable('box-forced')
|
||||
ax[3].imshow(bilat[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax[3].axis('off')
|
||||
ax[3].set_adjustable('box-forced')
|
||||
|
||||
######################################################################
|
||||
# One can see that the large continuous part of the image (e.g. sky) is
|
||||
@@ -193,26 +193,26 @@ 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))
|
||||
|
||||
fig, ax = plt.subplots(3, 2, figsize=(10, 10))
|
||||
ax1, ax2, ax3, ax4, ax5, ax6 = ax.ravel()
|
||||
fig, axes = plt.subplots(3, 2, figsize=(10, 10))
|
||||
ax = axes.ravel()
|
||||
|
||||
ax1.imshow(noisy_image, interpolation='nearest', cmap=plt.cm.gray)
|
||||
ax1.axis('off')
|
||||
ax[0].imshow(noisy_image, interpolation='nearest', cmap=plt.cm.gray)
|
||||
ax[0].axis('off')
|
||||
|
||||
ax2.plot(hist[1][:-1], hist[0], lw=2)
|
||||
ax2.set_title('Histogram of gray values')
|
||||
ax[1].plot(hist[1][:-1], hist[0], lw=2)
|
||||
ax[1].set_title('Histogram of gray values')
|
||||
|
||||
ax3.imshow(glob, interpolation='nearest', cmap=plt.cm.gray)
|
||||
ax3.axis('off')
|
||||
ax[2].imshow(glob, interpolation='nearest', cmap=plt.cm.gray)
|
||||
ax[2].axis('off')
|
||||
|
||||
ax4.plot(glob_hist[1][:-1], glob_hist[0], lw=2)
|
||||
ax4.set_title('Histogram of gray values')
|
||||
ax[3].plot(glob_hist[1][:-1], glob_hist[0], lw=2)
|
||||
ax[3].set_title('Histogram of gray values')
|
||||
|
||||
ax5.imshow(loc, interpolation='nearest', cmap=plt.cm.gray)
|
||||
ax5.axis('off')
|
||||
ax[4].imshow(loc, interpolation='nearest', cmap=plt.cm.gray)
|
||||
ax[4].axis('off')
|
||||
|
||||
ax6.plot(loc_hist[1][:-1], loc_hist[0], lw=2)
|
||||
ax6.set_title('Histogram of gray values')
|
||||
ax[5].plot(loc_hist[1][:-1], loc_hist[0], lw=2)
|
||||
ax[5].set_title('Histogram of gray values')
|
||||
|
||||
######################################################################
|
||||
# Another way to maximize the number of gray-levels used for an image is to
|
||||
@@ -261,7 +261,6 @@ loc_perc_autolevel2 = autolevel_percentile(image, selem=selem, p0=.05, p1=.95)
|
||||
loc_perc_autolevel3 = autolevel_percentile(image, selem=selem, p0=.1, p1=.9)
|
||||
|
||||
fig, axes = plt.subplots(nrows=3, ncols=2, figsize=(7, 8), sharex=True, sharey=True)
|
||||
ax0, ax1, ax2 = axes
|
||||
plt.gray()
|
||||
|
||||
title_list = ['Original',
|
||||
@@ -276,9 +275,9 @@ image_list = [image,
|
||||
loc_perc_autolevel1,
|
||||
loc_perc_autolevel2,
|
||||
loc_perc_autolevel3]
|
||||
axes_list = axes.ravel().tolist()
|
||||
axes_list = axes.ravel()
|
||||
|
||||
for i in range(0,len(image_list)):
|
||||
for i in range(0, len(image_list)):
|
||||
axes_list[i].imshow(image_list[i], cmap=plt.cm.gray, vmin=0, vmax=255)
|
||||
axes_list[i].set_title(title_list[i])
|
||||
axes_list[i].axis('off')
|
||||
@@ -295,26 +294,26 @@ noisy_image = img_as_ubyte(data.camera())
|
||||
|
||||
enh = enhance_contrast(noisy_image, disk(5))
|
||||
|
||||
fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex='row', sharey='row')
|
||||
ax1, ax2, ax3, ax4 = ax.ravel()
|
||||
fig, axes = plt.subplots(2, 2, figsize=[10, 7], sharex='row', sharey='row')
|
||||
ax = axes.ravel()
|
||||
|
||||
ax1.imshow(noisy_image, cmap=plt.cm.gray)
|
||||
ax1.set_title('Original')
|
||||
ax1.axis('off')
|
||||
ax1.set_adjustable('box-forced')
|
||||
ax[0].imshow(noisy_image, cmap=plt.cm.gray)
|
||||
ax[0].set_title('Original')
|
||||
ax[0].axis('off')
|
||||
ax[0].set_adjustable('box-forced')
|
||||
|
||||
ax2.imshow(enh, cmap=plt.cm.gray)
|
||||
ax2.set_title('Local morphological contrast enhancement')
|
||||
ax2.axis('off')
|
||||
ax2.set_adjustable('box-forced')
|
||||
ax[1].imshow(enh, cmap=plt.cm.gray)
|
||||
ax[1].set_title('Local morphological contrast enhancement')
|
||||
ax[1].axis('off')
|
||||
ax[1].set_adjustable('box-forced')
|
||||
|
||||
ax3.imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax3.axis('off')
|
||||
ax3.set_adjustable('box-forced')
|
||||
ax[2].imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax[2].axis('off')
|
||||
ax[2].set_adjustable('box-forced')
|
||||
|
||||
ax4.imshow(enh[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax4.axis('off')
|
||||
ax4.set_adjustable('box-forced')
|
||||
ax[3].imshow(enh[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax[3].axis('off')
|
||||
ax[3].set_adjustable('box-forced')
|
||||
|
||||
######################################################################
|
||||
# The percentile version of the local morphological contrast enhancement uses
|
||||
@@ -326,22 +325,22 @@ noisy_image = img_as_ubyte(data.camera())
|
||||
|
||||
penh = enhance_contrast_percentile(noisy_image, disk(5), p0=.1, p1=.9)
|
||||
|
||||
fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex='row', sharey='row')
|
||||
ax1, ax2, ax3, ax4 = ax.ravel()
|
||||
fig, axes = plt.subplots(2, 2, figsize=[10, 7], sharex='row', sharey='row')
|
||||
ax = axes.ravel()
|
||||
|
||||
ax1.imshow(noisy_image, cmap=plt.cm.gray)
|
||||
ax1.set_title('Original')
|
||||
ax[0].imshow(noisy_image, cmap=plt.cm.gray)
|
||||
ax[0].set_title('Original')
|
||||
|
||||
ax2.imshow(penh, cmap=plt.cm.gray)
|
||||
ax2.set_title('Local percentile morphological\n contrast enhancement')
|
||||
ax[1].imshow(penh, cmap=plt.cm.gray)
|
||||
ax[1].set_title('Local percentile morphological\n contrast enhancement')
|
||||
|
||||
ax3.imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax[2].imshow(noisy_image[200:350, 350:450], cmap=plt.cm.gray)
|
||||
|
||||
ax4.imshow(penh[200:350, 350:450], cmap=plt.cm.gray)
|
||||
ax[3].imshow(penh[200:350, 350:450], cmap=plt.cm.gray)
|
||||
|
||||
for ax in ax.ravel():
|
||||
ax.axis('off')
|
||||
ax.set_adjustable('box-forced')
|
||||
for a in ax:
|
||||
a.axis('off')
|
||||
a.set_adjustable('box-forced')
|
||||
|
||||
######################################################################
|
||||
#
|
||||
@@ -379,24 +378,24 @@ loc_otsu = p8 >= t_loc_otsu
|
||||
t_glob_otsu = threshold_otsu(p8)
|
||||
glob_otsu = p8 >= t_glob_otsu
|
||||
|
||||
fig, ax = plt.subplots(2, 2, sharex=True, sharey=True)
|
||||
ax1, ax2, ax3, ax4 = ax.ravel()
|
||||
fig, axes = plt.subplots(2, 2, sharex=True, sharey=True)
|
||||
ax = axes.ravel()
|
||||
|
||||
fig.colorbar(ax1.imshow(p8, cmap=plt.cm.gray), ax=ax1)
|
||||
ax1.set_title('Original')
|
||||
ax[0].set_title('Original')
|
||||
|
||||
fig.colorbar(ax2.imshow(t_loc_otsu, cmap=plt.cm.gray), ax=ax2)
|
||||
ax2.set_title('Local Otsu ($r=%d$)' % radius)
|
||||
fig.colorbar(ax[1].imshow(t_loc_otsu, cmap=plt.cm.gray), ax=ax2)
|
||||
ax[1].set_title('Local Otsu ($r=%d$)' % radius)
|
||||
|
||||
ax3.imshow(p8 >= t_loc_otsu, cmap=plt.cm.gray)
|
||||
ax3.set_title('Original >= local Otsu' % t_glob_otsu)
|
||||
ax[2].imshow(p8 >= t_loc_otsu, cmap=plt.cm.gray)
|
||||
ax[2].set_title('Original >= local Otsu' % t_glob_otsu)
|
||||
|
||||
ax4.imshow(glob_otsu, cmap=plt.cm.gray)
|
||||
ax4.set_title('Global Otsu ($t=%d$)' % t_glob_otsu)
|
||||
ax[3].imshow(glob_otsu, cmap=plt.cm.gray)
|
||||
ax[3].set_title('Global Otsu ($t=%d$)' % t_glob_otsu)
|
||||
|
||||
for ax in ax.ravel():
|
||||
ax.axis('off')
|
||||
ax.set_adjustable('box-forced')
|
||||
for a in ax:
|
||||
a.axis('off')
|
||||
a.set_adjustable('box-forced')
|
||||
|
||||
######################################################################
|
||||
# The following example shows how local Otsu thresholding handles a global
|
||||
@@ -446,24 +445,24 @@ opening = minimum(maximum(noisy_image, disk(5)), disk(5))
|
||||
grad = gradient(noisy_image, disk(5))
|
||||
|
||||
# display results
|
||||
fig, ax = plt.subplots(2, 2, figsize=[10, 7], sharex=True, sharey=True)
|
||||
ax1, ax2, ax3, ax4 = ax.ravel()
|
||||
fig, axes = plt.subplots(2, 2, figsize=[10, 7], sharex=True, sharey=True)
|
||||
ax = axes.ravel()
|
||||
|
||||
ax1.imshow(noisy_image, cmap=plt.cm.gray)
|
||||
ax1.set_title('Original')
|
||||
ax[0].imshow(noisy_image, cmap=plt.cm.gray)
|
||||
ax[0].set_title('Original')
|
||||
|
||||
ax2.imshow(closing, cmap=plt.cm.gray)
|
||||
ax2.set_title('Gray-level closing')
|
||||
ax[1].imshow(closing, cmap=plt.cm.gray)
|
||||
ax[1].set_title('Gray-level closing')
|
||||
|
||||
ax3.imshow(opening, cmap=plt.cm.gray)
|
||||
ax3.set_title('Gray-level opening')
|
||||
ax[2].imshow(opening, cmap=plt.cm.gray)
|
||||
ax[2].set_title('Gray-level opening')
|
||||
|
||||
ax4.imshow(grad, cmap=plt.cm.gray)
|
||||
ax4.set_title('Morphological gradient')
|
||||
ax[3].imshow(grad, cmap=plt.cm.gray)
|
||||
ax[3].set_title('Morphological gradient')
|
||||
|
||||
for ax in ax.ravel():
|
||||
ax.axis('off')
|
||||
ax.set_adjustable('box-forced')
|
||||
for a in ax:
|
||||
a.axis('off')
|
||||
a.set_adjustable('box-forced')
|
||||
######################################################################
|
||||
#
|
||||
# Feature extraction
|
||||
|
||||
Reference in New Issue
Block a user