What Is Color Matrix In Rawpy Object?
Solution 1:
A color-matrix like this:
AB C D
E F G H
I J K L
normally means you calculate the new Red value (Rn), new Green value (Gn) and new Blue value (Bn) from the old Red (Ro), old Green (Go) and old Blue (Bo) like this:
Rn = A*Ro + B*Go + C*Bo + D
Gn = E*Ro + F*Go + G*Bo + H
Bn = I*Ro + J*Go + K*Bo + L
D
, H
and L
are just constant "offsets".
Let's do an example with this image:
So, if you want to swap the Red and Blue channels and make the Green channel into solid 64 you could do this:
#!/usr/bin/env python3
from PIL import Image
# Open image
im = Image.open('start.jpg')
# Define color matrix to swap the red and blue channels andset green to absolute 64
# This says:
# New red =0*old red +0*old green +1*old blue +0offset
# New green =0*old red +0*old green +0*old blue +64offset
# New blue =1*old red +0*old green +0*old blue +0offset
Matrix = ( 0, 0, 1, 0,
0, 0, 0, 64,
1, 0, 0, 0)
# Apply matrix and save
result= im.convert("RGB", Matrix).save('result.png')
Coming to your specific matrix now... The values for F
and K
in your matrix are nearly 1
so, your matrix is performing minimal changes to the Green and Blue channel. However, it is deriving the new Red channel quite heavily from the existing Green channel because B=0.57969594
and the other entries on that first row are low.
Keywords: Python, image processing, Color-matrix, colour matrix, swap channels.
Post a Comment for "What Is Color Matrix In Rawpy Object?"