Fun with OpenCV and DFT IDFT Reads image gets R component then converts to DFT converts back style body height 200px style script src https docs opencv org master opencv js script script cv onRuntimeInitialized console log onRuntimeInitialized console log cv dft typeof cv dft check dft is ready dfttest async function dfttest let imgurl https notebook xbdev net var images pieces jpg let img document createElement img img src imgurl await img decode let src cv imread img let rgbaPlanes new cv MatVector cv split src rgbaPlanes let R rgbaPlanes get 0 new cv Mat let G rgbaPlanes get 1 let B rgbaPlanes get 2 let rect new cv Rect 0 0 128 128 R R roi rect let planeR new cv Mat R convertTo planeR cv CV_32F FORWARD DFT cv dft planeR planeR INVERSE DFT let inverseTransform new cv Mat cv dft planeR inverseTransform cv DFT_INVERSE cv DFT_REAL_OUTPUT cv normalize inverseTransform inverseTransform 0 1 cv NORM_MINMAX show the recovered image let finalImage new cv Mat inverseTransform convertTo finalImage cv CV_8U 255 cv imshow canvas 0 R cv imshow canvas 1 planeR cv imshow canvas 2 finalImage src delete end dfttest debug output three outputs original dft idft let canvas for let i 0 i 3 i canvas i document createElement canvas canvas i style padding 5px canvas i style display inline canvas i width 100 canvas i height 100 document body appendChild canvas i console log ready script Steganography example Convert image to frequency domain using DFT then write some text on the dft image Converting the dft image back into normal space you can t see the hidden writing e g test style body height 200px style script src https docs opencv org master opencv js script script cv onRuntimeInitialized console log onRuntimeInitialized console log cv dft typeof cv dft check dft is ready dfttest async function dfttest let imgurl https notebook xbdev net var images pieces jpg let img document createElement img img src imgurl await img decode let src cv imread img let rgbaPlanes new cv MatVector cv split src rgbaPlanes let R rgbaPlanes get 0 new cv Mat let G rgbaPlanes get 1 let B rgbaPlanes get 2 let rect new cv Rect 0 0 128 128 R R roi rect let planeR new cv Mat R convertTo planeR cv CV_32F FORWARD DFT cv dft planeR planeR cv putText planeR test new cv Point 10 50 cv FONT_HERSHEY_SIMPLEX 2 0 new cv Scalar 0 0 0 2 cv LINE_AA INVERSE DFT let inverseTransform new cv Mat cv dft planeR inverseTransform cv DFT_INVERSE cv DFT_REAL_OUTPUT cv normalize inverseTransform inverseTransform 0 1 cv NORM_MINMAX show the recovered image let finalImage new cv Mat inverseTransform convertTo finalImage cv CV_8U 255 cv imshow canvas 0 R cv imshow canvas 1 planeR cv imshow canvas 2 finalImage src delete end dfttest debug output three outputs original dft idft let canvas for let i 0 i 3 i canvas i document createElement canvas canvas i style padding 5px canvas i style display inline canvas i width 100 canvas i height 100 document body appendChild canvas i console log ready script
mal space you can t see the hidden writing e g test style body height 200px style script src https docs opencv org master opencv js script script cv onRuntimeInitialized console log onRuntimeInitialized console log cv dft typeof cv dft check dft is ready dfttest async function dfttest let imgurl https notebook xbdev net var images pieces jpg let img document createElement img img src imgurl await img decode let src cv imread img let rgbaPlanes new cv MatVector cv split src rgbaPlanes let R rgbaPlanes get 0 new cv Mat let G rgbaPlanes get 1 let B rgbaPlanes get 2 let rect new cv Rect 0 0 128 128 R R roi rect let planeR new cv Mat R convertTo planeR cv CV_32F FORWARD DFT cv dft planeR planeR cv putText planeR test new cv Point 10 50 cv FONT_HERSHEY_SIMPLEX 2 0 new cv Scalar 0 0 0 2 cv LINE_AA INVERSE DFT let inverseTransform new cv Mat cv dft planeR inverseTransform cv DFT_INVERSE cv DFT_REAL_OUTPUT cv normalize inverseTransform inverseTransform 0 1 cv NORM_MINMAX show the recovered image let finalImage new cv Mat inverseTransform convertTo finalImage cv CV_8U 255 cv imshow canvas 0 R cv imshow canvas 1 planeR cv imshow canvas 2 finalImage src delete end dfttest debug output three outputs original dft idft let canvas for let i 0 i 3 i canvas i document createElement canvas canvas i style padding 5px canvas i style display inline canvas i width 100 canvas i height 100 document body appendChild canvas i console log ready script