Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import numpy as np
- from scipy import ndimage
- import matplotlib.pyplot as plt
- fname = "mazeflyer.png"
- img = Image.open(fname).convert('L')
- img = np.asarray(img)
- blur_radius = 1
- # smooth the image (to remove small objects)
- imgf = ndimage.gaussian_filter(img, blur_radius)
- threshold_low = 5
- threshold_high = 250
- img_low = imgf > threshold_low
- img_high = imgf < threshold_high
- img_to_use = img_high & img_low
- labeled, nr_objects = ndimage.label(img_to_use)
- nr_objects
- plt.imsave('./out.png', labeled)
- # thresholds for number of pixels
- low = 6
- high = 25
- for i in range(np.max):
- amt = np.sum(labeled == i)
- if amt > low and amt < high:
- vals = np.where(labeled == 2)
- out = zip(*np.where(labeled==4))
- nr_objects
- img = Image.open(fname).convert('L')
- img = np.asarray(img)
- img = np.asarray(img)
- labeled, nr_objects = ndimage.label(img)
- nr_objects
- 37
- plt.imsave('./out.png', labeled)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement