#!/usr/bin/python

import os,string

use_color=False
prefix='posters'
sets = ('american','spanish')
use_lambda = "1"
use_gamma = "1E-3"

if use_color:
    prefix=os.path.join(prefix,'color')
else:
    prefix=os.path.join(prefix,'gray')

imgs=[]
vals=[]
for si in range(len(sets)):
    y = si*2-1
    set = os.path.join(prefix,sets[si])
    for img in [ i for i in os.listdir(set) if i[-5:].lower()=='.tiff']:
        imgs.append(os.path.join(set,img))
        vals.append(y)

if not use_color:
    print "x=[",string.join(map(lambda s:("reshape(im2double(imread('%s')),%d,1)" % (s,313*446)),imgs)," "),"];"
else:
    print "x=[",string.join(map(lambda s:("reshape(imread('%s'),%d,1,3)" % (s,313*446)),imgs)," "),"];"
    print "x=double(x(:,:,1))*2^16 + double(x(:,:,2))*2^8 + double(x(:,:,3));"

print "y=[",string.join(map(str,vals)," "),"];"

uset = os.path.join(prefix,'unknown')
ufls = [ os.path.join(uset,i) for i in os.listdir(uset) if i[-5:].lower()=='.tiff']
print "uf=[",string.join(map(lambda s:("'%s'" % s),ufls)," "),"];"
if not use_color:
    print "u=[",string.join(map(lambda s:("reshape(im2double(imread('%s')),%d,1)" % (s,313*446)),ufls)," "),"];"
else:
    print "u=[",string.join(map(lambda s:("reshape(imread('%s'),%d,1,3)" % (s,313*446)),ufls)," "),"];"
    print "u=double(u(:,:,1))*2^16 + double(u(:,:,2))*2^8 + double(u(:,:,3));"

print "LAMBDA=%s" % use_lambda
print "%GAMMA is used for gaussian only"
print "GAMMA=%s" % use_gamma
