Image pixelizer

Post Reply
User avatar
ciktor
Posts: 6
Joined: Wed Jan 06, 2010 6:45 pm
Location: Belgrade, Serbia
Contact:

Image pixelizer

Post by ciktor » Wed Jan 06, 2010 9:41 pm

Original GIF
crikey.gif
Original GIF
crikey.gif (15.31 KiB) Viewed 9138 times
Processed GIF
animated_out.gif
Processed GIF
animated_out.gif (15.99 KiB) Viewed 9137 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
Last edited by ciktor on Thu Jan 07, 2010 1:45 am, edited 1 time in total.
I see light. I hear sound. I feel touch.

User avatar
NightRadio
Site Admin
Posts: 3029
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: Image pixelizer

Post by NightRadio » Wed Jan 06, 2010 11:22 pm

Thank you for great examples!
p.s. Pixilang3 is on the way!

User avatar
ciktor
Posts: 6
Joined: Wed Jan 06, 2010 6:45 pm
Location: Belgrade, Serbia
Contact:

Re: Image pixelizer

Post by ciktor » Thu Jan 07, 2010 1:28 am

You're welcome!
Thank you for pixilang!

Vik
I see light. I hear sound. I feel touch.

User avatar
ciktor
Posts: 6
Joined: Wed Jan 06, 2010 6:45 pm
Location: Belgrade, Serbia
Contact:

Re: Image pixelizer

Post by ciktor » Thu Jan 07, 2010 11:07 pm

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

I see light. I hear sound. I feel touch.

User avatar
Al_Rado
Posts: 239
Joined: Tue Dec 04, 2007 2:33 pm
Location: Krasnodar
Contact:

Re: Image pixelizer

Post by Al_Rado » Fri Jan 08, 2010 2:46 am

Original!
ВекторКодПиксельПолигон - ВотЧтоЯЛюблю!

Post Reply