Skip to content
/ picsql Public

A Java library to query pictures with SQL-like language.

License

Notifications You must be signed in to change notification settings

olcav/picsql

Repository files navigation

PicSQL

A Java library to query pictures with SQL-like language.

Features :

  • Select and manipulate pixels of pictures in your disk with SQL-like dialect (only BMP at this time).
  • Access to each color channel r,b,g and pixel position : x,y, rank().
  • Can query any number of pictures in the FROM clause, load only a region or subquery or build a colored rectangle.
  • Math operators : *, /, +, -, %.
  • Math functions: rand, pi, cos, sin, tan.
  • Where clause with boolean operators : and / or.
  • Lag and lead to get relative pixels from a position.
  • Simple editor with execution of query in real time.

Launch with command line

java -jar picsql.jar "select r,g,b from ./test.bmp" "./output.bmp"

Launch a GUI

java -jar picsql.jar --gui

Last released version : 1.0.5


Examples

Select RGB Channels

Select only region

Select and create i * j grid

Create a colored rectangle

Blend colors

Play with x and y

Only x and y

Where condition

Where condition on two values

Maths functions

Lag and Lead

Complex lag and lead

Nested lag and lead

Picture blending

Picture blending madness

Subqueries

Convolution Mask

Discretization function

Flip a channel on x, y or xy axis

Butter function

GIF animation

Test pictures :

face.bmp

face2.bmp


Select r,g,b channels

select r, g, b
from./examples/face.bmp -- same image that original, we rebuild it.


Select only region

select r, g, b
from (. / examples / face . bmp, 10, 50, 120, 120) -- (x,y,width,height) of a region


Select and create i * j grid

select r, g, b
from (./examples/face.bmp, 5, 5)


Create a colored rectangle

select r, g, b
from (100, 100, 255, 0, 0) -- (width,height, r, g, b)


Blend colors

select g, b, r
from./examples/face.bmp -- put green in red, blue in green and red in blue.


Play with x and y

select (r * y)%255, x,  b
from./examples/face.bmp


Only x and y

select x * 2, y + 10, x - 10
from./examples/face.bmp -- same size than face.bmp


Where condition

select r, g, b
from./examples/face.bmp
where r > 120


Where condition on two values

select r, g, b
from./examples/face.bmp
where r > 20 and g < 200


Maths functions

select (r * sin(x))%255, 
       (g*tan(y))%255, 
       (cos(r))%255
from./examples/face.bmp


Lag and lead

select lag(r, 10, 10), --lag select a red value at x-10, y-10
       lead(g, 5, 5),  --lead green value at +5,+5.
       g
from./examples/face.bmp, 


Complex Lag and lead

select lag(r, sin(x), (r * g)%10),
       lag(r, y%10, rank()%10),
       lead(b, 10, 15)
from./examples/face.bmp


Nested Lag and lead

-- Lag, lead or other functions can be nested
select lag(r, lag(g, 5, 5)%5, 5),
       lag(g, 10, lag(r, 5, 5)%5),
       lag(r,
           lag(g, 5, 15)%20,
           lead(g, 15, 5)%10
           )
from./examples/face.bmp


Picture blending

select f.r, -- reference the red of the first picture
       f.g, -- reference the green of the first picture
       f2.b -- reference to the blue of the second picture
from
    ./examples/face.bmp f, -- alias is necessary with more than one picture
    ./examples/face2.bmp f2


Picture blending madness

select (f.r + f2.b)%255, 
       lead(f.r, f2.b%10, 10), 
       f.g
from./examples/face.bmp f, ./examples/face2.bmp f2


Subqueries

select sub1.r,
       sub2.g,
       (sub2.b + sub1.r)%255
from
    (select r from./examples/face.bmp where r > 60) sub1,
    (select b, g, lag(r, 5, 5) from./examples/face2.bmp) sub2


Convolution Mask

A convolution mask is a 9 values array, that will be applied on each pixel of the picture. Each value in the array take a different value of a channel relative to the pixel. The result is the sum of the values divided by nine.

So if x is the pixel, and x1, x2, x3, x4, x5, x6, x7, x8 are the pixels around x, the convolution mask is :

x1 | x2 | x3
x4 | x  | x5
x6 | x7 | x8

So value of red channel x.r is : (x1.r + x2.r + x3.r + x4.r + x.r + x5.r + x6.r + x7.r + x8.r) / 9

select r,
[-r,-b,-g,b*2,r,r,r,g*2,b],
[b,-b,b*2,r*r,b,g,b,-g,g]
from ./examples/face.bmp


Discretization function

Take a value of a channel and return a value between 0 and 255, with a step of 255 / step.

select
    discr(r, 10),
    discr(r, 5),
    discr(g, 3)
from ./examples/face.bmp


Flip a channel on x, y or xy axis

select
flip(r, x),
flip(g, x),
flip(b, x)
from ./examples/face.bmp

Ugly example:

select
    flip(r, x),
    flip(g, xy),
    flip(b, xy)
from ./examples/face.bmp

Butter function

Select r, g or b color channel of the real butter color !

select
    butter(r),
    g,
    butter(b)
from ./examples/face.bmp

Kalon vat !

GIF animation

select lag(r, 5, t%20), (g*t)%255, (t * 10) % 255 
from (./examples/face.bmp, 50)

Create a GIF by applying 50 times the query on the same picture, with increments "t" from 0 to 50.

Run query like that :

java -jar picsql.jar "select lag(r, 5, t%20), (g*t)%255, (t * 10) % 255 from (./examples/face.bmp, 50)" "test.gif"

Result:

About

A Java library to query pictures with SQL-like language.

Resources

License

Stars

Watchers

Forks

Packages

No packages published