Two Images At Once?
in
Programming Questions
•
1 year ago
Hello,
I would like to take two images (well.. one plus a copy of itself) and copy rows from one onto the other. The reason I am doing this is to rearrange the rows in the original image. I keep a copy to get the row data from so I am not overwriting the data I need as I go along.
I suppose I don't need to be overwriting the original. I could create a new image, but how would I do that row by row like this? And there is no particular order in which the rows will be combined.
What I don't understand, is how do I have two images in memory at once and how do I access there data individually? I was using the pixels[] array and get() to gather my data. Then I wondered how get() knows which image I want to GET pixels from. Is this a silly question?
I have a formal education with C, but this sort of confusion I always run into with Processing makes me very frustrated with it. Maybe it's just OOP that I don't get. I have been using Processing since 2007.
Here is a function I use to average the green value in all rows and return an array of those averages. This is tested and works.
- float[] rowAvgs(PImage img)
- {
- float totalGreen = 0;
- float[] average = new float[img.height]; //Array to hold results
- for(int j = 0; j < img.height; j++) //Rows
- {
- for(int i = 0; i < img.width; i++) //Columns
- {
- totalGreen += green(get(i, j)); //Running total
- }
- average[j] = totalGreen / img.width; //average of j-eth row
- totalGreen = 0; //Reset total to 0
- }
- return average;
- }
I originally wanted to take the average of the color (RGB) of a row, but quickly got confused on how to do that also. So I am just picking a color instead
1