Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Added color function and updated bayer_data function #114

Merged
merged 1 commit into from Feb 19, 2016

Conversation

campaul
Copy link
Member

@campaul campaul commented Jan 10, 2016

Changing things up a little because we made some mistakes the first time around. cdesc doesn't actually reflect color order, and in fact can't for sensors with non-standard pattern sizes. Instead you're supposed to use the libraw_COLOR to get the color of a specific pixel. I have added the Raw.color method to address this, and removed cdesc from the bayer_data function because it wasn't used for what we thought it was. Now you would use the code something like this:

from rawkit.raw import Raw


with Raw(filename='some_file.CR2') as raw:

    bayer_data = raw.bayer_data()

    row = 100
    col = 100

    print('pixel value is %s.' % bayer_data[row][col])
    print('pixel color is %s.' % raw.color(row, col))

This would give you output like:

pixel value is 5725.
pixel color is R.

@campaul
Copy link
Member Author

campaul commented Jan 10, 2016

Fixes #113

@KelSolaar
Copy link

I haven't tried the code yet but having to pass the pixel coordinates to get the CFA mask smells like huge performance hit. I guess that for periodic Bayer CFA one could access the 2 first rows 2 first pixels and from there assume the mask is tiling.

@campaul
Copy link
Member Author

campaul commented Jan 10, 2016

I've been operating under the assumption that the libraw COLOR function (which is the recommended way to get the color of a pixel) handled all the special cases like X-Trans sensors. This is not the case, and that function only seems to operate correctly for traditional 2x2 bayer sensors. I'm going to do more research tomorrow to verify, but if I'm right about the COLOR function I'll switch to generating a 2x2 array (or 1x4 if people prefer that) and returning it with the get_bayer_data function.

@campaul
Copy link
Member Author

campaul commented Jan 12, 2016

Second attempt. Now the bayer_data function returns the bayer data and color filter array. This currently only works for traditional bayer sensors, but will be expanded to handle other sensors as I get around to reading all the special cases in libraw. Code looks something like this:

from rawkit.raw import Raw

with Raw(filename='somefile.CR2') as raw:
    bayer_data, cfa = raw.bayer_data()

    # cfa is a 2x2 array
    cfa[0][0] = 'R'
    cfa[0][1] = 'G'
    cfa[1][0] = 'G'
    cfa[1][1] = 'B'

@KelSolaar what are your thoughts on this approach?

@KelSolaar
Copy link

Looks good to me, although I'm biased because I exclusively work with Bayer CFA cameras (Canon & Nikon) :)

@campaul
Copy link
Member Author

campaul commented Jan 12, 2016

As I expand this function it will benefit everyone. For example if you have an X-Trans sensor you will get back a 6x6 array instead. What I really want to know is if returning an MxN array is what is most useful. I personally like it because it makes it consistent with the format of the bayer data array.

campaul added a commit that referenced this pull request Feb 19, 2016
Added color function and updated bayer_data function
@campaul campaul merged commit ede197a into master Feb 19, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants