colour-demosaicing icon indicating copy to clipboard operation
colour-demosaicing copied to clipboard

Default convolution mode introduces edge effects

Open maaleske opened this issue 7 years ago • 3 comments

The default image extension mode used in scipy.ndimage.convolve is 'reflect', which reflects the image about the edge of the pixels. This introduces artefacts in the edge of the resulting RGB layers when demosaicing:

# Constant ones as image
orig = np.ones((2,2)) 
R, G, B = demosaicing_CFA_Bayer_bilinear(orig)

# R, G and B should also be constant 1 (at least in the measured pixels), but instead
# R: [[2.25, 0.75], G: [[0.5, 1.5], B: [[0.25, 0.75],
#     [0.75, 0.25]]     [1.5, 0.5]]     [0.75, 2.25]]

Passing mode='mirror' - which reflects about pixel centers (doesn't repeat the edge values) - to convolve in demosaicing_CFA_Bayer_bilinear returns the expected values. I figure this should be the default for demosaicing?

maaleske avatar Sep 18 '18 11:09 maaleske

Hi @maaleske,

I think this is a good point, basically going from:

d c b a | a b c d | d c b a

to

d c b | a b c d | c b a

Let's do it! I saw that #9 is breaking and I'm a bit unsure why, I will kick a fresh build of develop to see.

KelSolaar avatar Sep 20 '18 06:09 KelSolaar

So yeah, develop builds, not sure what is happening in your branch, I will have to pull it down.

KelSolaar avatar Sep 20 '18 07:09 KelSolaar

There is probably something silly wrong in the tests I wrote. I haven't yet been able to run the test suite myself as I'm having trouble getting OpenImageIO to work. However, I also think that the reason the existing tests are failing because they are testing against images that have this exact issue (demosaiced using the reflected padding). I'm actually wondering whether any demosaicing codes deal with this issue.

maaleske avatar Sep 20 '18 08:09 maaleske