Created
March 13, 2019 17:05
-
-
Save iandewancker/6bec4b18aa931c9472902d6125b6def3 to your computer and use it in GitHub Desktop.
felzenszwalb segmentations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import skimage | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from PIL import Image | |
import glob | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from skimage.segmentation import felzenszwalb, slic, quickshift, watershed | |
from skimage.segmentation import mark_boundaries | |
from skimage.util import img_as_float | |
from scipy import ndimage as nd | |
from skimage import feature | |
rgbs = glob.glob("*.jpeg") | |
rgbs = sorted(rgbs) | |
import PIL | |
import re | |
def natural_sort(l): | |
convert = lambda text: int(text) if text.isdigit() else text.lower() | |
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] | |
return sorted(l, key = alphanum_key) | |
for rgb_name in rgbs: | |
rgb = np.array(PIL.Image.open(rgb_name)) | |
fig = plt.figure(figsize=(18,9)) | |
ax1 = fig.add_subplot(1, 2, 1) | |
ax2 = fig.add_subplot(1, 2, 2) | |
ax1.imshow(rgb) | |
print(rgb_name) | |
segments_fz = felzenszwalb(rgb, scale=100, sigma=1.5, min_size=150) #min_size=150, sigma=1.5 | |
ax2.imshow(mark_boundaries(rgb, segments_fz)) | |
plt.title("Felzenszwalb Segments {}".format(np.unique(segments_fz).shape[0])) | |
plt.savefig(rgb_name+"_segments.png", dpi=150, transparent=True, bbox_inches='tight') | |
plt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment