Skip to content

Commit

Permalink
Apply black to tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Feb 12, 2020
1 parent 5e25f82 commit 86e04ae
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 116 deletions.
6 changes: 3 additions & 3 deletions examples/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def run_example(function):
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument('--save', action='store_true', help='save image')
parser.add_argument("--save", action="store_true", help="save image")
args = parser.parse_args()

img = function()

if args.save:
out_file = osp.join(here, '.readme/{}.jpg'.format(function.__name__))
out_file = osp.join(here, ".readme/{}.jpg".format(function.__name__))
imgviz.io.imsave(out_file, img)

plt.imshow(img)
plt.axis('off')
plt.axis("off")
plt.show()
16 changes: 8 additions & 8 deletions examples/centerize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def centerize():
data = imgviz.data.arc2017()

rgb = data['rgb']
rgb = data["rgb"]

H, W = rgb.shape[:2]
centerized1 = imgviz.centerize(rgb, shape=(H, H))
Expand All @@ -21,24 +21,24 @@ def centerize():
plt.figure(dpi=200)

plt.subplot(131)
plt.title('original')
plt.axis('off')
plt.title("original")
plt.axis("off")
plt.imshow(rgb)

plt.subplot(132)
plt.title('centerized1:\n{}'.format(centerized1.shape))
plt.title("centerized1:\n{}".format(centerized1.shape))
plt.imshow(centerized1)
plt.axis('off')
plt.axis("off")

plt.subplot(133)
plt.title('centerized2:\n{}'.format(centerized2.shape))
plt.title("centerized2:\n{}".format(centerized2.shape))
plt.imshow(centerized2)
plt.axis('off')
plt.axis("off")

return imgviz.io.pyplot_to_numpy()


if __name__ == '__main__':
if __name__ == "__main__":
from base import run_example

run_example(centerize)
14 changes: 7 additions & 7 deletions examples/depth2rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
def depth2rgb():
data = imgviz.data.arc2017()

depthviz = imgviz.depth2rgb(data['depth'], min_value=0.3, max_value=1)
depthviz = imgviz.depth2rgb(data["depth"], min_value=0.3, max_value=1)

# -------------------------------------------------------------------------

plt.figure(dpi=200)

plt.subplot(121)
plt.title('rgb')
plt.imshow(data['rgb'])
plt.axis('off')
plt.title("rgb")
plt.imshow(data["rgb"])
plt.axis("off")

plt.subplot(122)
plt.title('depth (colorized)')
plt.title("depth (colorized)")
plt.imshow(depthviz)
plt.axis('off')
plt.axis("off")

img = imgviz.io.pyplot_to_numpy()
plt.close()

return img


if __name__ == '__main__':
if __name__ == "__main__":
from base import run_example

run_example(depth2rgb)
35 changes: 19 additions & 16 deletions examples/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def draw():
)
viz = imgviz.draw.text_in_rectangle(
viz,
loc='lt',
text='face',
loc="lt",
text="face",
size=30,
background=(255, 255, 255),
aabb1=(y1, x1),
Expand All @@ -28,50 +28,53 @@ def draw():
# eye, eye, nose, mouse, mouse
xys = [(265, 265), (330, 265), (315, 320), (270, 350), (320, 350)]
colors = imgviz.label_colormap(value=255)[1:]
shapes = ['star', 'star', 'rectangle', 'circle', 'triangle']
shapes = ["star", "star", "rectangle", "circle", "triangle"]
for xy, color, shape in zip(xys, colors, shapes):
size = 20
color = tuple(color)
if shape == 'star':
if shape == "star":
viz = imgviz.draw.star(
viz, center=(xy[1], xy[0]), size=1.2 * size, fill=color)
elif shape == 'circle':
viz, center=(xy[1], xy[0]), size=1.2 * size, fill=color
)
elif shape == "circle":
viz = imgviz.draw.circle(
viz, center=(xy[1], xy[0]), diameter=size, fill=color)
elif shape == 'triangle':
viz, center=(xy[1], xy[0]), diameter=size, fill=color
)
elif shape == "triangle":
viz = imgviz.draw.triangle(
viz, center=(xy[1], xy[0]), size=size, fill=color)
elif shape == 'rectangle':
viz, center=(xy[1], xy[0]), size=size, fill=color
)
elif shape == "rectangle":
viz = imgviz.draw.rectangle(
viz,
aabb1=(xy[1] - size / 2, xy[0] - size / 2),
aabb2=(xy[1] + size / 2, xy[0] + size / 2),
fill=color,
)
else:
raise ValueError('unsupport shape: {}'.format(shape))
raise ValueError("unsupport shape: {}".format(shape))

# -------------------------------------------------------------------------

plt.figure(dpi=200)

plt.subplot(121)
plt.title('original')
plt.title("original")
plt.imshow(img)
plt.axis('off')
plt.axis("off")

plt.subplot(122)
plt.title('markers')
plt.title("markers")
plt.imshow(viz)
plt.axis('off')
plt.axis("off")

img = imgviz.io.pyplot_to_numpy()
plt.close()

return img


if __name__ == '__main__':
if __name__ == "__main__":
from base import run_example

