noise_speckle_grey16
Tcl_Obj* imageObj
Tcl_Obj* randomObj
double variance
/*
* Adding speckle-style (multiplicative) noise to the image, using the random
* numbers in the randomObj image (same size as imageObj is required).
*/
crimp_image* image;
crimp_image* image_random;
crimp_image* result;
int x, y;
double temp ;
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++) {
temp = GREY16 (image, x, y) / 255.0f ;
FLOATP (result, x, y) = temp +
(sqrt(10.0f * variance) * temp * (FLOATP (image_random, x, y) - 0.5f));
}
}
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:
*/