def addNoise(input, noise=0.1, doForeground=True, doBackground=True):
 if (doForeground and doBackground):
  return numpy.abs((input - (numpy.random.random(input.shape) < noise)))
 else:
  if doForeground:
   return numpy.logical_and(input, (numpy.random.random(input.shape) > noise))
  if doBackground:
   return numpy.logical_or(input, (numpy.random.random(input.shape) < noise))
 return input

def addNoise ( input , noise = 0.1 , doForeground = True , doBackground = True ) : if ( doForeground and doBackground ) : return numpy . abs ( ( input - ( numpy . random . random ( input . shape ) < noise ) ) ) else : if doForeground : return numpy . logical_and ( input , ( numpy . random . random ( input . shape ) > noise ) ) if doBackground : return numpy . logical_or ( input , ( numpy . random . random ( input . shape ) < noise ) ) return input
add noise to the given input .