회색 음영 이미지에 미세한 노이즈를 추가하는 방법을 알고 계십니까? 회색조 이미지에 약간의 흑백 노이즈를 추가하고 싶습니다. 누구든지이 작업을 수행하는 방법을 알고 있습니까?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;
}
가능한 복제 안드로이드 노이즈 효과의 비트 맵] (http://stackoverflow.com/questions/16690730/android-noise-effect-on-bitmap) –
@ Funkystein 다른 질문을 할 때이 가능한 복제 방법 전부? 또한, 그 질문에서 나온 방법은 제가 사용하는 것과 같습니다. 난 그냥 미묘한, 흑백 잡음을 추가하고 싶습니다. 임의의 색상이 아니야 –
그냥 임의의 색상 대신 검정색을 사용합니다. 또는 그레이 스케일로 변환하기 전에 노이즈를 적용하면 노이즈가 회색 음영으로 표시됩니다. –