Beispiel #1
0
def main(args):
    #args = sys.argv[1:]
    if len(args) != 3:
        print "Please enter the right number of arguments"
        exit()
    inputFile = open(args[1],'r')
    inputFileReadLine = inputFile.readline()
    inputFileReadLine = inputFileReadLine[1:len(inputFileReadLine)-1]
    S = inoutPut.inputToList(inputFile)
    lengthS = len(S)
    inputFile.close()
    if args[0] == '-bwt':
        print "bwt of:", inputFileReadLine
        newT = util.convertToNumAlphabet(S)
        s_array = ks.cd3(newT)
        S += ["$"]
        b_wt = bwt.bwt(S,s_array)
        outputFile = open(args[2],'w')
        inoutPut.outputToFile(outputFile, b_wt, 'bwt', inputFileReadLine)
        outputFile.close()
        print "length of string:", lengthS
        print "For BWT Check file:", args[2]
    elif args[0] == '-ibwt':
        print "ibwt of:", inputFileReadLine
        rec = bwt.ibwt(S)
        outputFile = open(args[2],'w')
        inoutPut.outputToFile(outputFile, rec,'ibwt', inputFileReadLine)
        outputFile.close()
        print "length of string:", lengthS
        print "For iBWT Check file:", args[2]
            
    else:
        print "You must indicate whether we are doing -btw or -ibtw"
        exit()
    
    pass
Beispiel #2
0
    if im.mode == 'B':
        im = im.convert('L')

    data = im.getdata()
    if len(im.mode) == 1:
        channels = [list(data)]
    else:
        channels = map(list, zip(*data))

    # Replace 255 with 254 so that we could apply inverse bwt later
    if not args.inverse:
        threads = []

        def thread_func(chan_num):
            channels[chan_num] = bwt_pixels(channels[chan_num])

        for i in xrange(len(channels)):
            threads.append(threading.Thread(target=thread_func, args=(i, )))
            threads[-1].start()
        [t.join() for t in threads]
    else:
        channels = [ibwt(channel, 255) for channel in channels]
    if len(im.mode) == 1:
        data = channels
    else:
        data = zip(*channels)

    im.putdata(data)
    im.save(args.output_image)