QRコードのnoiseを取除きたいですが、
ぐぐるで検索してみたら、いくつかのメソッドがあったんですが
試してみると、だめでした!
問題はどこかを教えていただけますでしょうか?
ほか、いいメソッドがあれば、ぜひご教授ください。
メソッド1
※このメソッドはnoise取除きではなく、追加ですね
※調査してわかったことを追記
java
1public static BufferedImage scale(BufferedImage src, int w, int h) 2 { 3 BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 4 int x, y; 5 int ww = src.getWidth(); 6 int hh = src.getHeight(); 7 for (x = 0; x < w; x++) { 8 for (y = 0; y < h; y++) { 9 int col = src.getRGB(x * ww / w, y * hh / h); 10 img.setRGB(x, y, col); 11 } 12 } 13 return img; 14 }
メソッド2
※このメソッドはnoise取除きではなく、追加ですね
※調査してわかったことを追記
java
1 public static BufferedImage impulseNoise(BufferedImage image, BufferedImage output) { 2 output.setData(image.getData()); 3 4 Raster source = image.getRaster(); 5 WritableRaster out = output.getRaster(); 6 double impulseRatio = 0.05; 7 double rand; 8 double halfImpulseRatio = impulseRatio / 2.0; 9 int bands = out.getNumBands(); 10 int width = image.getWidth(); // width of the image 11 int height = image.getHeight(); // height of the image 12 java.util.Random randGen = new java.util.Random(); 13 14 for (int j=0; j<height; j++) { 15 for (int i=0; i<width; i++) { 16 rand = randGen.nextDouble(); 17 if (rand < halfImpulseRatio) { 18 for (int b=0; b<bands; b++) out.setSample(i, j, b, 0); 19 } else if (rand < impulseRatio) { 20 for (int b=0; b<bands; b++) out.setSample(i, j, b, 255); 21 } 22 } 23 } 24 25 return output; 26 }
メソッド3
java
1 protected static BufferedImage gaussianNoise(BufferedImage image, BufferedImage output) { 2 Raster source = image.getRaster(); 3 WritableRaster out = output.getRaster(); 4 5 double stdDev = 10.0; 6 int currVal; // the current value 7 double newVal; // the new "noisy" value 8 double gaussian; // gaussian number 9 int bands = out.getNumBands(); // number of bands 10 int width = image.getWidth(); // width of the image 11 int height = image.getHeight(); // height of the image 12 java.util.Random randGen = new java.util.Random(); 13 14 for (int j=0; j<height; j++) { 15 for (int i=0; i<width; i++) { 16 gaussian = randGen.nextGaussian(); 17 18 for (int b=0; b<bands; b++) { 19 newVal = stdDev * gaussian; 20 currVal = source.getSample(i, j, b); 21 newVal = newVal + currVal; 22 if (newVal < 0) newVal = 0.0; 23 if (newVal > 255) newVal = 255.0; 24 25 out.setSample(i, j, b, (int)(newVal)); 26 } 27 } 28 } 29 30 return output; 31 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/13 10:13