Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/Users/CiderBones/anaconda3/bin/python
- # Testing out scikit-image with a scanned fluorescent maize ear
- import numpy as np
- import matplotlib.pyplot as plt
- from skimage import io
- from skimage.filters import sobel
- from skimage.color import rgb2gray
- # Importing the image as a numpy array
- maize = io.imread('/Users/CiderBones/Desktop/Laboratory/computer_vision/scikit-image/X402x498-2m1.png')
- # Testing to see if the image imported properly; it looks like it did.
- print(type(maize))
- print(maize.shape)
- # Converting the image to grayscale
- maize_grayscale = rgb2gray(maize)
- # Something's wrong with the histogram: after converting it to grayscale
- # everything's at 0.
- hist = np.histogram(maize_grayscale, bins=np.arange(0, 256))
- # Puts the image into some kind of cache that can be show with plt.show()
- # io.imshow(maize_grayscale)
- fig, axes = plt.subplots(1, 2, figsize=(8, 3))
- axes[0].imshow(maize_grayscale, cmap=plt.cm.gray, interpolation='nearest')
- axes[0].axis('off')
- axes[1].plot(hist[1][:-1], hist[0], lw=2)
- axes[1].set_title('histogram of gray values')
- # Shows both the original image and the histogram of gray values. Not sure how to
- # remove an images once it's in the cache from imshow(). For some reason this is
- # showing both the maize ear and the maize ear plus the histogram. Actually I think
- # I see in line 29 where it's adding both to the same line.
- plt.show()
- # Doing some region-based segmentation
- elevation_map = sobel(maize_grayscale)
- fig, ax = plt.subplots(figsize=(4, 3))
- ax.imshow(elevation_map, cmap=plt.cm.gray, interpolation='nearest')
- ax.set_title('elevation map')
- ax.axis('off')
- plt.show()
- # Finding markers of the background and the kernels based on extreme parts of the
- # histogram of gray values. Not sure what that means. Not working, maybe tied to
- # the histogram not working?
- markers = np.zeros_like(maize_grayscale)
- markers[maize_grayscale < 30] = 1
- markers[maize_grayscale > 150] = 2
- fig, ax = plt.subplots(figsize=(4, 3))
- ax.imshow(markers, cmap=plt.cm.nipy_spectral, interpolation='nearest')
- ax.set_title('markers')
- ax.axis('off')
- plt.show()
Add Comment
Please, Sign In to add comment