-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimage_calibration.py
35 lines (26 loc) · 1.07 KB
/
image_calibration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import argparse
import numpy as np
from PIL import Image
from skimage.transform import rescale
import pandas as pd
def main(prefix):
with open(prefix + 'pixel-size-raw.txt', 'r') as file:
raw_pix_size = float([line.rstrip() for line in file][0])
scale_pix_size = 0.5
scale = raw_pix_size / scale_pix_size
loc = pd.read_csv(prefix+'locs-raw.csv', header=0, index_col=0)
loc = loc * scale
loc = loc.round().astype(int)
loc.columns = ['x', 'y']
loc.to_csv(prefix+'locs.csv')
img = np.array(Image.open(prefix+'he-raw.jpg'))
img = rescale(img, [scale, scale, 1], preserve_range=True)
img = img.astype(np.uint8)
H, W, _ = img.shape
img = img[:H // 224 * 224, :W // 224 * 224]
Image.fromarray(img).save(prefix+'he.jpg')
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Process images and locs with a given prefix.")
parser.add_argument('--directory', type=str, help="The prefix for input/output files")
args = parser.parse_args()
main(args.directory)