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 › [updt]ArrayOutOfB and a bunch of code (alpha < 1)
Page Index Toggle Pages: 1
[updt]ArrayOutOfB and a bunch of code (alpha < 1) (Read 321 times)
[updt]ArrayOutOfB and a bunch of code (alpha < 1)
Mar 18th, 2009, 3:50am
 
[update in post #7]


hi, I want to merge maaany images with very low alpha values.
how to achieve an alpha value between 0 and 1?

in detail:
each frame I want to add another image on top of the screen.
the first one with alpha = 255 (1/1)
2nd one with alpha = 128 (1/2)
3rd one with alpha = 85(1/3)
...
255th one with alpha = 1 (1/255)
256th one with alpha = 0.996... (1/256) //PROBLEM

This way each frame should contains the same amount of information/visibility of all loaded images.
Doing this with 5000 images will make the exact alpha value very important. Any Ideas?

by the way: the solution does not have to work in realtime and can have visible steps in between the "right" frames (I just need the exported images to create a movie)

thx! and hello(my first post and my first processing program)!

edit2:
does colorMode(mode, range1, range2, range3, *range4*); get me anywhere?
I'd need to get an image with more than 8bit (that I could sample down again...)


edit1:
workarrounds I thought about:
1. dithering: whiping of 50% of the pixels of one image at random for 0.5 alpha
but this is somehow ugly

2. pre-merging images:  
1st image + 50% alpha (2nd image)  =-> merge1
merge1 + 50% alpha(3rd image + 50% alpha (4th image)) =-> merge2
merge2 + 50% alpha((5th image + 50% alpha (6th image)) + 50% alpha(7th image + 50% alpha (8th image)))
and so on...
this would merge 2, 4, 8, 16... images  
but this would give me only 12 frames with 5000 images

3.pre-merging image 2:
same as 2nd walkarround with  smaller steps.
but I don't really know how...
Re: alpha < 1 with colorMode(mode, range) ?
Reply #1 - Mar 18th, 2009, 7:45am
 
As alpha is only 8 bits, only the last 256 images will have a visible effect.

If you need to do 5000 images, I would suggest making an array of floats. combine the images in that, then remap() and store the values in pixel[]
Re: alpha < 1 with colorMode(mode, range) ?
Reply #2 - Mar 18th, 2009, 9:54am
 
Ogre is right. If you need such accuracy, I fear you have to do the fractional alpha math (and corresponding merging) yourself, with your own algorithm.

But beyond some level of alpha, I doubt you will see any effect on the final image. You should do some experiments with a smaller number of images, if not done already.
Re: alpha < 1 with colorMode(mode, range) ?
Reply #3 - Mar 18th, 2009, 10:33am
 
I think you just need 3 float[] the same size as your images, one each for red/blue/green, just add the red values for all 5000 images to the corresponding entry in the array, and then divide by 5000 to get the result I'd have thought.
Re: alpha < 1 with colorMode(mode, range) ?
Reply #4 - Mar 18th, 2009, 1:20pm
 
PhiLho  wrote on Mar 18th, 2009, 9:54am:
But beyond some level of alpha, I doubt you will see any effect on the final image.

It's all about the grey and how many images can be added until you can't recognise anything any more.

Quote:
I think you just need 3 float[] the same size as your images, one each for red/blue/green, just add the red values for all 5000 images to the corresponding entry in the array, and then divide by 5000 to get the result I'd have thought.


I just can guess what array and float means and I need to add the images step by step, but I think your Idea works, thank you!

3 values for each pixel and when adding a new image I add 1/x of the difference to the new pixel:
just need to learn how to read the pixel values from the images (should be very easy)  and how to write such repetitive code (I allways feared arrays or what it is).

thank you!
Re: alpha < 1 with colorMode(mode, range) ?
Reply #5 - Mar 18th, 2009, 2:05pm
 
I don't think you need to add 1 Xth for the value at any point. You only had to do the variable alpha part if you were adding frames into something that has a limited range of values, like it does with the pixels array. If you're doing it into something with no (real) limit, you can just add all the values, and then divide by the number of values.

e.g. frame1+frame2+frame3+... /(float)numFrames.

Re: alpha < 1 with colorMode(mode, range) ?
Reply #6 - Mar 18th, 2009, 2:11pm
 
Quote:
e.g. frame1+frame2+frame3+... /(float)numFrames.

thx man!
if you are intrested: this is how the last or first frame will look like (taking 5ooo frames of a moving person in a portrait like framing):
http://img3.imagebanana.com/img/fm47106/mergehoch4frame.bmp.png
Re: alpha < 1 with colorMode(mode, range) ?
Reply #7 - Mar 22nd, 2009, 12:12am
 
moved to programs: http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1237726063
Page Index Toggle Pages: 1