00001
00002
00003 #include "Noise.h"
00004
00005 template void Noise< int >(Image< int >&, string, float, float, int);
00006 template void Noise< byte >(Image< byte >&, string, float, float, int);
00007 template void Noise< float >(Image< float >&, string, float, float, int);
00008 template void Noise< int >(Image< int >&, int);
00009 template void Noise< byte >(Image< byte >&, int);
00010 template void Noise< float >(Image< float >&, int);
00011 template void Noise< int >(Image< int >&, float, float, int);
00012 template void Noise< byte >(Image< byte >&, float, float, int);
00013 template void Noise< float >(Image< float >&, float, float, int);
00014 template void Noise< int >(Image< int >&, string, int);
00015 template void Noise< byte >(Image< byte >&, string, int);
00016 template void Noise< float >(Image< float >&, string, int);
00017
00018 template< class T > void Noise(Image< T >& input, string noise_type,
00019 float a, float b, int seed = 1)
00020 {
00021 SetGenRand(seed);
00022 if (noise_type.substr(0, 1) == "u" || noise_type.substr(0, 1) == "U")
00023 for (int i = 0; i < input.getHeight(); i++)
00024 for (int j = 0; j < input.getWidth(); j++)
00025 input[i][j] += (T)GenRand(a, b);
00026 if (noise_type.substr(0, 1) == "n" || noise_type.substr(0, 1) == "N")
00027 for (int i = 0; i < input.getHeight(); i++)
00028 for (int j = 0; j < input.getWidth(); j++)
00029 input[i][j] += (T)GaussRand(a, b);
00030 if (noise_type.substr(0, 1) == "s" || noise_type.substr(0, 1) == "S") {
00031 int i, j, amt;
00032 a = (a < 0) ? 0:a;
00033 a = (a > 100) ? 100:a;
00034 amt = (int)rint(input.getHeight()*input.getWidth()*a/100.0);
00035 for (int k = 0; k < amt; k++) {
00036 j = (int)rint(GenRand(0, input.getWidth()-1));
00037 i = (int)rint(GenRand(0, input.getHeight()-1));
00038 input[i][j] = (T)(255*rint(GenRand()));
00039 }
00040 }
00041 }
00042
00043 template< class T > void Noise(Image< T >& input, int seed = 1)
00044 {
00045 Noise(input, "n", 0, 1, seed);
00046 }
00047
00048 template< class T > void Noise(Image< T >& input, float a, float b, int seed = 1)
00049 {
00050 Noise(input, "n", a, b, seed);
00051 }
00052
00053 template< class T > void Noise(Image< T >& input, string noise_type, int seed = 1)
00054 {
00055 if (noise_type.substr(0, 1) == "u" || noise_type.substr(0, 1) == "U" ||
00056 noise_type.substr(0, 1) == "n" || noise_type.substr(0, 1) == "N")
00057 Noise(input, noise_type, 0, 1, seed);
00058 if (noise_type.substr(0, 1) == "s" || noise_type.substr(0, 1) == "S") {
00059 SetGenRand(seed);
00060 int amt;
00061 amt = (int)rint(GenRand(0, 100));
00062 Noise(input, noise_type, amt, 1, seed);
00063 }
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076