比较这两个不同的图像的像素,时间太长的时间 [英] compare the pixel of the two different images , takes too long time

查看:153
本文介绍了比较这两个不同的图像的像素,时间太长的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要比较的两个不同的图像的像素。我比较与第二图像的所有像素的第一图像的像素,这是我的code的东西。

I want to compare the pixel of the two different images. I am comparing the pixel of first image with all the pixels of the second Image, here is my code stuff.

    for (int i = 0; i < bitmap.getWidth(); i++) {
        for (int j = 0; j < bitmap.getHeight(); j++) {

            for (int k = 0 ; k<bitmpa2.getWidth(); k++) {
                               for (int l = 0 ; l<bitmpa2.getHeight(); l++) {

                            if( bitmap.getPixel(i, j) ==bitmap2.getPixel(k, l) )
                              Counter++ ;            
              }   
           }
        }
    }

下面计数器的值是,在这两个图像相同的像素数。问题是,这工作,但它需要太多的时间来执行,所以时间限制的问题就在这里,所以我有什么可以减少时间,并得到确切的结果。任何其他可能性是值得欢迎的。 谢谢你。

Here the value of Counter is the number of pixels that are same in both the Images. The problem is that this works but it takes much time to perform it, so time constraint is the problem here, So what can I have to reduce the time and get exact result. Any other possibility is welcome. Thanks.

推荐答案

如果您使用的是API 12级或以上,有一个叫方法<一href="http://developer.android.com/reference/android/graphics/Bitmap.html#sameAs%28android.graphics.Bitmap%29"相对=nofollow> sameAs的位图做的正是你要寻找的。否则,使用<一个href="http://developer.android.com/reference/android/graphics/Bitmap.html#getPixels%28int%5B%5D,%20int,%20int,%20int,%20int,%20int,%20int%29"相对=nofollow> 的getPixels ,并做一些事情,如:

If you're using API level 12 or above, there's a method called sameAs on Bitmap to do exactly what you're looking for. Otherwise, use getPixels and do something like:

int width = bitmap1.getWidth();
int height = bitmap1.getHeight();
int pixelCount = width * height;
int[] pixels1 = new int[pixelCount];
int[] pixels2 = new int[pixelCount];

bitmap1.getPixels(pixels1, 0, 0, 0, 0, width, height);
bitmap2.getPixels(pixels2, 0, 0, 0, 0, width, height);

for (int i = 0; i < pixelCount; i++) {
    if (pixels1[i] != pixels2[i]) {
        return false;
    }
}
return true;

或者,如果你真的想这样做柜台的事情,看看有多少像素都是一样的,继续前进,做到这一点。

Or if you really want to do the counter thing to see how many pixels are the same, go ahead and do that.

其实,你也许可以做一些与缓冲器太...也许像

Actually, you can probably do something with the buffers too... Maybe something like

int width = bitmap1.getWidth();
int height = bitmap1.getHeight();
int pixelCount = width * height;
IntBuffer buffer1 = IntBuffer.allocate(pixelCount);
IntBuffer buffer2 = IntBuffer.allocate(pixelCount);
bitmap1.copyPixelsToBuffer(buffer1);
bitmap2.copyPixelsToBuffer(buffer2);
int result = buffer1.compareTo(buffer2);

我不知道这两种方法在性能上的比较,但它的东西玩弄,如果你想要的。

I'm not sure how those two methods compare in performance, but it's something to play around with if you want.

这篇关于比较这两个不同的图像的像素,时间太长的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