Fujifilm Pattern with rawpy

Hello,

I am trying to extract channel by channel pixel values of a X-Pro2. For detector calibration purpose (educational).
I do not understand the color pattern returned by the library (or is it rawpy ?).

   >>> rawpy.libraw_version
  (0, 18, 2)
   >>> im = rawpy.imread("20170728-DSCF3470.RAF")
   >>> im.raw_pattern
   array([[1, 2, 1, 2, 1, 2],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0]], dtype=uint8)

Same thing with im.raw_colors.
However looking at a grey scale raw_image it is obvious that the (non-bayer) pattern is not has indicated.
Maybe it is a feature of rawpy and not libraw ?
Any clues?

S.

Forums: 

Looks like rawpy

Looks like rawpy incompleteness.

For X-Trans sensors (imgdata.idata.filters == 9), color pattern is contained in
imgdata.idata.xtrans (6x6 array, indexed by row%6,col%6, row and col are relative to visible area)
and in
imgdata.idata.xtrans_abs (same as above, but row/col are relative to full sensor)

-- Alex Tutubalin @LibRaw LLC

int LibRaw::COLOR(int row, int col)

Hi Alex,
I'm the rawpy developer and just had a look at this. I'm using LibRaw::COLOR(row, col) to construct the color pattern matrix, which works fine for non-x-trans images. But for x-trans any value after the first row returns 0. so ::COLOR(1, 0) is 0, as well as ::COLOR(1,1) is 0. I'm using libraw 0.18.2 currently and noticed some x-trans related changes in newer versions: https://github.com/LibRaw/LibRaw/compare/0.18.2...0.18.5 But they seem to be related to security only.
My test image is: http://img.photographyblog.com/reviews/fujifilm_x_t1/photos/fujifilm_x_t...
Can you check whether the COLOR method works correctly here? I think there may be a problem.
Thanks!
Maik

OK, looks like over

OK, looks like over-optimization in COLOR:

  int COLOR(int row, int col)
  {
    return libraw_internal_data.internal_output_params.fuji_width ? FCF(row, col) : FC(row, col);
  }
  int FC(int row, int col) { return (imgdata.idata.filters >> (((row << 1 & 14) | (col & 1)) << 1) & 3); }
  int fcol(int row, int col);

where FCF() is for 'fuji-rotated' images (S5 Pro, etc).

It should be

  int COLOR(int row, int col)
  {
    return imgdata.idata.filters < 1000 ? fcol(row,col): (libraw_internal_data.internal_output_params.fuji_width ? FCF(row, col) : FC(row, col));
  }

To be fixed in 0.19 (0.18 is security-only-patches now)

-- Alex Tutubalin @LibRaw LLC

Finally: it is fixed in

Finally: it is fixed in LibRaw 0.19 (now in beta): COLOR() will check xtrans mask for xtrans files.

-- Alex Tutubalin @LibRaw LLC