POV-Ray : Newsgroups : povray.advanced-users : How to read an image pixel by pixel, and a question : How to read an image pixel by pixel, and a question Server Time
29 Jul 2024 06:27:44 EDT (-0400)
  How to read an image pixel by pixel, and a question  
From: normdoering
Date: 11 Nov 2002 04:25:11
Message: <web.3dcf7587da80818e1dffbb4f0@news.povray.org>
In my quest to write some macros that can turn special 2D pencil drawings
into mesh2 models (like human figures and faces that are photographically
real) I've figured out how to read an imported picture pixel by pixel.

However, I'd also like to know how to get a picture's size in pixels using a
POV feature (if there is any) because right now I'm reading those from
Corel and typing them in.

Here's the scene file:

//=================================================================
#version 3.5;
#include "colors.inc"
global_settings { assumed_gamma 1.0 }
// ----------------------------------------

camera
{ location  <0, 0, -850.0>
  look_at   <0, 0, 0>
  angle 35
}
background {rgb <0.5, 0.5, 0.5>}

//No light source needed to test these assumptions uses ambient finish
// -----------------------------
// the test:
//==============================
#declare xPixels = 271; // 271 is number of pixels in x dimension
#declare yPixels = 496; // 496 in y dimension
// ---> How do I get these numbers without having to declare them?
// That is, how can I ask for the size of an image in pixels?

#declare ScX = 1;    // scale has to be declared because it's shared with
the
#declare ScY = 1.83; // #while loop. Difference in scale because the
function
                     // wants to create a square picture and fills the
square
                     // area from (x,y) coordinates (0,0) to (1,1)
regardless
                     // of the image's original size in pixels.

// these mark how the picture goes exactly to upper right quadrant
cylinder {-200*x, 200*x, 1 pigment {rgb <1,1,0>} finish {ambient 1}}
cylinder {-200*y, 200*y, 1 pigment {rgb <1,1,0>} finish {ambient 1}}


#declare MyTesti = function    // In order to get the HF_ macros to read
{ pigment                      // imported pictures they have to be
  { image_map                  // declared this way.
    { jpeg "12.jpg" map_type 0 // <----
      once
    }
    scale <ScX, ScY, 1>
  }
}
#declare MyTest = function {MyTesti(x,y,z).grey} // then redeclared
                                                 // because
                                                 // they're the wrong data
                                                 // type
#declare Resx = xPixels/6; // actual size takes too long to render
#declare Resy = yPixels/6; // so I divide it by 6

#declare incx = 1/Resx;
#declare incy = 1/Resy;

#declare yloc = 0;            // This loop can read a picture one pixel at a
#while (yloc < ScY + 0.0001)  // time.
#declare xloc = 0;
#while (xloc < ScX + 0.0001)

sphere
 { <xloc*50, yloc*50, -5> 0.5
   pigment { rgb <MyTest(xloc,yloc,0), MyTest(xloc,yloc,0),
MyTest(xloc,yloc,0)>}
   finish {ambient 1}
 }

#declare xloc = xloc+incx;
#end
#declare yloc = yloc+incy;
#end
//=================================================================

The above code will read a picture, potentially pixel by pixel, and copy it
to a structure made of spheres.

-- normdoering


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.