We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi!
I am trying to make a light field renderer based on this Nvidia research https://research.nvidia.com/sites/default/files/publications/Slim near-eye display using pinhole aperture arrays.pdf
Long story short - "int o = 1;" needs to be 0.75 but get() doesn't support floats.. any ideas?
This is my code so far:
int N = height/3;
int o = 1;
void setup() {
size(400, 300);
}
void draw() {
PImage myImage = loadImage("fox.jpg");
image(myImage, 0, 0);
for (int i = 0; i < myImage.width; i = i+1) {
for (int j = 0; j < myImage.height; j = j+1) {
PImage c = get(i*N*o, j*N*o, N, N);
tint(0, 200, 255); //just for checking it works
image(c, i*N*o, j*N*o);
}
}
}
Answers
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
We should only access width & height after size()! L-)
Whoops.. thanks :)
But still - anyone have any suggestions?
Ok... first point: Do not load your image in draw(). You are loading the same file 30 fps.
Second point: I would recommend calling your variable "o" something more meaningful based on what it does. If you write 100 or 200 lines of code, the letter o gets mixed with 0 and anything that looks round. If o is a scale factor, for example, call it scaleVal for sake of clarity.
A possible solution is to make your variable float instead of integer. If you are trying to interpolate between pixel colors, you can check lerpColor: https://processing.org/reference/lerpColor_.html
You need to be also aware of the colorMode. The default mode is RGB. Check https://processing.org/reference/colorMode_.html
You should also check the reference for tint() as you are calling it 30 x withd x height many times. If you need to use it, it will be used outside the for loop: https://processing.org/reference/tint_.html
Kf
All good suggestions, but it's not really what i'm looking for. Its just how i use get() with float?
No. Stop. Fix the fact that you are loading your image in draw() first. i refuse to even look at the rest of your code until you fix that. Do not load things in draw().
I will shout this at you if I have to.
DO NOT LOAD THINGS IN DRAW.
Look I know I'm not supposed to do that and I know the code has flaws - but it's just a sketch and I just need to know if anyone knows if there's an alternative to using floats with get()
Cast them to int?
The problem, you see, is that it doesn't make any sense to use floats with get(). The get() function is trying to get you the color of a pixel. If you're get()ing the pixel at (x,y), you're getting the x'th pixel in the y'th row. You can't get() a color of a pixel between pixels, because, well, there's nothing between them. There's no, say first-and-three-fourths pixel. There's the first pixel, and the second pixel. And so on. They're counted by whole numbers, not floats.
Also, DO NOT LOAD THINGS IN DRAW().
Okay, I see - thank you very much :)
And I promise to never ever load any images outside of draw ;)