Computer Science Canada

Copying portions of a large array into a smaller one

Author:  Joeltron [ Fri Apr 05, 2013 9:21 pm ]
Post subject:  Copying portions of a large array into a smaller one

I need help making a copy of portions of a larger array in a smaller array. what i am trying to do is load an image raster (which is an array), and then crop the image, by making a copy of the data in select bins. The image below helps to explain what im trying to do. the larger array has been written out in the form it makes the raster image. the bin numbers have been written out. what i need to do is make a copy of just the highlighted bins in the smaller array. so copy[0,1,2,3] will be equal to bigArray[14,15,20,21]

Author:  Insectoid [ Fri Apr 05, 2013 9:31 pm ]
Post subject:  RE:Copying portions of a large array into a smaller one

You can easily do this with a nested for loop.

code:
int x_offset, y_offset
int x_size, y_size

array old_array, new_array

for (int x = 0; x < x_size, x++){
    for (int y = 0; y < y_size, y++){
        new_array[x][y] = old_array[x+x_offset][y+y_offset]
    }
}

Author:  Joeltron [ Fri Apr 05, 2013 9:55 pm ]
Post subject:  Re: Copying portions of a large array into a smaller one

im using a standard java array. which looks like array[bin], so im not too sure what you mean by new_array[x][y]. any further explanation would be awesome. thanks.

Author:  Tony [ Fri Apr 05, 2013 10:18 pm ]
Post subject:  RE:Copying portions of a large array into a smaller one

you can think of it as array of arrays. So the value of 2D_array[0] would be an array with values such as [0,6,12,18,24,30]


: