Skip to content
Browse files

fixed exception, won't break on misformatted files in collection, add…

…ed support for blacknwhite source images
  • Loading branch information...
1 parent 97357f5 commit b30d44249e18c3de017d936f4ed9ba6e841fc381 Abhishek Mishra committed
Showing with 18 additions and 10 deletions.
  1. +18 −10 pymos/core.py
View
28 pymos/core.py
@@ -35,8 +35,12 @@ def build_colormap(files):
temp = Image.open(eachfile)
red = green = blue = 0
- imdata = list(temp.getdata())
- imdata_size = len(imdata)
+ try:
+ imdata = list(temp.getdata())
+ imdata_size = len(imdata)
+ except:
+ log.debug ("Error processing " + eachfile)
+ continue
try:
for i in imdata:
@@ -83,12 +87,13 @@ def build_mosaic(input_path, output_path, collection_path,
if os.path.exists(colormap_file) and not new_colormap:
colormap = pickle.load(open(colormap_file))
else:
- try:
- colormap = build_colormap(files)
- pickle.dump(colormap, open(colormap_file, 'w'))
- except IOError:
- log.info( "Error: Collection not found.")
- sys.exit(1)
+ #try:
+ colormap = build_colormap(files)
+ pickle.dump(colormap, open(colormap_file, 'w'))
+ #except IOError:
+ # log.info( "Error: Collection not found.")
+ # sys.exit(1)
+ # this exception might cause it to break even at x% of colormap build
log.info("Color Index built")
@@ -111,8 +116,11 @@ def build_mosaic(input_path, output_path, collection_path,
if (fuzz!=0):
source_color = tuple(s_x + random.randint(-fuzz, fuzz)
for s_x in source_color)
-
- r_1, g_1, b_1 = source_color
+
+ if cmp(type(source_color).__name__, 'int') == 0:
+ r_1 = g_1 = b_1 = source_color
+ else:
+ r_1, g_1, b_1 = source_color
# euclidean distance, color, index in colormap
match = (196608, (555, 555, 555), 0)# initially something out of range

0 comments on commit b30d442

Please sign in to comment.
Something went wrong with that request. Please try again.