简体   繁体   中英

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. I am using PixelGrabber to acquire the pixels. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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