Sunday, September 16, 2007

Saturday (09.16.2007) - basic functioning

I spent the day working on the python script, which went rather nicely. I spent the afternoon and evening getting familiar with gamera through script commands and came up with the following (although not perfect by any means it works):


import os
import sys

from gamera.core import *
from gamera.toolkits.musicstaves import musicstaves_rl_simple
from gamera.toolkits.musicstaves import musicstaves_rl_carter
from gamera.toolkits.musicstaves import musicstaves_rl_fujinaga
from gamera.toolkits.musicstaves import musicstaves_rl_roach_tatem
init_gamera()

source_folder = ['/Users/jasonos/test_images/']
target_folder = ['/Users/jasonos/test_images_conversion/']
folder_contents = os.listdir("/Users/jasonos/test_images/")[1:]

line_removal = ["simple", "carter", "fujinaga", "roach_tatem"]

#folder generation & file copy
for i in range(0,len(folder_contents)):
source= folder_contents[i]
target_subfolder=str(target_folder)[2:-2] + source[:-4]
os.system("mkdir %s" % (target_subfolder))
os.system("cp %s %s" % ((str(source_folder)[2:-2] + "/" + source), str(target_subfolder)))

# gamera commands
image = load_image(str(source_folder)[2:-2]+source)
onebit = image.to_onebit()
onebit_name = source[:-4]+".png"
onebit.save_PNG(onebit_name)
os.system("mv %s %s" % (onebit_name, target_subfolder))
image = onebit

# music staves stuff -> staff removal
for n in range(0, len(line_removal)):
ms = "musicstaves_rl_" +line_removal[n] +".MusicStaves_rl_" + line_removal[n] + "(image)"
ms.remove_staves(crossing_symbols = 'bars')
no_staves_img = ms.image.image_copy()
rl_name = source[:-4] + "_" + n + ".png"
no_staves_img.save_PNG(tl_name)
os.system("m %s %s" % (rl_name, target_subfolder))


actually i lied. the last bit doesnt work yet because i havent figured out how to get a string to run as a command in python yet. I assume it has something to do with the eval statement, such that if I write my own little function, I can then evaluate that func. but I also think that there has to be some sort of simple transform functionality that im missing. anyways, the function DOES work without thte final for loop by replacing that tidy bit of code with blocks for each line removal algorithm.

No comments: