help with image program
Author |
Message |
Justin_
|
Posted: Thu Jun 08, 2006 11:41 pm Post subject: help with image program |
|
|
okay so "sourcePixels" is an array of values between 0-255 which are pixels. this is a black and white image scaler with just one problem, some of the image is chopped off and the image that appears is enlarged and slightly compressed rather than scaled down. It should just scale down 50% but I cannot see what I'm doing wrong.
Java: |
int height = sourcePixels.length, width = sourcePixels[0].length;
int[][] transformedPixels = new int[height/2][width/2];
int[] linearArray = new int[height * width];
int i = 0;
int num = 0;
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
linearArray[i] = sourcePixels[row][col];
i++;
}
}
for (int row = 0; row < height/2; row++)
{
for (int col = 0; col < width/2; col++)
{
transformedPixels[row][col] = (linearArray[num] + linearArray[num++] + linearArray[num + (width-2)] + linearArray[num+(width-1)])/4;
num++;
}
}
return transformedPixels;
}
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
rizzix
|
Posted: Fri Jun 09, 2006 9:41 am Post subject: (No subject) |
|
|
What are you trying to achieve here? Why don't you try and use Java's built-in methods to scale the image? It would probably be faster (more optimized) and it works. |
|
|
|
|
|
Justin_
|
Posted: Fri Jun 09, 2006 9:55 am Post subject: (No subject) |
|
|
Sorry I forgot to mention that this is for a school summative and I'm supposed to make my own functions. It is supposed to scale the image stored in the pixel array by 50% or in other words div both height and width by 2.
Does anyone know an algorithm to accomplish it? To explain my algorithm I essentially took the 2d pixel array and put it into a 1d array because that way I can choose 4 pixels in a box like: o o
o o
by simply using the algorithm: num, num++, num+(width-2), num+(width-1) to choose pixels in this order.
Anyway, if someone has done this kind of thing before please shed some light. |
|
|
|
|
|
[Gandalf]
|
Posted: Sat Jun 10, 2006 5:53 pm Post subject: (No subject) |
|
|
Why don't you just store every second pixel of that image in an array and redraw the pixels in that array? I've just tried that in Turing, and it doesn't look too bad, even with Turing's crappy colour preservation. |
|
|
|
|
|
|
|