Commit 614bc659 authored by Andrey Filippov's avatar Andrey Filippov

generating Verilog input data from tiff images

parent cb75953f
from __future__ import division
from __future__ import print_function
'''
# Copyright (C) 2015, Elphel.inc.
# Class to export hardware definitions from Verilog parameters
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
@author: Andrey Filippov
@copyright: 2015 Elphel, Inc.
@license: GPLv3.0+
@contact: andrey@elphel.com
@deffield updated: Updated
'''
__author__ = "Andrey Filippov"
__copyright__ = "Copyright 2015, Elphel, Inc."
__license__ = "GPL"
__version__ = "3.0+"
__maintainer__ = "Andrey Filippov"
__email__ = "andrey@elphel.com"
__status__ = "Development"
from PIL import Image
import sys
import numpy as np
class imagej_tiff:
# imagej stores labels lengths in this tag
__TIFF_TAG_LABELS_LENGTHS = 50838
# imagej stores labels conents in this tag
__TIFF_TAG_LABELS_STRINGS = 50839
# init
def __init__(self,filename, digits, outname):
# file name
self.fname = filename
self.outname = outname
tif = Image.open(filename)
# total number of layers in tiff
# self.nimages = tif.n_frames
# labels array
# self.labels = []
# infos will contain xml data Elphel stores in some of tiff files
# self.infos = []
# dictionary from decoded infos[0] xml data
# self.props = {}
# bits per sample, type int
# self.bpp = tif.tag[258][0]
image_array = np.array(tif)
f="%%0%dx"%(digits)
with open(outname,"w") as outfile:
print("//",file=outfile)
print("// autogenerated from %s"%(fname),file=outfile)
print("//",file=outfile)
for image_line in image_array:
for pixel in image_line:
print(f%(pixel), file=outfile, end = " ")
print(file=outfile)
tif.close()
#MAIN
if __name__ == "__main__":
try:
fname = sys.argv[1]
except IndexError:
fname = "/data_ssd/nc393/elphel393/fpga-elphel/x393/attic/hor-pairs-12b-1044x36.tiff"
try:
digits = int(sys.argv[2])
except:
digits = 3
try:
outname = sys.argv[3]
except IndexError:
outname = fname.replace(".tiff",".vh")
ijt = imagej_tiff(fname,digits,outname)
print ("All done!")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment