Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you are going to use SQL select, why use a separate operate statement when you could just use SQL's method for this, update? For that matter, if you are going to use SQL syntax, I would imagine you would want to keep one of the main features, which is joining of datasets. Being able to join an image with itself in some manner (or another image...), would be really useful. Instead of globals, use the images as tables of pixels with those attributes.

Imagine breaking an image down into pixels, actually storing them into a database, performing some queries, and outputting the result. Something equivalent to that (sans database) sounds interesting to me.




Author here- My reason for deviating slightly from traditional SQL syntax is that I don't find it to be super intuitive. Yes, "UPDATE color SET r = 255 WHERE col = 100" is a pretty straightforward looking thing for those of us familiar with SQL, but simple things like the fact that you set the value before deciding what you're setting the value of are a bit off putting. The separation of queries into multiple statements along with this fact lead to just universally cleaner and more consistent looking syntax even as queries get complex.

That said, I'm still very much in the "trying things out" phase w.r.t. syntax 'n such. So the feedback is appreciated! (And you're not the only one who has suggested this...)

Curious what you'd expect the result of a join to be? I assume you mean across multiple images? Currently, that would be a bit odd as the function of "select" exists more along the lines of "composing a mask" more than it does "fetching data", so not entirely sure how that'd fit in. Still very interesting. If you're interested in fleshing that idea out here, it could be helpful for me!

Thanks!


Well, the two initial ideas I had for joining are to join to itself, and to join to another image. For example:

  # Join image to itself but offset by one pixel and report the average of the RGB values
  SELECT (img1_pixel.red+img2_pixel.red)/2
         (img1_pixel.green+img2_pixel.green/2
         (img1_pixel.blue+img2_pixel.blue)/2
  FROM   img1 img1_pixel INNER JOIN img1 img2_pixel
         ON img1_pixel.column = img2_pixel.column
         AND img1_pixel.row = img2_pixel.row+1;

  # Superimpose one image over another, offset by 100 pixels width/height
  UPDATE img1, img2
  SET    img1.rgb = img2.rgb
  WHERE  img1.row = img2.row+100
         AND img1.column = img2.column;


"Curious what you'd expect the result of a join to be?"

When you join two tables in SQL, you typically include an ON expression specifying how you want to relate the tables to each other. Or, put another way, how you want the tables to be aligned.

Extending this to PixQL, the ON clause of a JOIN tells the engine how to align two different images, perhaps by offsets in the x,y directions. You could even extend further to LEFT,RIGHT,OUTER,INNER joins where it crops one image to the boundary of the other depending on the join type.

Assuming a more fleshed out FROM syntax (see my other comment) with alias support, you could select the same image multiple times but at different offsets to facilitate a blur.


You can imagine composing a mask from several images using Join or Union. Summing up images to make HDR, only on some areas of the pictures based on different criteria to produce the mask.

Another possibility would be to output a mosaic based on properties of a set of pictures.

I also vote for the use of UPDATE and also the use of INSERT to insert some part of image 1 x mask in image 2 x mask, or insert geometric features x mask.

I think this project is a great idea, thanks for submiting it.


What if you dropped the whole `OPERATE SET x = y` syntax, and instead used traditional SELECT syntax, with column names as the attribute name to change. Editing your simple examples:

    # turn all red pixels green
    # omitting column name assumes COLOR
    pixql -i in.bmp -o out.bmp -q "SELECT #00FF00FF WHERE COLOR = #FF0000FF;"
    
    # copy red channel into green channel
    pixql -i in.bmp -o out.bmp -q "SELECT R AS G;"
    
    # add white 1px 100x100 grid
    pixql -i in.bmp -o out.bmp -q "SELECT WHITE AS COLOR WHERE ROW % 100 = 0 OR COL % 100 = 0;"
Edit: Combining this with a "FROM" syntax on your last example:

    SELECT 255-R AS R, 255-G AS G, 255-B AS B
    FROM (SELECT WHITE WHERE ROW % 20 < 10 FROM BLACK(100,100))
    WHERE COL % 20 < 10;


There are lots of fun things you can do with a few gigs of images and an inverted index.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: