![](public_html/YaBBImages/1pix.gif) |
Author |
Topic: Image To 3D (Read 1845 times) |
|
seltar
|
Image To 3D
« on: Mar 8th, 2005, 7:42pm » |
|
http://wliia.org/projects/img_to_3d/ --- edit --- http://wliia.org/projects/img_to_3d/indexv2.php http://wliia.org/projects/img_to_3d/indexv6.php http://wliia.org/projects/img_to_3d/indexv7.php --- edit --- This script converts an image pixel-heights to a 3d-model and then saves it in an ASC file (only when executed in processing) which allowes you to import it into i.e. 3DSMAX. plugin Now i know this will never replace 3d-modelling, but i think i can get some pretty cool effects for art-purposes with this script.. The question i have is how would i go about removing those pesky spikes, from low-value to high-value. Some sort of smoothing algorithm.. and this is how i see it, but something just isn't right about it.. Code: [ ] [ ] [ ] [ ] [X] [ ] [ ] [ ] [ ] X marks the pixel i'm checking, empty boxes is pixels around it. I'm thinking i'll have to check if the height-value of X is x-units larger or small than the surrounding pixels, do a avarage value-convertion.. |
| if anybody has a better idea, that they think will actually work, please let me in on your idea -seltar
|
« Last Edit: Mar 13th, 2005, 9:18pm by seltar » |
|
|
|
|
st33d
![Email](public_html/YaBBImages/email.gif)
|
Re: Converting 2D image To 3D model
« Reply #1 on: Mar 8th, 2005, 9:29pm » |
|
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm A blurb about perlin noise and interpolation. Your nice little 3DMax application would work well with perlin noise for creating some quick and dirty landscapes. It's the second bit on interpolation that might interest you. That's what takes the spikyness out of the random numbers and gives you smooth random numbers. I've also ripped REAS's code for my web cam. I've set it up differently though so you can spin the landscape around and such to check it out. I've posted the code below - but be warned, it was set up to run with 176x144 images and this adaptation will do bigger but a 400x400 is pretty heavy on the machine. mousePressed switches between the colour and greyscale and the keyPressed switches the interpretation mode. Code: int xm,ym,zm; boolean col = true; int con = 3; BImage swap; void setup() { size (800,600); swap = loadImage("file.gif"); xm = swap.width; ym = swap.height; zm = 50;//display cube depth } void loop() { background(255); push(); /* set the z value on translate a little higher for images smaller than 400x400, about 300 for 176x144 */ translate(width/2,height/2,0); rotateY((TWO_PI/width)*mouseX); rotateX((TWO_PI/width)*mouseY); //rotateX(PI); drawCube(); cubeBrown(); pop(); } void mousePressed(){ col = !col; } void keyPressed(){ con = (con+1)%5; } void cubeBrown(){ strokeWeight(1); stroke(15,15,15,100); line(-(xm/2),-(ym/2),-(zm/2),(xm/2),-(ym/2),-(zm/2)); line(-(xm/2),-(ym/2),-(zm/2),-(xm/2),(ym/2),-(zm/2)); line(-(xm/2),-(ym/2),-(zm/2),-(xm/2),-(ym/2),(zm/2)); line((xm/2),-(ym/2),-(zm/2),(xm/2),(ym/2),-(zm/2)); line((xm/2),-(ym/2),-(zm/2),(xm/2),-(ym/2),(zm/2)); line(-(xm/2),(ym/2),-(zm/2),(xm/2),(ym/2),-(zm/2)); line(-(xm/2),-(ym/2),(zm/2),(xm/2),-(ym/2),(zm/2)); line(-(xm/2),-(ym/2),(zm/2),-(xm/2),(ym/2),(zm/2)); line(-(xm/2),(ym/2),(zm/2),(xm/2),(ym/2),(zm/2)); line(-(xm/2),(ym/2),(zm/2),-(xm/2),(ym/2),-(zm/2)); line((xm/2),(ym/2),(zm/2),(xm/2),(ym/2),-(zm/2)); line((xm/2),(ym/2),(zm/2),(xm/2),-(ym/2),(zm/2)); } void drawCube(){ for (int ix = 1; ix < xm-1; ix++){ for (int iy = 1; iy < ym-1; iy++){ float zee = zm; int c1 = int((zee/255.0)*grey(swap.pixels[ix + iy*xm])); int c2 = int((zee/255.0)*grey(swap.pixels[ix + 1 + iy*xm])); int c3 = int((zee/255.0)*grey(swap.pixels[ix + (iy + 1)*xm])); int c4 = int((zee/255.0)*grey(swap.pixels[ix + 1 + (iy + 1)*xm])); if (col){ stroke(swap.pixels[ix + iy*xm]); }else{ stroke(grey(swap.pixels[ix + iy*xm])); } switch(con){ case 0: strokeWeight(3); point(ix-(xm/2),iy-(ym/2),c1-(zm/2));break; case 1: line(ix-(xm/2),iy-(ym/2),c1-(zm/2), ix-(xm/2)+1,iy-(ym/2),c2-(zm/2)); break; case 2: line(ix-(xm/2),iy-(ym/2),c1-(zm/2), ix-(xm/2)+1,iy-(ym/2),c2-(zm/2)); line(ix-(xm/2),iy-(ym/2),c1-(zm/2), ix-(xm/2),iy-(ym/2)+1,c3-(zm/2));break; case 3: noStroke(); if (col){ fill(swap.pixels[ix + iy*xm]); }else{ fill(grey(swap.pixels[ix + iy*xm])); } beginShape(QUADS); vertex(ix-(xm/2),iy-(ym/2),c1-(zm/2)); vertex((ix+1)-(xm/2),iy-(ym/2),c2-(zm/2)); vertex((ix+1)-(xm/2),(iy+1)-(ym/2),c4-(zm/2)); vertex(ix-(xm/2),(iy+1)-(ym/2),c3-(zm/2)); endShape();break; } } } if (con==4){ noStroke(); fill(255); beginShape(QUADS); texture(swap); vertex(-(xm/2),-(ym/2),0, 0,0); vertex((xm/2),-(ym/2),0, swap.width,0); vertex((xm/2),(ym/2),0, swap.width,swap.height); vertex(-(xm/2),(ym/2),0, 0,swap.height); endShape(); } } float grey(color p){ float r = red(p); float g = green(p); float b = blue(p); return (r+g+b)/3; } |
|
|
I could murder a pint.
|
|
|
seltar
|
Re: Converting 2D image To 3D model
« Reply #2 on: Mar 9th, 2005, 5:58am » |
|
Thanks alot.. Figured out another solution for the tweaking though.. and it turned out pretty good http://wliia.org/projects/img_to_3d/indexv2.php pretty neato, huh? -seltar
|
|
|
|
seltar
|
Re: Image To 3D
« Reply #4 on: Mar 13th, 2005, 9:32pm » |
|
Woohoo, now it's almost complete! http://wliia.org/projects/img_to_3d/indexv7.php * 3d visualization of the 2d image * Rotate 3d-model by Axis * Edit 3d-model realtime * Switching resolution * Smoothing 3d-model * 2d blending modes * Multiple Source- and Blend-images * Lock on Vertex * Lock on Color * Save Model to Disk or Web * Save Image to Disk (or Web)
|
|
|
|
Ricard
|
Re: Image To 3D
« Reply #5 on: Mar 14th, 2005, 11:12am » |
|
Very nice!! I like the GUI and I find it a smart program to help you know what the blendings do. I would only change one thing, and this is the way we visualize the buffers. I think it would be nice to have 3 buffers (A, B and C=A blend C). We could have the possibility to mesh, swap and copy any of these buffers. And each of them would have a small thumbnail. I think this would make the program much more structured. Just a thought.
|
|
|
|
kurol
|
Re: Image To 3D
« Reply #6 on: Mar 29th, 2005, 12:07pm » |
|
OBTW That application of making landscapes is also called height fields. If you'd liked that and would like to learn more about height fields, check out your local public library or the POV-Ray documentation.
|
I hate programming . . .![](http://img33.exs.cx/img33/453/popeyes1b7oh.gif) ![](http://img33.exs.cx/img33/8339/popeyes1a2he.gif)
|
|
|
|