Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Algorithm:
- Read the original image.
- Separate the original matrix/image in to 3 matrices: R,G,B
- Odd Row, Odd Column = B
- Odd Row, Even Column = R
- Even Row, Odd Column = R
- Even Row, Even Column = G
- generate---
- Each of these 3 new matrices is missing pixel data
- (where the other colours used to be) so use kernels
- to fill in missing data.
- *Note: In order to prevent addition overflow (>255), normalize the
- kernel values so their total sum is 1.
- * Also note: The kernel is only applied to pixels where data is missing. No need to colour in pixels that are already coloured.
- There are 4 possible pixel layouts, so eight 3X3 Kernels are needed:
- 1)
- RGR
- BRB
- RGR
- 1b) Kernel to colour centre Blue: {(0,0,0),(0.5,0,0.5),(0,0,0)}
- 1g) Kernel to colour centre Green: {(0,0.5,0),(0,0,0),(0,0.5,0)}
- 2)
- GRG
- RBR
- GRG
- 2r) Kernel to colour centre Red: {(0,0.25,0),(0.25,0,0.25),(0,0.25,0)}
- 2g) Kernel to colour centre Green: {(0.25,0,0.25),(0,0,0),(0.25,0,0.25)}
- 3)
- BRB
- RGR
- BRB
- 3b) Kernel to colour centre Blue: {(0.25,0,0.25),(0,0,0),(0.25,0,0.25)}
- 3r) Kernel to colour centre Red: {(0,0.25,0),(0.25,0,0.25),(0,0.25,0)}
- 4)
- RBR
- GRG
- RBR
- 4b) Kernel to colour centre Blue: {(0,0.5,0),(0,0,0),(0,0.5,0)}
- 4g) Kernel to colour centre Green: {(0,0,0),(0.5,0,0.5),(0,0,0)}
- Note: Some of these kernels are duplicates, so really only 4 kernels are needed:
- i) 1b, 4g -> {(0,0,0),(0.5,0,0.5),(0,0,0)}
- ii) 1g, 4b -> {(0,0.5,0),(0,0,0),(0,0.5,0)}
- iii) 2g, 3b -> {(0.25,0,0.25),(0,0,0),(0.25,0,0.25)}
- iv) 2r, 3r -> {(0,0.25,0),(0.25,0,0.25),(0,0.25,0)}
- This will leave you with 8 separate matrices. Combine the Rs in to a single complete R matrix, combine the Bs in to a complete B matrix, the Gs in to a complete G matrix.
- Then combine these 3 full matrices in to a single 3-channel color image.
- Display.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement