9 x_min = map_image.size[0]
11 y_min = map_image.size[1]
13 pix = map_image.load()
14 for x
in range(map_image.size[0]):
15 for y
in range(map_image.size[1]):
22 return x_min, x_end, y_min, y_end
25 """ Compute the image for the cropped map when map_image is cropped by bounds and had origin before. """
32 dx = bounds[0] * resolution
33 dy = (map_image.size[1] - bounds[3]) * resolution
37 new_ox = ox + dx * math.cos(oth) - dy * math.sin(oth)
38 new_oy = oy + dx * math.sin(oth) + dy * math.cos(oth)
40 return [new_ox, new_oy, oth]
42 if __name__ ==
"__main__":
44 print >> sys.stderr,
"Usage: %s map.yaml [cropped.yaml]" % sys.argv[0]
47 with open(sys.argv[1])
as f:
48 map_data = yaml.safe_load(f)
51 crop_name = sys.argv[2]
52 if crop_name.endswith(
".yaml"):
53 crop_name = crop_name[:-5]
54 crop_yaml = crop_name +
".yaml"
55 crop_image = crop_name +
".pgm"
57 crop_yaml =
"cropped.yaml"
58 crop_image =
"cropped.pgm"
60 map_image_file = map_data[
"image"]
61 resolution = map_data[
"resolution"]
62 origin = map_data[
"origin"]
64 map_image = Image.open(map_image_file)
69 cropped_image = map_image.crop((bounds[0], bounds[2], bounds[1] + 1, bounds[3] + 1))
71 cropped_image.save(crop_image)
72 map_data[
"image"] = crop_image
74 with open(crop_yaml,
"w")
as f:
75 yaml.dump(map_data, f)
def computed_cropped_origin