2014-10-28 3 views
0

회색 음영 이미지에 미세한 노이즈를 추가하는 방법을 알고 계십니까? 회색조 이미지에 약간의 흑백 노이즈를 추가하고 싶습니다. 누구든지이 작업을 수행하는 방법을 알고 있습니까?Android 비트 맵에 미세한 노이즈 추가

현재이 방법을 사용하고 있습니다. 그러나 이는 임의의 색상을 생성하고 기존 픽셀을 해당 색상으로 교체하는 것입니다. 어떻게 약간의 흑백 노이즈를 비트 맵의 ​​일부 픽셀에만 추가 할 수 있습니까?

public static Bitmap applyFleaEffect(Bitmap source) { 
// get source image size 
int width = source.getWidth(); 
    int height = source.getHeight(); 
int[] pixels = new int[width * height]; 
// get pixel array from source 
source.getPixels(pixels, 0, width, 0, 0, width, height); 
// create a random object 
Random random = new Random(); 

int index = 0; 
// iteration through pixels 
for(int y = 0; y < height; ++y) { 
for(int x = 0; x < width; ++x) { 
// get current index in 2D-matrix 
index = y * width + x; 
// get random color 
int randColor = Color.rgb(random.nextInt(255), 
    random.nextInt(255), random.nextInt(255)); 
// OR 
pixels[index] |= randColor; 

}} // 출력 비트 맵 맵 bmOut = Bitmap.createBitmap (폭, 높이, source.getConfig()); bmOut.setPixels (픽셀, 0, 너비, 0, 0, 너비, 높이); return bmOut; } }

UPDATE : 그레이 스케일 단계를 보여 전체 코드를 추가하고,

 //First, apply greyscale to make Image black and white 
    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, mBitmap.getConfig()); 
    Canvas c = new Canvas(bmpGrayscale); 
    Paint paint = new Paint(); 
    ColorMatrix cm = new ColorMatrix(); 
    cm.setSaturation(0); 
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); 
    paint.setColorFilter(f); 

    //Apply noise after grayscale 
    int[] pixels = new int[width * height]; 

    bmpGrayscale.getPixels(pixels, 0, width, 0, 0, width, height); 
    // a random object 
    Random random = new Random(); 

    int index = 0; 

    // Note: Declare the c and randColor variables outside of the for loops 
    int co = 0; 
    int randColor = 0; 
    // iteration through pixels 
    for (int y = 0; y < height; ++y) { 
     for (int x = 0; x < width; ++x) { 
      if (random.nextInt(101) < percentNoise) { 
       // Skip this iteration a certain percentage of the time 
       continue; 
      } 
      // get current index in 2D-matrix 
      index = y * width + x; 


      co = random.nextInt(255); 


      randColor = Color.rgb(co, co, co); 
      pixels[index] |= randColor; 




     } 
    } 
    // output bitmap 
    mBitmap = Bitmap.createBitmap(width, height, bmpGrayscale.getConfig()); 
    mBitmap.setPixels(pixels, 0, width, 0, 0, width, height); 

    c.drawBitmap(mBitmap, 0, 0, paint); 
    return bmpGrayscale; 
} 
+0

가능한 복제 안드로이드 노이즈 효과의 비트 맵] (http://stackoverflow.com/questions/16690730/android-noise-effect-on-bitmap) –

+0

@ Funkystein 다른 질문을 할 때이 가능한 복제 방법 전부? 또한, 그 질문에서 나온 방법은 제가 사용하는 것과 같습니다. 난 그냥 미묘한, 흑백 잡음을 추가하고 싶습니다. 임의의 색상이 아니야 –

+0

그냥 임의의 색상 대신 검정색을 사용합니다. 또는 그레이 스케일로 변환하기 전에 노이즈를 적용하면 노이즈가 회색 음영으로 표시됩니다. –

답변

0

첫 번째 시도 노이즈 단계는 randColor은 코드와 그레이 컬러가 될 가능성이 없습니다. 임의의, 그레이 스케일 색상 생성하려면 : (: 원하는대로 percentNoise 매개 변수를 조정 주) : 염두에두고

int c = random.nextInt(255); 
int randColor = Color.rgb(c, c, c); 

을, 여기에 내가 코드를 다시 작성합니다 어떻게

public static Bitmap applyFleaEffect(Bitmap source, int percentNoise) { 
    // get source image size 
    int width = source.getWidth(); 
    int height = source.getHeight(); 
    int[] pixels = new int[width * height]; 
    // get pixel array from source 
    source.getPixels(pixels, 0, width, 0, 0, width, height); 
    // create a random object 
    Random random = new Random(); 

    int index = 0; 
    // Note: Declare the c and randColor variables outside of the for loops 
    int c = 0; 
    int randColor = 0; 
    // iterate through pixels 
    for (int y = 0; y < height; ++y) { 
     for (int x = 0; x < width; ++x) { 
      if (random.nextInt(101) < percentNoise) { 
       // Skip this iteration a certain percentage of the time 
       continue; 
      } 
      // get current index in 2D-matrix 
      index = y * width + x; 
      // get random color 
      c = random.nextInt(255); 
      randColor = Color.rgb(c, c, c); 
      pixels[index] |= randColor; 
     } 
    } 
    Bitmap bmOut = Bitmap.createBitmap(width, height, source.getConfig()); 
    bmOut.setPixels(pixels, 0, width, 0, 0, width, height); 
    return bmOut; 
} 
+0

고마워요. 내 편집 좀 봐 주시겠습니까? 우선 이미지를 회색 음영으로 변환 한 다음 아주 작은 노이즈를 추가하려고합니다. 나는 percentNoise 필드로 놀았습니다. 0에 가까울수록 비트 맵의 ​​흰색이 더 밝아지고 100 %에 근접합니다. 노이즈는 검정색이 많을수록 높습니다. 이것에 대한 통찰력? –