■ 함수 분석


148     public boolean sameAs(IChimpImage other, double percent) {
149         BufferedImage otherImage = other.getBufferedImage();
150         BufferedImage myImage = getBufferedImage();
151
152         // Easy size check
153         if (otherImage.getWidth() != myImage.getWidth()) {
154             return false;
155         }
156         if (otherImage.getHeight() != myImage.getHeight()) {
157             return false;
158         }
159
160         int[] otherPixel = new int[1];
161         int[] myPixel = new int[1];
162
163         int width = myImage.getWidth();
164         int height = myImage.getHeight();
165
166         int numDiffPixels = 0;
167         // Now, go through pixel-by-pixel and check that the images are the same;
168         for (int y = 0; y < height; y++) {
169             for (int x = 0; x < width; x++) {
170                 if (myImage.getRGB(x, y) != otherImage.getRGB(x, y)) {
171                     numDiffPixels++;
172                 }
173             }
174         }
175         double numberPixels = (height * width);
176         double diffPercent = numDiffPixels / numberPixels;
177         return percent <= 1.0 - diffPercent;


특징

1) Width와 Height가 틀리다면, 비교가 실패한다.

2) 한 픽셀씩 비교한다음에, 결국 numDiffPixels를 하나씩 증가 시킨다.

3) diffPercent = numDiffPixels / numberPixels

4) percent <= 1.0 - diffPercent



+ Recent posts