34 const std::string TYPE_POISSON =
"poisson";
48 addUsageLine(
"Noise can be generated using uniform, gaussian or t-student distributions.");
52 addParamsLine(
" gaussian <stddev> <avg=0.> :Gaussian distribution parameters");
53 addParamsLine(
" student <df> <stddev> <avg=0.> :t-student distribution parameters");
54 addParamsLine(
" uniform <min> <max> :Uniform distribution parameters");
55 addParamsLine(
" " + TYPE_POISSON +
" <min> <max> :Poission distribution. Each pixel i of output is generated as poisson(ref-input[i])");
56 addParamsLine(
" [--limit0 <float> ] :Crop noise histogram below this value ");
57 addParamsLine(
" [--limitF <float> ] :Crop noise histogram above this value ");
59 addExampleLine(
"Add noise to a single image, writing in different image:",
false);
60 addExampleLine(
"xmipp_transform_add_noise -i cleanImage.spi --type gaussian 10 5 -o noisyGaussian.spi");
61 addExampleLine(
"+++Following =cleanImage.spi= at left and =noisyGaussian.spi= at right: %BR%",
false);
62 addExampleLine(
"+++%ATTACHURL%/cleanImage.jpg %ATTACHURL%/noisyGaussian.jpg %BR%",
false);
63 addExampleLine(
"Add uniform noise to a volume, overriding input volume:",
false);
64 addExampleLine(
"xmipp_transform_add_noise -i g0ta.vol -uniform -0.1 0.1");
82 if (noise_type ==
"gaussian")
87 else if (noise_type ==
"student")
93 else if (noise_type ==
"uniform")
98 else if (TYPE_POISSON == noise_type)
110 if (noise_type ==
"gaussian")
111 std::cout <<
"Noise avg=" << param1 << std::endl
112 <<
"Noise stddev=" << param2 << std::endl;
113 else if (noise_type ==
"student")
114 std::cout <<
"Degrees of freedom= "<< df << std::endl
115 <<
"Noise avg=" << param1 << std::endl
116 <<
"Noise stddev=" << param2 << std::endl;
117 else if (noise_type ==
"uniform")
118 std::cout <<
"Noise min=" << param1 << std::endl
119 <<
"Noise max=" << param2 << std::endl;
120 else if (TYPE_POISSON == noise_type)
121 std::cout <<
"Mean background=" << param1 << std::endl
122 <<
"Mean foreground=" << param2 << std::endl;
124 std::cout <<
"Crop noise histogram below=" << limit0 << std::endl;
126 std::cout <<
"Crop noise histogram above=" << limitF << std::endl;
132 const size_t count = img.
data.nzyxdim;
133 for (
size_t i = 0;
i < count; ++
i) {
138 const size_t count = img.
data.nzyxdim;
139 for (
size_t i = 0;
i < count; ++
i) {
148 if (TYPE_POISSON == noise_type) {
151 std::random_device rd;
152 std::mt19937 gen(rd());
155 const float gap = param1 -
param2;
156 auto dist = std::poisson_distribution<>(0);
157 for (
size_t i = 0;
i < count; ++
i) {
158 float mean = param1 - gap * img.
data[
i];
159 if (dist.mean() != mean) {
160 dist = std::poisson_distribution<>(mean);
162 res.
data[
i] = dist(gen);
169 img().addNoise(param1, param2, noise_type, df);
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
const char * getParam(const char *param, int arg=0)
Incorrect argument received.
void addExampleLine(const char *example, bool verbatim=true)
void limit(Image< T > &img)
bool checkParam(const char *param)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
void addParamsLine(const String &line)