简体   繁体   English

加快使用PixelGrabber的图像处理

[英]Speed up the processing of an image which uses PixelGrabber

I am writing a program which which will divide an image into domains and ranges . 我正在编写一个程序,它将图像分为范围 In this domain will be 16X16 matrix. 在这个域中将是16X16矩阵。 I am using PixelGrabber to acquire the pixels. 我正在使用PixelGrabber来获取像素。 I have used for loop for the iteration but it is taking so much time to process.In java any alternate is there to reduce this time. 我已经将for循环用于迭代,但是要花很多时间来处理。在Java中,任何替代方法都可以减少这个时间。 I need a better performance. 我需要更好的表现。 Whether we can use any collections for that? 我们是否可以为此使用任何集合?

My code is: 我的代码是:

int[] pix = new int[16 * 16];
long start = System.nanoTime();
for (int i = 0; i < 512; i += 16) 
{
 for (int j = 0; j < 512; j += 16) 
 {
   PixelGrabber pg = new PixelGrabber(Im, i, j, 16, 16, pix, 0, 16);
   pg.grabPixels();
   makeStack(pix, i, j);
 }
}
long end = System.nanoTime();

Your problem right now is that you don't know why it's slow. 现在的问题是您不知道为什么它运行缓慢。 Yes, it's somewhere in the code above but you can't tell us where exactly . 是的,它在上面的代码中的某处,但是您不能告诉我们确切的位置

You should really run the code using a profiler to see where it spends most of the time. 您实际上应该使用探查器来运行代码,以查看大部分时间都花在了哪里。

That said, for image processing, it's usually most useful to convert the whole image into a byte[] or int[] array and then process that directly. 也就是说,对于图像处理,通常最有用的方法是将整个图像转换为byte[]int[]数组,然后直接对其进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM