Ask Your Question
0

How to apply noise in frames video ?

asked 2018-06-21 12:13:44 -0600

azdoud.y gravatar image

updated 2020-10-05 05:22:38 -0600

Hello,

I have seen the video of Megamind.avi and it noisy version Megamind_bugy.avi you can find them within OpenCV directory opencv/samples/data/

I want to apply the same noise on my list of video as well to test my code

thank you

edit retag flag offensive close merge delete

Comments

2

that's not exactly "noise", but random (rotated) rectangle overlays.

for "salt&pepper" noise, look at cv::randu() / cv::randn()

berak gravatar imageberak ( 2018-06-21 12:16:48 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-06-21 18:10:33 -0600

sjhalayka gravatar image

updated 2018-06-21 18:11:31 -0600

A code to take a 2D mat of type CV_32FC1 and add noise to it:

void add_noise(Mat &mat, float scale)
{
    for (int j = 0; j < mat.rows; j++)
    {
        for (int i = 0; i < mat.cols; i++)
        {
            float noise = static_cast<float>(rand() % 256);
            noise /= 255.0f;

            mat.at<float>(j, i) = (mat.at<float>(j, i) + noise*scale) / (1.0f + scale);

            if (mat.at<float>(j, i) < 0)
                mat.at<float>(j, i) = 0;
            else if (mat.at<float>(j, i) > 1)
                mat.at<float>(j, i) = 1;
        }
    }
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-06-21 12:13:44 -0600

Seen: 404 times

Last updated: Jun 21 '18