Giter VIP home page Giter VIP logo

star_alignment's Introduction

Star Alignment

Align several astronomy / nightscape images by star points in images. Apply to wide angle lens as well as tele-lens.

A detailed blog describing the motivation and algorithm can be found at This Site (which is my special column at zhihu.com, of course, in Chinese)

matlab code

Check star_align_average_main.m as the main script.

python code

Check DataModel.py and run it. Need OpenCV, NumPy, SciPy, pywt, Tyf, matplotlib (optional), tifffile be installed. Matplotlib is used for debug, and it makes no difference on result if you remove / comment relevant lines.

WARNING

I use Tyf to handle with metadata of tiff file. But there are bugs on data types that may cause crashes when reading and writing tiff file. I have opened an issue and it is not fixed yet. Relevant lines can be comment out to run the script properly. Or one can correct those issues in sources of Tyf packet (I just did that).

Any suggestion about read and write metadata (exif information) of tiff file is welcome.

Acknowlagements

Some updates by Sean Liu

  • Added Python3 support - and all subsequent changes are only for Python3
  • Added raw support by rawpy
  • Separated command line from DataModel.py
  • The main command line is now alignStar.py
  • python3>python alignStar.py
  • usage: alignStar.py [-h] [-o OUTPUT] [-d] [-k] [-f FOCAL] images [images ...]
  • Forego the writing of exif info to final tiff file as it doesn't seem to work well

星点对齐叠加

对多张星空图片进行星点对齐并叠加,适用于深空、星野图片,适用于长焦、广角拍摄的图片,改正了常见叠加方法无法对齐广角星空的缺点。

在我的知乎专栏《星野摄影降噪(2):对齐叠加》中,对算法思路和细节有详细描述,欢迎讨论。

matlab 代码

脚本 star_align_average_main.m 为主脚本。

python 代码

所有算法都在 DataModel.py 文件中,依赖的第三方包:OpenCV, NumPy, SciPy, pywt, Tyf, matplatlib(可选), tifffile。其中 matplotlib 主要用于调试输出中间图,去掉相关代码对实际功能没有影响。

警告

这里采用了 Tyf 包来处理 tiff 文件的 exif 信息, 但是这个包有几个关于数据格式的小错误,会导致读取 / 写入信息的时候程序崩溃。 我已经在相关仓库下开了 issue,欢迎讨论。 如果遇到崩溃情况,请把 exif 相关 的行都注释掉,应该就可以正确运行了。或者,也可以手动修改 Tyf 的源文件(我就是这么做的)。

如果有人知道其他能够读写 tiff 文件的 metadata 的包,欢迎进行讨论。

感谢

star_alignment's People

Contributors

lovedaisy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

star_alignment's Issues

Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded

get_exif_value 貌似有问题,去掉了
有些小问题

[root@node1 python3]# python3 alignStar.py -f 40  -o /root/align.tiff  /root/f3tiff/*
Final star points = 329
Final star points = 377
Final star points = 305
Final star points = 543
Final star points = 584
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 590
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 579
Final star points = 346
Final star points = 609
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 536
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Done. Output image in  /root/align.tiff
[root@node1 python3]# python3 alignStar.py -f 40  -o /root/f3align.tiff  /root/f3tiff/*
Final star points = 621
Final star points = 377
Final star points = 305
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 543
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 584
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 590
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 329
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 579
Final star points = 346
Final star points = 609
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 536
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 567
Final star points = 307
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 564
Final star points = 563
Final star points = 571
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 540
Final star points = 318
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 582
Final star points = 587
Final star points = 604
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 1022
Traceback (most recent call last):
  File "alignStar.py", line 104, in <module>
    img_tf = cv2.warpPerspective(img.original_image, tf[0], tuple(img_size))
cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-qacpj5ci/opencv/modules/imgproc/src/imgwarp.cpp:3167: error: (-215:Assertion failed) (M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 3 && M0.cols == 3 in function 'warpPerspective'

[root@node1 python3]# python3 alignStar.py -f 40  -o /root/f3align.tiff  /root/f3tiff/*
Final star points = 621
Final star points = 377
Final star points = 305
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 543
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 584
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 590
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 329
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 579
Final star points = 346
Final star points = 609
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 536
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 567
Final star points = 307
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 564
Final star points = 563
Final star points = 571
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 540
Final star points = 318
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 582
Final star points = 587
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 604
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 1022
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 1022
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 730
Final star points = 542
Traceback (most recent call last):
  File "alignStar.py", line 103, in <module>
    tf, pair_idx = DataModel.ImageProcessing.fine_tune_transform(img.features, ref_img.features, pair_idx)
  File "/root/star_alignment/python3/DataModel.py", line 509, in fine_tune_transform
    pts12 = cv2.perspectiveTransform(np.array([[p] for p in feature1["pts"]], dtype="float32"), tf[0])[:, 0, :]
cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-qacpj5ci/opencv/modules/core/src/matmul.dispatch.cpp:531: error: (-215:Assertion failed) scn + 1 == m.cols in function 'perspectiveTransform'

[root@node1 python3]# python3 alignStar.py -f 40  -o /root/f3align.tiff  /root/f3tiff/*
Final star points = 621
Final star points = 377
Final star points = 305
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 543
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 584
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 590
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 329
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 579
Final star points = 346
Final star points = 609
Final star points = 536
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 567
Final star points = 307
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 564
Final star points = 563
Final star points = 571
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 540
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 318
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 582
Final star points = 587
Final star points = 604
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 1022
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 1022
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 730
Final star points = 542
Traceback (most recent call last):
  File "alignStar.py", line 103, in <module>
    tf, pair_idx = DataModel.ImageProcessing.fine_tune_transform(img.features, ref_img.features, pair_idx)
  File "/root/star_alignment/python3/DataModel.py", line 509, in fine_tune_transform
    pts12 = cv2.perspectiveTransform(np.array([[p] for p in feature1["pts"]], dtype="float32"), tf[0])[:, 0, :]
cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-qacpj5ci/opencv/modules/core/src/matmul.dispatch.cpp:531: error: (-215:Assertion failed) scn + 1 == m.cols in function 'perspectiveTransform'

[root@node1 python3]# 


去掉几张图片后:
[root@node1 python3]# python3 alignStar.py -f 40  -o /root/f3align.tiff  /root/f3tiff/*
Final star points = 600
Final star points = 377
Final star points = 305
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 543
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 584
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 590
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 329
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 579
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 346
Final star points = 609
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 536
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 567
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 307
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 564
Final star points = 563
Final star points = 571
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 540
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 318
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 582
Final star points = 587
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 604
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 1022
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 1022
Alignment failed for this picture: Optimal alignment cannot be achieved. . Discarded
Final star points = 730
Final star points = 529
Final star points = 582
Final star points = 590
/root/star_alignment/python3/DataModel.py:481: RuntimeWarning: invalid value encountered in arccos
  theta = np.arccos(np.sum(xyz1[pair_idx[:, 0]] * xyz2[pair_idx[:, 1]], axis=1))
Alignment failed for this picture: attempt to get argmin of an empty sequence . Discarded
Final star points = 621
Alignment failed for this picture: attempt to get argmin of an empty sequence . Discarded
Final star points = 614
Final star points = 624
Alignment failed for this picture: attempt to get argmin of an empty sequence . Discarded
Final star points = 631
Alignment failed for this picture: attempt to get argmin of an empty sequence . Discarded
Final star points = 624
Alignment failed for this picture: attempt to get argmin of an empty sequence . Discarded
Final star points = 605
Final star points = 604
Final star points = 596
Final star points = 607
Alignment failed for this picture: attempt to get argmin of an empty sequence . Discarded
Final star points = 559
Final star points = 592
Alignment failed for this picture: attempt to get argmin of an empty sequence . Discarded
Final star points = 615
Final star points = 602
Final star points = 611
Final star points = 601
Final star points = 588
Final star points = 607
Final star points = 601
Final star points = 605
Final star points = 599
Final star points = 607
Final star points = 615
Final star points = 615
Final star points = 621
Final star points = 637
Final star points = 645
Final star points = 627
Done. Output image in  /root/f3align.tiff


Feature descriptor

请问一下在哪里可以找到feature descriptor的解释?看上去与正态分布的函数很相近但是看不太明白。谢谢。

    fx = np.arange(-np.pi, np.pi, 3 * np.pi / 180)
    features = np.zeros((pts_num, len(fx)))
    for i in range(k):
        sigma = 2.5 * np.exp(-rho_feature[:, i] * 100) + .04
        tmp = np.exp(-np.subtract.outer(theta_feature[:, i], fx) ** 2 / 2 / sigma[:, np.newaxis] ** 2)
        tmp = tmp * (vol_feature[:, i] * rho_feature[:, i] ** 2 / sigma)[:, np.newaxis]
        features += tmp

    features = features / np.sqrt(np.sum(features ** 2, axis=1)).reshape((pts_num, 1))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.