def test_slic_consistency_across_image_magnitude(): # verify that that images of various scales across integer and float dtypes # give the same segmentation result img_uint8 = data.cat()[:256, :128] img_uint16 = 256 * img_uint8.astype(np.uint16) img_float32 = img_as_float(img_uint8) img_float32_norm = img_float32 / img_float32.max() seg1 = slic(img_uint8) seg2 = slic(img_uint16) seg3 = slic(img_float32) seg4 = slic(img_float32_norm) np.testing.assert_array_equal(seg1, seg2) np.testing.assert_array_equal(seg1, seg3) np.testing.assert_array_equal(seg1, seg4)
def test_slic_consistency_across_image_magnitude(): # verify that that images of various scales across integer and float dtypes # give the same segmentation result img_uint8 = data.cat()[:256, :128] img_uint16 = 256 * img_uint8.astype(np.uint16) img_float32 = img_as_float(img_uint8) img_float32_norm = img_float32 / img_float32.max() seg1 = slic(img_uint8) seg2 = slic(img_uint16) seg3 = slic(img_float32) seg4 = slic(img_float32_norm) np.testing.assert_array_equal(seg1, seg2) np.testing.assert_array_equal(seg1, seg3) # Floating point cases can have mismatch due to floating point error # exact match was observed on x86_64, but mismatches seen no i686. # For now just verify that a similar number of superpixels are present in # each case. n_seg1 = seg1.max() n_seg4 = seg4.max() assert abs(n_seg1 - n_seg4) / n_seg1 < 0.5
from skimage import data from skimage.transform import rotate, rescale from utils import show_image image = data.cat() show_image(image) # Rotate the image 90 degrees clockwise rotated_img = rotate(image, -90) show_image(rotated_img, 'rotated_img') # Rescale with anti aliasing rescaled_with_aa = rescale(rotated_img, 1 / 4, anti_aliasing=True, multichannel=True) # Rescale without anti aliasing rescaled_without_aa = rescale(rotated_img, 1 / 4) # Show the resulting images show_image(rescaled_with_aa, "Transformed with anti aliasing") show_image(rescaled_without_aa, "Transformed without anti aliasing")
image = caller() plt.figure() plt.title(name) if image.ndim == 2: plt.imshow(image, cmap=plt.cm.gray) else: plt.imshow(image) plt.show() ############################################################################ # Thumbnail image for the gallery # sphinx_gallery_thumbnail_number = -1 fig, axs = plt.subplots(nrows=3, ncols=3) for ax in axs.flat: ax.axis("off") axs[0, 0].imshow(data.astronaut()) axs[0, 1].imshow(data.binary_blobs(), cmap=plt.cm.gray) axs[0, 2].imshow(data.brick(), cmap=plt.cm.gray) axs[1, 0].imshow(data.colorwheel()) axs[1, 1].imshow(data.camera(), cmap=plt.cm.gray) axs[1, 2].imshow(data.cat()) axs[2, 0].imshow(data.checkerboard(), cmap=plt.cm.gray) axs[2, 1].imshow(data.clock(), cmap=plt.cm.gray) further_img = np.full((300, 300), 255) for xpos in [100, 150, 200]: further_img[150 - 10:150 + 10, xpos - 10:xpos + 10] = 0 axs[2, 2].imshow(further_img, cmap=plt.cm.gray) plt.subplots_adjust(wspace=0.1, hspace=0.1)