-
Notifications
You must be signed in to change notification settings - Fork 0
/
rot_im.py
78 lines (58 loc) · 1.47 KB
/
rot_im.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sys
import os
import numpy as np
#import cv2
from astropy.io import fits
from astropy.stats import sigma_clipped_stats
from scipy import ndimage
from scipy.misc import imsave
#Load input image
arg = sys.argv
fname = arg[1]
step = int(float(arg[2]))
flip_choice = arg[3]
name = os.path.splitext(fname)[0]
print fname
# Read fits
def readFITS(fname):
hdu_list = fits.open(fname) # Load the file
image_data = hdu_list[0].data
return image_data
# Clipper function
def clip(data,lim):
data[data<lim] = 0.0
return data
def cut_rot(image,new_width):
new_img = image.copy()
new_height = new_width
width,height = image.shape
left = (width - new_width)/2
top = (height - new_height)/2
right = (width + new_width)/2
bottom = (height + new_height)/2
new_img = new_img[left:right,top:bottom]
return new_img
image_data = readFITS(fname)
img = np.copy(image_data)
idx = np.isnan(img)
img[idx] = 0
# Estimate stats
mean, median, std = sigma_clipped_stats(img, sigma=3.0, iters=10)
for i in range(0,359,step):
rot = ndimage.rotate(img,i, reshape=False)
fname1 = name +'-'+str(i)+'.png'
rot = cut_rot(rot, 150)
# Clip off n sigma points
rot = clip(rot,std*3)
imsave(fname1,rot)
if flip_choice == '1':
print 'Flip version enabled'
# Flipped version
#flpd = cv2.flip(img_clip,0)
flpd = np.fliplr(img)
for i in range(0,359,step):
rot1 = ndimage.rotate(flpd,i)
fname1 = name +'-flip-'+str(i)+'.png'
rot1 = cut_rot(rot1, 150)
rot1 = clip(rot1,std*3)
imsave(fname1,rot1)