Page 1 of 1

Image pixelizer

Posted: Wed Jan 06, 2010 9:41 pm
by ciktor
Original GIF
crikey.gif
Original GIF
crikey.gif (15.31 KiB) Viewed 9890 times
Processed GIF
animated_out.gif
Processed GIF
animated_out.gif (15.99 KiB) Viewed 9889 times

Code: Select all


// input params
pixel_size = 2
treshold = 128 //lower value - brighter output and vice versa
// end of input params

img = load_pixi( "crikey.gif" ) // put your animated gif here or any picture

in_width = get_pixi_xsize (img)
ih_height = get_pixi_ysize (img) 

xsize = in_width * pixel_size
ysize = ih_height * pixel_size

hx = xsize / 2
hy = ysize / 2

resize_pixi( 0, xsize, ysize )

//video_export_gif("animated_out.gif")
start:
clear( BLACK )
pixi( img, 0, 0, pixel_size, 0)

y = -hy

while( y < hy )
{
	x = -hx
	while( x < hx )
	{ 
		col = get_dot (x,y)
		
		red = get_red (col)
		grn = get_green (col)
		blu = get_blue (col)
		
		L = red * red * 241/1000 + grn * grn * 691/1000 + blu * blu * 68/1000 // calculating percieved brightness of a color
		sqrt
		
		if rslt>treshold
		{
			fbox (x,y,pixel_size,pixel_size,WHITE)
		}
		else
		{
			fbox (x,y,pixel_size,pixel_size,BLACK)
		}
		x=x+pixel_size
	}
	y=y+pixel_size
}

frame( 25 )
go start

sqrt:
   rslt = L
   div = L 
   if L <= 0 { ret }
   while (1){
      div = (L / div + div) / 2
      if rslt > div { rslt = div }
      else { ret }
   }
ret

Re: Image pixelizer

Posted: Wed Jan 06, 2010 11:22 pm
by NightRadio
Thank you for great examples!
p.s. Pixilang3 is on the way!

Re: Image pixelizer

Posted: Thu Jan 07, 2010 1:28 am
by ciktor
You're welcome!
Thank you for pixilang!

Vik

Re: Image pixelizer

Posted: Thu Jan 07, 2010 11:07 pm
by ciktor
Hi, this is improved version of pixelizer, with sliding treshold.

This is input (unprocessed picture I used)
Image.

This is output (processed) image
Image,

and this is the code

Code: Select all

// *************************  input params

	pixel_size = 5
	treshold = 100 //lower value - brighter output and vice versa
	treshold_variety = 64 //experiment with this value - larger value causes more dynamic pixels
	resize_image = 0 // 0 - no, 1 - yes
	
// *************************  end of input

start_timer( 0 )
img = load_pixi( "me.jpg" ) // put your image here

in_width = get_pixi_xsize (img)
ih_height = get_pixi_ysize (img) 

if resize_image = 1
{
	xsize = in_width * pixel_size
	ysize = ih_height * pixel_size
}
else
{
	xsize = in_width
	ysize = ih_height
}

hx = xsize / 2
hy = ysize / 2

resize_pixi( 0, xsize, ysize )

//if you want to export ******************
//video_export_avi("animated_out.avi")
//video_export_gif("animated_out.gif")
//****************************************

start:
clear( BLACK )

if resize_image = 1
{
	pixi( img, 0, 0, pixel_size, 0)
}
else
{
	pixi( img, 0, 0, 1, 0)
}

y = -hy

max_rslt = 0

while( y < hy )
{
	x = -hx
	while( x < hx )
	{ 
		rand_seed (get_timer( 0 ) + get_dot (x,y))
		
		col = get_dot (x,y)
		
		red = get_red (col)
		grn = get_green (col)
		blu = get_blue (col)
		
		L = red * red * 241/1000 + grn * grn * 691/1000 + blu * blu * 68/1000 // calculating percieved brightness of a color
		sqrt

		calc_color2 // result is in out_color variable
		fbox (x,y,pixel_size,pixel_size,out_color)
		x=x+pixel_size
	}
	y=y+pixel_size
}

frame( 100 )
go start

sqrt:
   rslt = L
   div = L 
   if L <= 0 { ret }
   while (1){
      div = (L / div + div) / 2
      if rslt > div { rslt = div }
      else { ret }
   }
ret

//this is color calculation from the first version of pixelizer
calc_color1:
	if rslt>treshold
	{
		out_color = WHITE
	}
	else
	{
		out_color = BLACK
	}
ret

//this color calculation is based on probability
calc_color2:
	
	rnd = rand*treshold_variety/32768 //random from 0 to treshold_variety
	
	new_treshold = treshold - treshold_variety/2 + rnd
	if rslt>new_treshold //rslt - brightness from 0 to 256
	{
		out_color = WHITE
	}
	else
	{
		out_color = BLACK
	}
ret


Re: Image pixelizer

Posted: Fri Jan 08, 2010 2:46 am
by Al_Rado
Original!