// Convolution matrix v1.0 // By Hugo Asmussen camera { location <0,0,-1.85> look_at 0 orthographic } light_source { <-80,80,-80>, 1.2 } #default { finish { ambient 1 diffuse 0 } } #declare Input_Width=400; #declare Input_Height=400; #declare Output_Width=75; #declare Output_Height=75; // Input pigment <0,0,0> to <1,1,0> #declare Input=pigment { image_map { function Input_Width,Input_Height { pigment { object { sphere { 0,.3333 } color rgb 1 color rgb 0 } translate <.5,.5,0> } } } } // Convolution Matrix 9*9 /* #local cm=array[9][9] { { 0 0 1 1 1 1 1 0 0 } { 0 1 2 3 3 3 2 1 0 } { 1 2 3 6 7 6 3 2 1 } { 1 3 6 9 11 9 6 3 1 } { 1 3 7 11 12 11 7 3 1 } { 1 3 6 9 11 9 6 3 1 } { 1 2 3 6 7 6 3 2 1 } { 0 1 2 3 3 3 2 1 0 } { 0 0 1 1 1 1 1 0 0 } } */ // Convolution Matrix 3*3 //#local cm=array[3][3] { { 1,1,1 } { 1,2,1 } { 1,1,1 } } // Convolution Matrix 5*5 #local cm=array[5][5] { { 1,1,2,1,1 } { 1,2,2,2,1 } { 1,2,4,2,1 } { 1,2,2,2,1 } { 1,1,2,1,1 } } // No more user definable variables from now on. #local fn_stepX=Output_Width; #local fn_stepY=Output_Height; #local fn=function { pigment { Input scale } } #local cm_size=dimension_size(cm,1)*dimension_size(cm,2); #local cm_maxX=(dimension_size(cm,1)-1)/2; #local cm_maxY=(dimension_size(cm,2)-1)/2; #local New_Array=array[fn_stepX][fn_stepY] // To hold new color values // Blurring #local fn_Y=0; #while (fn_Y/cm_size; // Store pixel value divived by kernel size #local fn_X=fn_X+1; #end #local fn_Y=fn_Y+1; #end // End of loops // Creating object.. should be changed to create a pigment.. #local New_StepX=1/fn_stepX; #local New_StepY=1/fn_stepY; #local New_Object=union{ #local New_Y=0; #local fn_Y=0; #while (fn_Y-.00001, pigment { rgb New_Array[fn_X][fn_Y] } } #local fn_X=fn_X+1; #local New_X=New_X+New_StepX; #end #local fn_Y=fn_Y+1; #local New_Y=New_Y+New_StepY; #end } // Display original image and then blurred image. box { -.5,.5 pigment { Input translate <-.5,-.5,0> } scale <1,1,.1> translate -.6*x } object { New_Object translate <-.5,-.5,0> scale <1,1,.1> translate .6*x } // Outline around images #declare Ramme=union { cylinder { -.6*y,.6*y,.03 translate -.6*x } cylinder { -.6*y,.6*y,.03 translate .6*x } cylinder { -.6*y,.6*y,.03 rotate 90*z translate -.6*y } cylinder { -.6*y,.6*y,.03 rotate 90*z translate .6*y } sphere { <-.6,-.6,0>,.03 } sphere { <.6,-.6,0>,.03 } sphere { <.6,.6,0>,.03 } sphere { <-.6,.6,0>,.03 } pigment { rgb <1,1,0> } finish { ambient .1 specular .25 diffuse .6 } } object { Ramme translate -.6*x } object { Ramme translate .6*x } // Text #default { pigment { rgb 1 } } text { ttf "arial.ttf" "No blur" .01,.01 scale .125 translate <-.825,.7,0> } text { ttf "arial.ttf" "Gaussian blur" .01,.01 scale .125 translate <.225,.7,0> } text { ttf "arial.ttf" concat(str(Input_Width,0,0),"*",str(Input_Height,0,0)),.01,.01 scale .125 translate <-.84,-.8,0> } text { ttf "arial.ttf" concat(str(Output_Width,0,0),"*",str(Output_Height,0,0)),.01,.01 scale .125 pigment { rgb 1 } translate <.46,-.8,0> } // End