|
a |
|
b/3D Reconstruction/Interpolation/png2raw.py |
|
|
1 |
import numpy |
|
|
2 |
import os |
|
|
3 |
import argparse |
|
|
4 |
from PIL import Image |
|
|
5 |
|
|
|
6 |
parser = argparse.ArgumentParser( |
|
|
7 |
description = 'Convert continuous PNG file to RAW file(volume data)') |
|
|
8 |
parser.add_argument('-in', '--input_dir', default = '', help='Input directory for PNG files') |
|
|
9 |
parser.add_argument('-out', '--output_dir', default = '', help='Output directory for RAW file') |
|
|
10 |
|
|
|
11 |
args = parser.parse_args() |
|
|
12 |
|
|
|
13 |
images = [] |
|
|
14 |
for dirName, subdirList, fileList in os.walk(args.input_dir): |
|
|
15 |
for filename in fileList: |
|
|
16 |
if '.png' in filename.lower(): |
|
|
17 |
image = Image.open(os.path.join(dirName, filename)) |
|
|
18 |
images.append(numpy.array(image)) |
|
|
19 |
|
|
|
20 |
dimZ = len(images) |
|
|
21 |
dimX = images[0].shape[0] |
|
|
22 |
dimY = images[0].shape[1] |
|
|
23 |
|
|
|
24 |
ArrayRaw = numpy.zeros((dimZ, dimX, dimY), dtype=numpy.uint8) |
|
|
25 |
|
|
|
26 |
# loop through all the image files |
|
|
27 |
for idx, image in enumerate(images): |
|
|
28 |
# store the raw image data |
|
|
29 |
ArrayRaw[idx, :, :] = image |
|
|
30 |
|
|
|
31 |
# save raw |
|
|
32 |
ArrayRaw.tofile(os.path.join(args.output_dir,'output.raw')) |