run_example(draw)
14 changes: 7 additions & 7 deletions examples/flow2rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
def flow2rgb():
data = imgviz.data.middlebury()

rgb = data['rgb']
flowviz = imgviz.flow2rgb(data['flow'])
rgb = data["rgb"]
flowviz = imgviz.flow2rgb(data["flow"])

# -------------------------------------------------------------------------

plt.figure(dpi=200)

plt.subplot(121)
plt.title('image')
plt.title("image")
plt.imshow(rgb)
plt.axis('off')
plt.axis("off")

plt.subplot(122)
plt.title('flow')
plt.title("flow")
plt.imshow(flowviz)
plt.axis('off')
plt.axis("off")

img = imgviz.io.pyplot_to_numpy()
plt.close()

return img


if __name__ == '__main__':
if __name__ == "__main__":
from base import run_example

run_example(flow2rgb)
30 changes: 15 additions & 15 deletions examples/instances2rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
def instances2rgb():
data = imgviz.data.voc()

captions = [data['class_names'][l] for l in data['labels']]
captions = [data["class_names"][l] for l in data["labels"]]
insviz1 = imgviz.instances2rgb(
image=data['rgb'],
bboxes=data['bboxes'],
labels=data['labels'],
image=data["rgb"],
bboxes=data["bboxes"],
labels=data["labels"],
captions=captions,
)
insviz2 = imgviz.instances2rgb(
image=data['rgb'],
masks=data['masks'] == 1,
labels=data['labels'],
image=data["rgb"],
masks=data["masks"] == 1,
labels=data["labels"],
captions=captions,
)

Expand All @@ -27,27 +27,27 @@ def instances2rgb():
plt.figure(dpi=200)

plt.subplot(131)
plt.title('rgb')
plt.imshow(data['rgb'])
plt.axis('off')
plt.title("rgb")
plt.imshow(data["rgb"])
plt.axis("off")

plt.subplot(132)
plt.title('instances\n(bboxes)')
plt.title("instances\n(bboxes)")
plt.imshow(insviz1)
plt.axis('off')
plt.axis("off")

plt.subplot(133)
plt.title('instances\n(masks)')
plt.title("instances\n(masks)")
plt.imshow(insviz2)
plt.axis('off')
plt.axis("off")

img = imgviz.io.pyplot_to_numpy()
plt.close()

return img


if __name__ == '__main__':
if __name__ == "__main__":
from base import run_example

run_example(instances2rgb)
14 changes: 7 additions & 7 deletions examples/io_examples/pyglet_imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

def get_images():
data = imgviz.data.arc2017()
yield data['rgb']
yield imgviz.depth2rgb(data['depth'], min_value=0.3, max_value=1)
yield imgviz.label2rgb(data['class_label'])
yield data["rgb"]
yield imgviz.depth2rgb(data["depth"], min_value=0.3, max_value=1)
yield imgviz.label2rgb(data["class_label"])


def main():
imgviz.io.pyglet_imshow(next(get_images()), 'ndarray')
imgviz.io.pyglet_imshow(next(get_images()), "ndarray")
imgviz.io.pyglet_run()

imgviz.io.pyglet_imshow(get_images(), 'generator')
imgviz.io.pyglet_imshow(get_images(), "generator")
imgviz.io.pyglet_run()

imgviz.io.pyglet_imshow(list(get_images()), 'list')
imgviz.io.pyglet_imshow(list(get_images()), "list")
imgviz.io.pyglet_run()


if __name__ == '__main__':
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion examples/io_examples/pyglet_threaded_image_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ def main():
viewer.imshow(image)


if __name__ == '__main__':
if __name__ == "__main__":
main()
22 changes: 11 additions & 11 deletions examples/label2rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
def label2rgb():
data = imgviz.data.voc()

rgb = data['rgb']
label = data['class_label']
rgb = data["rgb"]
label = data["class_label"]

label_names = [
'{}:{}'.format(i, n) for i, n in enumerate(data['class_names'])
"{}:{}".format(i, n) for i, n in enumerate(data["class_names"])
]
labelviz_withname1 = imgviz.label2rgb(
label, label_names=label_names, font_size=25
)
labelviz_withname2 = imgviz.label2rgb(
label, label_names=label_names, font_size=25, loc='lt'
label, label_names=label_names, font_size=25, loc="lt"
)
img = imgviz.color.rgb2gray(rgb)
labelviz_withimg = imgviz.label2rgb(label, img=img)
Expand All @@ -28,27 +28,27 @@ def label2rgb():
plt.figure(dpi=200)

plt.subplot(131)
plt.title('+img')
plt.title("+img")
plt.imshow(labelviz_withimg)
plt.axis('off')
plt.axis("off")

plt.subplot(132)
plt.title('loc=centroid')
plt.title("loc=centroid")
plt.imshow(labelviz_withname1)
plt.axis('off')
plt.axis("off")

plt.subplot(133)
plt.title('loc=lt')
plt.title("loc=lt")
plt.imshow(labelviz_withname2)
plt.axis('off')
plt.axis("off")

img = imgviz.io.pyplot_to_numpy()
plt.close()

return img


if __name__ == '__main__':
if __name__ == "__main__":
from base import run_example

run_example(label2rgb)

0 comments on commit 86e04ae

Please sign in to comment.