Mimic Color Blindness with FFMpeg and IM
In earlier posts, I have used color scales to represent images in false color or data sets. They typically followed what was available in the tools I used. As it turns out, those color scales took into account color blindness that affects a large portion of people.
In this post, I’ll be using FFMpeg and Imagemagick to approximate the effect of what types of color blindness are like. I’ll be covering 3 main types, Protanopia, Deuteranopia, and Tritanopia.
These IM commands were used against a color bar pattern typically used for testing a NTSC TV screen.
# Protanopia # This 3×3 matrix reweights the red, green, and blue channels so that red contributions are less prominent, approximating a protanopic view. convert colorbars.jpeg -color-matrix "0.567 0.433 0 0.558 0.442 0 0 0.242 0.758" output_protanopia.png
# Deuteranopia # Here the matrix shifts the balance between red and green channels, making greens less distinct to mimic deuteranopia. convert colorbars.jpeg -color-matrix "0.625 0.375 0 0.700 0.300 0 0 0.300 0.700" output_deuteranopia.png
# Tritanopia # This transformation reduces the influence of blue light while adjusting the green channel, simulating a tritanopic view. convert colorbars.jpeg -color-matrix "0.950 0.050 0 0 0.433 0.567 0 0.475 0.525" output_tritanopia.png
The FFMpeg commands follow a similar logic when shifting colors in the RGB set. The following code was used to generate the 3 types of color blindness based on a source video.
# Protanopia ffmpeg -i MINI0038_Full_Stab.MOV -vf "colorchannelmixer=rr=0.567:rg=0.433:rb=0:gr=0:gg=0.558:gb=0.442:br=0:bg=0.242:bb=0.758" MINI0038_Full_Stab_protanopia.MOV # Deuteranopia ffmpeg -i MINI0038_Full_Stab.MOV -vf "colorchannelmixer=rr=0.625:rg=0.375:rb=0:gr=0:gg=0.700:gb=0.300:br=0:bg=0.300:bb=0.700" MINI0038_Full_Stab_deuteranopia.MOV # Tritanopia ffmpeg -i MINI0038_Full_Stab.MOV -vf "colorchannelmixer=rr=0.950:rg=0.050:rb=0:gr=0:gg=0.433:gb=0.567:br=0:bg=0.475:bb=0.525" MINI0038_Full_Stab_tritanopia.MOV
The following video is tiled displaying all examples. The source video in the upper left, protanopia in the upper right, deuteranopia in the lower left, and tritanopia in the lower right.
Here is the code used to generate the video above.
ffmpeg -i "MINI0038_Full_Stab.MOV" -vf "[in] scale=iw:ih, pad=2*iw:ih [left];movie=MINI0038_Full_Stab_protanopia.MOV, scale=iw:ih [right]; [left][right] overlay=main_w/2:0 [out]" "SideBySide_Top.MOV" ffmpeg -i "MINI0038_Full_Stab_deuteranopia.MOV" -vf "[in] scale=iw:ih, pad=2*iw:ih [left];movie=MINI0038_Full_Stab_tritanopia.MOV, scale=iw:ih [right]; [left][right] overlay=main_w/2:0 [out]" "SideBySide_Bottome.MOV" ffmpeg -i "SideBySide_Top.MOV" -vf "pad=iw:2*ih [top]; movie=SideBySide_Bottome.MOV [bottom]; [top][bottom] overlay=0:main_h/2" "Tiled_4_Camera_View.MOV" ffmpeg -i Tiled_4_Camera_View.MOV -vf "scale=iw*.25:ih*.25" Tiled_4_Camera_View_DownScaled.MOV
This video provides and interesting anthropological view of color vision.