97 lines
2.4 KiB
C
97 lines
2.4 KiB
C
/* @(#) Add gaussian noise with mean 0 and variance sigma to image
|
|
* @(#) The noise is generated by averaging 12 random numbers
|
|
* @(#) page 78 PIETGEN 1989 n = 12
|
|
* @(#) Input image is any, output is float
|
|
* @(#) If running on SYSTEM V CONSTANT should be replaced by 2**15 - 1
|
|
* @(#) Usage
|
|
* @(#)
|
|
* @(#) int im_addgnoise(imin, imout, sigma)
|
|
* @(#) IMAGE *imin, *imout;
|
|
* @(#) double sigma;
|
|
* @(#) Returns 0 on success and -1 on error
|
|
* @(#)
|
|
*
|
|
* Copyright 1990, N. Dessipris.
|
|
*
|
|
* File written on 2/12/1986
|
|
* Author : N. Dessipris
|
|
* Updated : 22/01/1991
|
|
* 1/2/95 JC
|
|
* - junked!
|
|
* - now uses partial im_gaussnoise() and partial im_add() to do the
|
|
* same job
|
|
& 1/5/01 JC
|
|
* - oops, failed for not-1-band images
|
|
*/
|
|
|
|
/*
|
|
|
|
This file is part of VIPS.
|
|
|
|
VIPS is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
|
|
|
*/
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include <config.h>
|
|
#endif /*HAVE_CONFIG_H*/
|
|
#include <vips/intl.h>
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <vips/vips.h>
|
|
|
|
#ifdef WITH_DMALLOC
|
|
#include <dmalloc.h>
|
|
#endif /*WITH_DMALLOC*/
|
|
|
|
#define MAX_BANDS (200)
|
|
|
|
int
|
|
im_addgnoise( IMAGE *in, IMAGE *out, double sigma )
|
|
{
|
|
IMAGE *noise[MAX_BANDS];
|
|
IMAGE *nb;
|
|
int i;
|
|
|
|
if( in->Bands > MAX_BANDS ) {
|
|
im_error( "im_addgnoise", _( "too many bands" ) );
|
|
return( -1 );
|
|
}
|
|
|
|
/* Make n-band noise image.
|
|
*/
|
|
for( i = 0; i < in->Bands; i++ )
|
|
if( !(noise[i] = im_open_local( out, "im_addgnoise:2", "p" )) ||
|
|
im_gaussnoise( noise[i], in->Xsize, in->Ysize,
|
|
0.0, sigma ) )
|
|
return( -1 );
|
|
|
|
if( !(nb = im_open_local( out, "im_addgnoise:3", "p" )) ||
|
|
im_gbandjoin( noise, out, in->Bands ) ||
|
|
im_add( in, nb, out ) )
|
|
return( -1 );
|
|
|
|
return( 0 );
|
|
}
|