Created
October 20, 2015 14:09
-
-
Save NickShargan/e47d7dc3258bc31dbdc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import Image | |
def mergeImages(images): | |
if len(images) > 0: | |
merged = Image.new('RGB', (images[0].size[0], images[0].size[1]), "black") | |
pixels = merged.load() | |
for img in images: | |
for x in range(merged.size[0]): | |
for y in range(merged.size[1]): | |
if img.getpixel((x, y)) != (0, 0, 0): | |
pixels[x, y] = img.getpixel((x, y)) | |
return merged | |
def main(path): | |
files = os.listdir(path) | |
# read color maps in path | |
colMaps = [] | |
colMapsPathes = [] | |
for el in files: | |
if el[-3:] == 'tif': | |
if el[-12:-10] == 'TM': | |
colMaps.append(Image.open(path + el)) | |
colMapsPathes.append(path + el) | |
mergedTM = mergeImages(colMaps) | |
mergedTM.save('mergedTM.tif') | |
# Remove maps for each separate object | |
for i in reversed(range(len(colMaps))): | |
del colMaps[i] | |
os.remove(colMapsPathes[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment