japs / astrotools

Some tools to process astrophotography images.
GNU General Public License v3.0
3 stars 1 forks source link

Simplification #1

Closed letmaik closed 9 years ago

letmaik commented 9 years ago

Hi! I'm the author of lensfunpy and rawpy. Thanks for using my libraries! :) If you have any questions, comments, feature requests etc. let me know.

Just wanted to say that in def raw_to_nparray of astro_develop.py you can also simply write:

return raw_img.postprocess(DCRAW_DEFAULT_PARAMS)
japs commented 9 years ago

Hi! I was actually looking for a way to contact you just yesterday. Thanks for the advice, I will surely implement it!

I do have a question/feature request: it would be nice to be able to modify the content of RawPy.raw_image. This would allow to e.g. subtract a noise pattern directly from the Bayer pattern, before demosaicing takes place. I noticed that RawPy.raw_image is readonly, and despite poking around your cython code, as well as libraw's code, I couldn't figure out how hard it would be to modify this behaviour. An workaround would be to provide an interface to feed the Bayer pattern data directly to the demosaicing algorithms, bypassing any class. Were this possible, another cool feature would be to have a floating point output instead of the standard 8/16 bit one.

I am aware that possibly nothing of what I said is contemplated by libraw, but since you asked... what do you think?

Thanks for your wrapper!

letmaik commented 9 years ago

Actually, raw_image is writeable, I write on that data to correct hot pixels myself. The interpolation algorithms (invoked through postprocess() or like you did) work exactly on that modified data. The wrapper is a direct view on the C array managed by libraw. Have a look at https://github.com/neothemachine/rawpy/blob/master/rawpy/enhance.py#L229 for example, this writes directly to the raw data, here on raw_image_visible but that's just another view which only covers the visible parts of the bayer image.

So in summary: you have to make sure to directly operate on that array, and not reassign it with new data. So instead of raw.raw_image = raw.raw_image - noise_image, just do raw.raw_image -= noise_image.

Floating point output is really a limitation of libraw, I don't think it will be implemented soon. But maybe you can actually live with the slight rounding during interpolation, not sure if this is a problem with astronomical images.

PS: In general, don't hesitate opening issues in the rawpy/lensfunpy repos for such things.

japs commented 9 years ago

Ok, i think when I tried, I just fired up ipython3 and did

raw.raw_image = raw.raw_image - noise_image

I'll follow your advice and learn from your code!

As for the data type, soon after demosaicing, my data is converted into floating point and brought back to 16-bit tiff only at the very last step. I'm quite new to astrophotography, but I'm dealing with such low signal to noise ratio that even that rounding error could add up to seeing some extra detail.

By the way, for what I've seen in libraw code, demosaicing works on float32 and converts back to int8/16, so one day I think I'll try to isolate those functions.

Greetings from Pisa.