Introduce an image generator (#426)
author김정현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh0822.kim@samsung.com>
Mon, 9 Apr 2018 00:51:23 +0000 (09:51 +0900)
committer오형석/동작제어Lab(SR)/Senior Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 9 Apr 2018 00:51:23 +0000 (09:51 +0900)
This commit introduces an image generator:

- How to execute:
`$ ./imagegen.py`
Two output images are generated: `image.bin` and `image.ppm`.

- Changing the size of the output image
Change variable `image_size` at the beginning of `imagegen.py`.

- Changing output image format
If you want to output another image format, you can use as below:
`im.save("image.jpg")`

Signed-off-by: Junghyun Kim <jh0822.kim@samsung.com>
tools/image_importer/README.md [new file with mode: 0644]
tools/image_importer/imagegen.py [new file with mode: 0755]

diff --git a/tools/image_importer/README.md b/tools/image_importer/README.md
new file mode 100644 (file)
index 0000000..abc088f
--- /dev/null
@@ -0,0 +1,15 @@
+# A simple image generator
+
+## How to execute:
+`$ ./imagegen.py`
+Two output images are generated: `image.bin` and `image.ppm`.
+
+## Changing the size of the output image
+Change variable `image_size` at the beginning of `imagegen.py`.
+
+## Changing output image format
+If you want to output another image format, you can use as below:
+`im.save("image.jpg")`
+
+# An image importer
+Need description.
diff --git a/tools/image_importer/imagegen.py b/tools/image_importer/imagegen.py
new file mode 100755 (executable)
index 0000000..6137761
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+from PIL import Image
+import numpy as np
+
+image_size = {
+        "H":10,
+        "W":10,
+        "C":3 # C is fixed as 3 for R,G,B channels
+        }
+
+rgb = np.zeros([image_size['H'],image_size['W'],image_size["C"]], dtype=np.uint8)
+for y in range(image_size["H"]):
+    for x in range(image_size["W"]):
+        for c in range(image_size["C"]):
+            rgb[y][x][c] = 255  #value range = [0~255]
+
+im = Image.fromarray(rgb)
+im.save("image.ppm")
+
+# image can be saved as .jpg or .png
+# im.save("image.jpg")
+# im.save("image.png")
+
+with open("image.bin", "wb") as f:
+    f.write(im.tobytes())