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
picsql.jar "select r,g,b from ./test.bmp" "./output.bmp"
Can also be used like a library by including JAR (doc coming soon).
Last released version : 1.0.2
Version 1.0.1
- Load a grid of a same picture with syntax :
select r, g, b
from (./examples/face.bmp, 5, 5)
Picture face.bmp is loaded 25 times in a grid of 5 x 5.
- Launch a simple GUI by add "--gui" flag:
picsql.jar --gui
- Fixes and Gradle updates.
Version 1.0.0
- Access to r,g,b channels and x,y position.
- FROM can load picture, region of picture, colored rectangle or data from subquery.
- 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.
Examples
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
Some maths :
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