letmaik / rawpy

📷 RAW image processing for Python, a wrapper for libraw
https://pypi.python.org/pypi/rawpy
MIT License
613 stars 68 forks source link

Question: if I want to subtract a manual dark image, how? #40

Closed graeme-winter closed 6 years ago

graeme-winter commented 6 years ago

I have constructed a numpy array of a dark image, from the raw_image values, and want to apply this to the data image before postprocess - however I get:

AttributeError: attribute 'raw_image' of 'rawpy._rawpy.RawPy' objects is not writable

trying to:

    black = raw.black_level_per_channel
    assert black[0] == black[1] == black[2] == black[3]
    help(raw)
    raw.raw_image += black[0]
    raw.raw_image -= dark

here the += black[0] is to ensure value stays positive as all data are type uint16 i.e. keep standard black value...

Any help much appreciated!

graeme-winter commented 6 years ago

Solved myself - should have remembered numpy array syntax:

    raw.raw_image[:,:] = raw.raw_image + black[0] - dark
letmaik commented 6 years ago

Good that you solved it. If dark is also just a scalar, then you can simply do:

raw.raw_image[:] += black[0] - dark
graeme-winter commented 6 years ago

Dark here is an array of same size as raw_image.

You have a place where things like this could be documented? I am happy to do so...

letmaik commented 6 years ago

Currently the place for more tutorial-like examples would be https://github.com/letmaik/rawpy-notebooks. There's no place currently for shorter code snippets. So, if you have a nice use case that involves modifying the raw bayer data, then that could become a Jupyter notebook. Before starting on that, please open an issue in that repo to discuss what it is about and whether it fits.