POV-Ray : Newsgroups : povray.text.scene-files : povray image processing Server Time
29 Oct 2024 22:45:14 EDT (-0400)
  povray image processing (Message 1 to 1 of 1)  
From: PeterC
Subject: povray image processing
Date: 30 Nov 2001 21:53:05
Message: <3c0844cd.2081780@localhost>
Source for the image posted in the binaries
newsgroup.  This illustrates how povray 3.5 can be used
for some image processing functions, including
converstion to greyscale, to sepia tone, swaping R
& B values, etc.
	To get this to work, replace "otrek_7.tga" with
whatever image you have handy on your computer.

Pete
-- 
#version 3.5;

/* using newer 3.5 features to read in a color picture and render
   it in a scene as a b/w picture

   This version uses the grey level as an index into a color
   gradient.  Can use to this get sepia tones, blueiffied pics,
   or just get plain weird
*/


#macro lazy_map(lm_filename)
  #local lz_sl = strlen(lm_filename);
  #local lz_ext = strlwr(substr(lm_filename, lz_sl - 2, 3))
  #if (strcmp(lz_ext, "tga") = 0)
    tga lm_filename
  #else
    #if (strcmp(lz_ext, "png") = 0)
      png lm_filename
    #else
      #if (strcmp(lz_ext, "gif") = 0)
        gif lm_filename
      #else
        #if (strcmp(lz_ext, "iff") = 0)
          iff lm_filename
        #else
          sys lm_filename
        #end
      #end
    #end
  #end
#end


#macro rnd_rotate()
  rotate <360 * rand(rseed), 360 * rand(rseed), 360 * rand(rseed)>
#end


#macro rnd_translate()
  translate <4 - 8 * rand(rseed), 4 - 8 * rand(rseed), 4 - 8 *
rand(rseed)>
#end


#macro perturb()
  rnd_translate()
  rnd_rotate()
#end


#macro rrand(rlo, rhi)
  #local real_lo = min(rlo, rhi);
  #local real_hi = max(rlo, rhi);
  #local rr_result = real_lo + (rand(rseed) * (real_hi - real_lo));
  rr_result
#end


#macro rnd(nn)
  #local rnd_result = int(rand(rseed) * nn);
  rnd_result
#end


camera {
  location 0
  direction <0, 0, 3.8>
  right <(640 / 480), 0, 0>
  up <0, 1, 0>
  translate <0, 2, -13>  
}


#declare pic_pig = pigment {
  image_map {
    lazy_map("otrek_7.tga")  // replace with your picture
    interpolate 2
  }
  scale 1.001
}


#declare pic_function = function {
  pigment { pic_pig }
}


box { // the piccy as is (color)
  <-0.5, -0.5, 0>, <0.5, 0.5, 0>
  pigment {
    pic_pig
    translate <-0.5, -0.5, 0>
  }
  finish { ambient 0.5 diffuse 0.5 }
  scale <640/480, 1, 1>
  scale 2.1
  translate <0.741, 1.45, 0>
}


box { // the piccy in greyscale
  <-0.5, -0.5, 0>, <0.5, 0.5, 0>
  pigment {
    function {
      pic_function(x, y, z).grey
    }
    color_map {
      [ 0.0 color rgb 0 ]
      [ 1.0 color rgb 1 ]
    }
    translate <-0.5, -0.5, 0>
  }
  finish { ambient 0.5 diffuse 0.5 }
  scale <640/480, 1, 1>
  translate <-1.48, 3.1, 0>
}


box { // the piccy with a sepiatone
  <-0.5, -0.5, 0>, <0.5, 0.5, 0>
  pigment {
    function {
      pic_function(x, y, z).grey
    }
    color_map {
      [ 0.0 color rgb 0 ]
      [ 0.5 color rgb <0.6, 0.5, 0.4> ]
      [ 1.0 color rgb <1, 1, 1> ]
    }
    translate <-0.5, -0.5, 0>
  }
  finish { ambient 0.5 diffuse 0.5 }
  scale <640/480, 1, 1>
  translate <-1.48, 2, 0>
}


box { // the piccy with red and blue components swapped
  <-0.5, -0.5, 0>, <0.5, 0.5, 0>
  pigment {
    average
    pigment_map {
      [ // map blue to red
        function {
          pic_function(x, y, z).blue
        }
        color_map {
          [ 0.0 color rgb 0 ]
          [ 1.0 color rgb <3, 0, 0> ]
        }
      ]
      [ // map green to green
        function {
          pic_function(x, y, z).green
        }
        color_map {
          [ 0.0 color rgb 0 ]
          [ 1.0 color rgb <0, 3, 0> ]
        }
      ]
      [ // map red to blue
        function {
          pic_function(x, y, z).red
        }
        color_map {
          [ 0.0 color rgb 0 ]
          [ 1.0 color rgb <0, 0, 3> ]
        }
      ]
    }
    translate <-0.5, -0.5, 0>
  }
  finish { ambient 0.5 diffuse 0.5 }
  scale <640/480, 1, 1>
  translate <-1.48, 0.9, 0>
}


#declare rainbowpig = pigment {
  gradient <1, 0, 0>
  color_map {
    [ 0.0 color rgb <1, 0, 0> * (2/3) ]
    [ 1/5 color rgb <1, 1, 0> * (2/3) ]
    [ 2/5 color rgb <0, 1, 0> * (2/3) ]
    [ 3/5 color rgb <0, 1, 1> * (2/3) ]
    [ 4/5 color rgb <0, 0, 1> * (2/3) ]
    [ 1.0 color rgb <1, 0, 1> * (2/3) ]
  }
}


box { // the piccy in rainbowgradientvision!
  <-0.5, -0.5, 0>, <0.5, 0.5, 0>
  pigment {
    function {
      pic_function(x, y, z).grey
    }
    pigment_map {
      [ 0.0 color rgb 0 ]
      [ 0.5 rainbowpig ]
      [ 0.8 color rgb 0.8 ]
      [ 1.0 color rgb 1 ]
    }
    translate <-0.5, -0.5, 0>
  }
  finish { ambient 0.5 diffuse 0.5 }
  scale <640/480, 1, 1>
  translate <0, 3.1, 0>
}



box { // the piccy in negative
  <-0.5, -0.5, 0>, <0.5, 0.5, 0>
  pigment {
    average
    pigment_map {
      [ // blue
        function {
          pic_function(x, y, z).blue
        }
        color_map {
          [ 0.0 color rgb <0, 0, 3> ]
          [ 1.0 color rgb <0, 0, 0> ]
        }
      ]
      [ // green
        function {
          pic_function(x, y, z).green
        }
        color_map {
          [ 0.0 color rgb <0, 3, 0> ]
          [ 1.0 color rgb <0, 0, 0> ]
        }
      ]
      [ // red
        function {
          pic_function(x, y, z).red
        }
        color_map {
          [ 0.0 color rgb <3, 0, 0> ]
          [ 1.0 color rgb <0, 0, 0> ]
        }
      ]
    }
    translate <-0.5, -0.5, 0>
  }
  finish { ambient 0.5 diffuse 0.5 }
  scale <640/480, 1, 1>
  translate <1.48, 3.1, 0>
}



plane {
  <0, 0, -1>, -0.05
  pigment { color rgb 1 }
  finish { ambient 0.5 diffuse 0.5 }
}


light_source {
  <0, 0, -3000>
  color rgb 1
  area_light <800, 0, 0>, <0, 800, 0>, 5, 5 adaptive 1
  rotate x*8
  rotate x*30
  rotate y*45
}


/* actual end of this file */


Post a reply to this message

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