Created
May 20, 2014 12:33
-
-
Save TurpIF/8b67184a581b6aec17c0 to your computer and use it in GitHub Desktop.
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
from scipy.misc import imread, imsave | |
from scipy import ndimage | |
import numpy as np | |
import math | |
def circle(radius): | |
""" Product a boolean array with a shape of circle inside (True inside the | |
circle and False outside). """ | |
assert radius >= 1 | |
radius -= 1 | |
size = (radius * 2) + 1 | |
y, x = np.ogrid[-radius:size - radius, -radius:size - radius] | |
mask = x ** 2 + y ** 2 <= radius ** 2 | |
array = np.full((size, size), False, dtype=bool) | |
array[mask] = True | |
return array | |
if __name__ == '__main__': | |
input_filename = 'Astar_inv.png' | |
output_filename = 'output.png' | |
radius = 10 # in pixel | |
bot_radius = 350.0 # in mm | |
mm_per_pixel = 2.0 # in mm / pixel | |
img = imread(input_filename) | |
bool_img = img.astype(bool) | |
mask = circle(radius) | |
iterations = math.ceil(bot_radius / mm_per_pixel / radius) | |
masked_img = ndimage.morphology.binary_dilation( | |
bool_img[:,:], structure=mask, iterations=iterations) | |
out_img = masked_img.astype(np.uint8) * 255 | |
imsave(output_filename, out_img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment