How for me to create gaussian noise to be put into images where the gaussian noise have several level of noise. Eg) i can select 10% until 100% for the level of gaussian noise to be inserted into the images.

Dani AI

Generated

Summary: the goal is to inject Gaussian noise into images with a selectable level (10%–100%). was right to point toward using an image library; gave useful Visual Studio setup hints. Two distinct meanings of “level” should be picked explicitly before implementing: (A) strength — how large the Gaussian standard deviation is relative to the pixel range, and (B) coverage — what fraction of pixels actually get changed. They lead to different code patterns and different visual results.

Approach options (short):

  • Strength mode: pick sigma = level * 255 (for 8‑bit images) or scale sigma by an explicit base value; for each pixel add N(0,sigma) and clamp to [0,255]. This preserves the same noisy texture everywhere but with adjustable intensity.
  • Coverage mode: randomly choose level% of pixel indices and add Gaussian samples only to those pixels. This keeps noise sparse when wanted.
  • Blend mode: compute noise image and add scaled noise: pixel' = clamp(pixel + alpha * noise), where alpha in [0,1] controls the perceived strength without changing sigma semantics.

A compact, robust C++ pattern (uses <random>):

#include <random>
#include <chrono>
#include <cmath>
#include <algorithm>

double gaussian(double mean, double sigma){
  static std::mt19937 rng((unsigned)std::chrono::high_resolution_clock::now().time_since_epoch().count());
  static std::normal_distribution<double> d(0.0, 1.0);
  return mean + sigma * d(rng);
}

unsigned char addNoise(unsigned char px, double sigma, double alpha){
  int v = int(std::round(px + alpha * gaussian(0.0, sigma)));
  return (unsigned char)std::min(255, std::max(0, v));
}

Practical notes and troubleshooting: the sample files must be built (double‑clicking a .cpp just opens it). When using external libraries, ensure the runtime DLLs match the build (x86 vs x64 and Debug vs Release) and are on PATH or beside the executable; also set the program working directory to where sample images live. For color images, add noise per channel or apply noise to luminance to avoid odd color casts.

Recommended Answers

All 5 Replies

The easy way would be to use the OpenCV library which has special function for this.

The easy way would be to use the OpenCV library which has special function for this.

How to use tis OpenCV i had install it but it seems like consist of library file and i had install a OpenCV.exe but i seems like do not knw how to use it. Beside this, is there any others methods

How to use tis OpenCV i had install it but it seems like consist of library file and i had install a OpenCV.exe but i seems like do not knw how to use it.

You install the file and then you read the documentation, or open one of the many example files that came with it.

Beside this, is there any others methods

Yes there are. But if you don't understand how to install OpenCV, I wouldn't start on them...

You install the file and then you read the documentation, or open one of the many example files that came with it.

Yes there are. But if you don't understand how to install OpenCV, I wouldn't start on them...

I already install the opencv and see the sample but i need to copy paste in the dll files which i downloaded. But when i run the code using visual studio it seems like cannot run. What i need to do to run the code?? I nw just double click the code then open in visual studio. Izzit i need to create a new project and copy paste to code to let it run

I'm pretty sure there's oodles of freely available guides available to tell you how to use openCV. Try http://www.google.com/search?hl=en&rls=com.microsoft%3Aen-au&q=opencv+visual-studio

Failing that, I found the following works for me:

Basically what you have to do is set up your project to include the following files:
"c:/Program Files/OpenCV/lib/cv.lib"
"c:/Program Files/OpenCV/lib/cvaux.lib"
"c:/Program Files/OpenCV/lib/cvcam.lib"
"c:/Program Files/OpenCV/lib/cxcore.lib"
"c:/Program Files/OpenCV/lib/cxts.lib"
"c:/Program Files/OpenCV/lib/highgui.lib"
"c:/Program Files/OpenCV/lib/trs.lib"

You'll probably need to specify include file paths:
C:\Program Files\OpenCV\cv\include
C:\Program Files\OpenCV\cvaux\include
C:\Program Files\OpenCV\cxcore\include
C:\Program Files\OpenCV\otherlibs\highgui
C:\Program Files\OpenCV\otherlibs\cvcam\include

You'll may need to specify library file paths:
C:\Program Files\OpenCV\lib

You will need to include some of the following header files:
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.