Last active
April 29, 2016 04:41
-
-
Save MizukiSonoko/56a0cbfff3fcfae743ebab3918e17cc4 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
# -*- coding: utf-8 -*- | |
#星のデータの読み込み | |
import csv | |
def read_constellation(filename): | |
with open(filename, 'r') as f: | |
reader = csv.reader(f) | |
result = [] | |
for row in reader: | |
number = int(row[0]) | |
ra_hour = float(row[1]) | |
ra_min = float(row[2]) | |
ra_sec = float(row[3]) | |
sign = int(row[4]) | |
dec_deg = float(row[5]) | |
dec_min = float(row[6]) | |
dec_sec = float(row[7]) | |
mag = float(row[8]) | |
A = ra_hour*15 + ra_min/60*15 + (ra_sec/3600)*15 | |
B = dec_deg + dec_min/60 + dec_sec/3600 | |
if (sign == 0): | |
B *= -1 | |
obj={} | |
obj["hipid"] = number | |
obj["mag"] = mag | |
obj["ra"] = A | |
obj["dec"] = B | |
if mag < 4: | |
result.append(obj) | |
return result |
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
# -*- coding: utf-8 -*- | |
from PIL import Image | |
#import Image | |
import cv2 | |
import random | |
import numpy as np | |
from make_star_image import make_star_image | |
#入力ベースマップ | |
#作りたい元の画像 | |
# 出力星の数 | |
def scanstars(stars,img,scale): | |
width, height = img.shape[:2] | |
ratio = 10.0*scale/width | |
x = random.random() * 360 | |
y = random.random() * 180 - 90.0 | |
akari = cv2.resize(img,(int(height*ratio),int(width*ratio))) | |
mask = akari[:,:,3] | |
#mask = akari[0:height,0:width,3] | |
mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR) | |
mask = mask / 255.0 | |
mask = np.uint8(mask) | |
out_img = make_star_image(stars) | |
cv2.imwrite('tmp.png', out_img) | |
img = Image.open('akari.png', 'r') | |
img2 = Image.open('tmp.png', 'r') | |
canvas = Image.new('RGB', ( height, width), (255, 255, 255)) | |
w, h = img.size | |
img.thumbnail((w/4, h/4), Image.ANTIALIAS) | |
canvas.paste( img2, (0, 0)) | |
canvas.paste( img, (int(x), int(y))) | |
# 保存 | |
canvas.save('result.png', 'PNG', quality=100, optimize=True) | |
#img = cv2.imread("tmp.png") | |
#cv2.imwrite('my_with_akarin.png', res) | |
#return | |
#out_img[0:height, 0:width] *= (1 - mask) | |
#out_img[0:height, 0:width] += akari * mask | |
#cv2.imwrite('star_with_akari.png', out_img) | |
#print random.random() | |
#print random.uniform(1,2) | |
#print random.randint(1,100) | |
#print random.choice("123456789abcdefghij") | |
#sample_list = ["python","izm","com","random","sample"] | |
#random.shuffle(sample_list) |
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
# -*- coding: utf-8 -*- | |
from constellation import read_constellation | |
from make_star_image import make_star_image | |
from scanstars import scanstars | |
import cv2 | |
#星のデータの読み込み | |
stars = read_constellation('some.csv') | |
# 与えた画像とベースマップから星のデータ数を取得する | |
img = cv2.imread('akari.png',-1) | |
scale = 5.0 | |
n = scanstars(stars,img,scale) | |
#make_star_image(stars, "stars.png") |
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
# -*- coding: utf-8 -*- | |
import cv2 | |
import random | |
import numpy as np | |
from make_star_image import make_star_image | |
#入力ベースマップ | |
#作りたい元の画像 | |
# 出力星の数 | |
def scanstars(stars,img,scale): | |
width, height = img.shape[:2] | |
ratio = 10.0 * scale / width | |
x = random.random() * 360 | |
y = random.random() * 180 - 90.0 | |
akari = cv2.resize(img,(int(height*ratio),int(width*ratio))) | |
mask = akari[:,:,3] | |
mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR) | |
mask = mask / 255.0 | |
out_img = make_star_image(stars) | |
out_img = np.float64( cp.deepcopy(out_img) ) | |
out_img[0:height:, 0:width] *= (1 - mask) | |
# out_img[0:height:, 0:width] += akari * mask | |
# cv2.imwrite('star_with_akari.png', out_img) | |
#print random.random() | |
#print random.uniform(1,2) | |
#print random.randint(1,100) | |
#print random.choice("123456789abcdefghij") | |
#sample_list = ["python","izm","com","random","sample"] | |
#random.shuffle(sample_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment