Reputation: 1
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();
Upvotes: 0
Views: 196
Reputation: 328594
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.
Upvotes: 1