#This is a python script runned by the windows system.
#Anaconda is recommended for users.
#The script is used to add ruler to the photo from optical microscope.
#Author: Li Xin, a graduate student studying Materials Science & Engineering in USTB
#Email: lixin@xs.ustb.edu.cn
from __future__ import print_function
from PIL import Image
import os
print("Please input the folder where your pictures are placed:")
path = input()
if path[-1] != "\\":
    path = path + "\\"
scaleplate_path = "C:\\scaleplate\\"
files = os.listdir(path)
for i in files:
    name = i.split('_')
    if len(name) == 3:
        if name[1] == "40":
            scale = name[1]+".jpg"
        elif name[1] == "100":
            scale = name[1]+".jpg"
        elif name[1] == "200":
            scale = name[1]+".jpg"
        elif name[1] == "500":
            scale = name[1]+".jpg"
        else:
            print("There is no scaleplate to match your picture!!! Please check again.")
        if name[1] == "40" or "100" or "200" or "500":
            im = Image.open(path+i)
            scaleplate = Image.open(scaleplate_path+scale)
            origin_region = im.size
            scaleplate_region = scaleplate.size
            region = []
            region.append(origin_region[0] - scaleplate_region[0])
            region.append(origin_region[1] - scaleplate_region[1])
            im.paste(scaleplate, region)
            im.save(path+"c_"+i)
            print("Finish",i)
    else:
        print("Please check the name of pictures:",i)
        print("Format: name_100_number")
print("Work done!")
os.system('pause')

Format of photos:

name_100_number e.g. test_100_1.bmp
Last modified: 2020年3月30日

Comments

U R St rong!

Write a Reply or Comment

Your email address will not be published.