Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Generating Gaussian Noise in OpenCV Mat Image using QT
Forum Update on Monday, May 27th 2025

Generating Gaussian Noise in OpenCV Mat Image using QT

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Titas93
    wrote on 24 Jan 2014, 06:46 last edited by
    #1

    Hi Everyone! I have been trying to add Additive White Gaussian Noise in my Mat image(Using Qt 5.2.0) using the following piece of code, but i am getting the original image only. No noise is being added! Please can anyone help me by telling where I am going wrong!

       @        cv::Mat gaussianD;
        cv::Mat gaussian = grImage.clone();
        gaussian.convertTo(gaussianD, CV_32F);
        cv::Mat mult = cv::Mat::zeros(grImage.rows, grImage.cols, CV_32F);
        cv::randn(mult, 0, ui->doubleSpinBox_sDev->value());
        gaussianD = gaussianD + sqrt(ui->doubleSpinBox_sDev->value())*mult;
        gaussianD.convertTo(gaussianD, CV_8U);
        cv::namedWindow("Gaussian Noise");
        cv::imshow("Gaussian Noise", gaussianD);
        cv::imwrite("gaussian.jpg", gaussianD);
        gauss.load("gaussian.jpg");
        ui->label_NoiseImg->setPixmap(QPixmap::fromImage(gauss.scaled(ui->label_NoiseImg->size(), Qt::KeepAspectRatio)));@
    

    Here grImage is my original grayscale image, double spinbox s_Dev gives the value of the variance defined by the user, and mult is the array of gaussian random nos.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Jan 2014, 08:31 last edited by
      #2

      Hi and welcome to devnet,

      does your namedWindow show the correct image ?

      If not, you should first check your OpenCV code

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Titas93
        wrote on 24 Jan 2014, 11:21 last edited by
        #3

        Thanks for the reply SGaist,
        I have been using the same code for namedwindow in the entire project and it shows the correct image, so i don't think dats the problem! My guess is that the noise which is being infused in the image is too small to really have any effect on the final image, but why is that happening i dont know! Any suggestions or help is utmost welcome!

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 24 Jan 2014, 20:32 last edited by
          #4

          Jpeg compression ? Try to save your image in an uncompressed format

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          24 Jan 2014, 06:46

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved