Home > other >  RGGB (x,y) --> RGB = (x/2,y/2,3)
RGGB (x,y) --> RGB = (x/2,y/2,3)

Time:12-27

The output of a camerasensor is SRGGB12.

  import numpy as np

    rggb = np.array([['R', 'G', 'R', 'G'],
                     ['G', 'B', 'G', 'B'],
                     ['R', 'G', 'R', 'G'],
                     ['G', 'B', 'G', 'B']])
    
    
    test2 = np.chararray((3, 4, 4))
    test2[:] = ''
    test2[2,::2, ::2] = rggb[1::2, 1::2]  # blue
    test2[1,1::2, ::2] = rggb[0::2, 1::2]  # green
    test2[1,::2, 1::2] = rggb[1::2, 0::2]  # green
    test2[0,1::2, 1::2] = rggb[0::2, 0::2]  # red
    print(test2)

>>
    [[['' '' '' '']
      ['' b'R' '' b'R']
      ['' '' '' '']
      ['' b'R' '' b'R']]
    
     [['' b'G' '' b'G']
      [b'G' '' b'G' '']
      ['' b'G' '' b'G']
      [b'G' '' b'G' '']]
    
     [[b'B' '' b'B' '']
      ['' '' '' '']
      [b'B' '' b'B' '']
      ['' '' '' '']]]
    (3, 4, 4)

Now I would like to delete/trim all of the empty entries. In the example the rggb array was 4x4. The wanted matrice should be (3,2,2).

Thats the function, which needs to be adjusted accordingly:

def conver_rggb_to_rgb(rggb):

  ret_arr = np.zeros((rggb.shape[0]//2, rggb.shape[1]//2, 3)).astype(np.uint16)

  blue = rggb[1::2, 1::2]    # blue
  green1 = rggb[0::2, 1::2]  # green
  green2 = rggb[1::2, 0::2]  # green
  red = rggb[0::2, 0::2]     # red

  ret_arr[:,:,0] = red
  ret_arr[:,:,1] = (green1   green2)/2
  ret_arr[:,:,2] = blue

  return ret_arr

idea

CodePudding user response:

def conver_rggb_to_rgb(rggb):

     ret_arr = np.zeros((rggb.shape[0]//2,rggb.shape[1]//2,3)).astype(np.uint16)
     blue = rggb[1::2, 1::2]    # blue
     green1 = rggb[0::2, 1::2]  # green
     green2 = rggb[1::2, 0::2]  # green
     red = rggb[0::2, 0::2]     # red

     ret_arr[0] = ret_arr[0]   red
     ret_arr[1] = ret_arr[1]   (green1   green2)/2
     ret_arr[2] = ret_arr[2]   blue

     return ret_arr

CodePudding user response:

import numpy as np

def convert_rggb_to_rgb(rggb):

 ret_arr = np.zeros((3,rggb.shape[0]//2,rggb.shape[1]//2)).astype(np.uint16)
 blue = rggb[1::2, 1::2]    # blue
 green1 = rggb[0::2, 1::2]  # green
 green2 = rggb[1::2, 0::2]  # green
 red = rggb[0::2, 0::2]     # red

 ret_arr[0] = ret_arr[0]   red
 ret_arr[1] = ret_arr[1]   (green1   green2)/2
 ret_arr[2] = ret_arr[2]   blue

 return ret_arr

e.g.:

x=2032
y=1520
Megapixel = x*y
rggb = np.zeros(Megapixel).reshape(2032,1520) 

test = convert_rggb_to_rgb(rggb)
print(test.shape)

Output >>>

(3,1016,760)
  • Related