We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Fill array with images
Pages: 1 2 
Fill array with images (Read 3386 times)
Re: Fill array with images
Reply #15 - Jan 21st, 2010, 3:44am
 
> does that look right?

no 8)

you don't need to loadPixels for every j, you can move that and updatePixels outside the j loop

i'd also get rid of the images array - there's no need to store all of them, just open the one you're interested in, use it and load the next one.

i did something similar using music videos and php a while ago, a single pixel from each frame (5985 frames x 576 pixels high) - here's a small version

...
Re: Fill array with images
Reply #16 - Jan 21st, 2010, 4:14am
 
No wonder it is slow: you do loadPixels on each pixel!
Moreover, you do it on the screen, not on the involved images. They are not necessary for PImages anyway. Just remove these calls.

[EDIT] I shouldn't prepare the meal before hitting Send... Smiley
koogy was faster, and he is right, you don't need to load all the image data in an array if you don't plan to re-use this data: for thousand of images, you will quickly blow out the memory. Just load each image over the previous one.
Re: Fill array with images
Reply #17 - Jan 22nd, 2010, 12:23am
 
Replying to my own post. The same thing with "copy" is a hundred times faster
ah ok did not see previous responses before sending.
All I can do is try stuff and see if something appears on the screen at the end. These questions loading images in memory or am I loading the address of the image in memory are in my mind but I do not as yet find the documentation to answer those questions.
I think I need to have an array with the addresses of each image on disk (I might want to access them out of order)
so is that part of code wrong?
<edit> and with loadPixels outside the loop it is much quicker than copy()
I do not yet see how to make a new image and address it in memory(or on disk) or to address the screen image(is there just one)?
Re: Fill array with images
Reply #18 - Jan 22nd, 2010, 4:19am
 
I need to understand the difference between loading an image and working with the screen image.

what is a PImage ?
here is tidier how would it be improved ?
Code:
File path= sketchFile("pictures");
File[] files= path.listFiles();
PImage getimage = loadImage(files[0].getAbsolutePath());
PImage NewImage=createImage(getimage.width,getimage.height,RGB);
int count = getimage.width*getimage.height/(files.length);
size(getimage.width,getimage.height);
for (int i=0;i<files.length;i++)
{
getimage = loadImage(files[i].getAbsolutePath());
loadPixels();
//print(i+"; ");
for (int j=0;j<count;j++)
{
NewImage.pixels[i*count+j]=getimage.pixels[i*count+j];
}
updatePixels();
}
image(NewImage,0,0);
save("test.jpg");


cheers

mick
Re: Fill array with images
Reply #19 - Jan 22nd, 2010, 4:42am
 
As I wrote, you can drop the loadPixels and updatePixels, as these functions, as you use them, act on the screen (well, sketch's image), not on the manipulated images.
Another caveat you must be aware: the reference states that size() call must be the first instruction, and should use constants. Which isn't always convenient, I agree. The issue is that often, code before size() is executed twice.
If really necessary, I think you can do a size, then resize if needed.

Note: you can skip the image() call (and thus the size() issues) and do directly NewImage.save("test.jpg") if all you want is an image on disk.
Re: Fill array with images
Reply #20 - Jan 22nd, 2010, 8:11am
 
Thanks for all your replies.
I understand that save() saves the screen image.
I suppose saving an image that is in memory is more complicated ?
Edit: note to self digest replies before posting.

I understand that the pixels are saved as a line of data ?
If I want to get every y pixel at x coordinate I need some "step" instruction in the for loop ?
Also with "for" I can't seem to make it go backwards( from high to 0)
so what I have been doing is rotating the images in imagemagick which is slightly inconvienient.
Mick
Re: Fill array with images
Reply #21 - Jan 22nd, 2010, 9:24am
 
See for reference.
The magic is in the last part: change i++ to i-- to make it backward (of course, you need to change the initial value and the test too!), change it to i += 5 to skip every other 4 lines. You can even use more complex expressions, like i = sin(i * PI) (not a good idea there! Smiley)
Pages: 1 2