noise_gaussian_grey8
Tcl_Obj* imageObj
Tcl_Obj* randomObj
double mean
double variance
/*
* Adding gaussian-style noise (*) to the image, using the random numbers in
* the randomObj image (same size as imageObj is required), converting them to
* gaussian distributed numbers.
*/
crimp_image* image;
crimp_image* image_random;
crimp_image* result;
int x, y;
double rand_no;
crimp_input (imageObj, image, grey8);
crimp_input (randomObj, image_random, float);
if (!crimp_eq_dim (image, image_random)) {
Tcl_SetResult(interp, "image dimensions do not match", TCL_STATIC);
return TCL_ERROR;
}
result = crimp_new_float (image->w, image->h);
for (y = 0; y < result->h; y++) {
for (x = 0; x < result->w; x++) {
rand_no = FLOATP (image_random, x, y) ;
rand_no = sqrt ((-2.0f ) * log(rand_no)) * sin (2 * M_PI * rand_no);
FLOATP (result, x, y) =
(GREY8 (image, x, y) / 255.0f ) + (sqrt(variance) * rand_no) + mean;
}
}
Tcl_SetObjResult(interp, crimp_new_image_obj (result));
return TCL_OK;
/* vim: set sts=4 sw=4 tw=80 et ft=c: */
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/