image processing

Started by 0x69, July 25, 2010, 02:33:25 AM

Previous topic - Next topic

0x69

Hi,



I want to manipulate individual pixels of image - is it possible in newLISP ?

That is, I want to get RGB values of each pixel and change these values by my needs.

[If such functionality isn't there - maybe newLISP can be extended to support that ? If so - when ? :) ]



Thanks for answer.

0x69

#1
As for now -I found workarround - read,modify & save PPM image file. It's trivial to work with http://en.wikipedia.org/wiki/Netpbm_format">PPM images, because format is very simple, kinda-

P3
# The P3 means colors are in ASCII, then 3 x 2 image size, then 255 for max color, then RGB triplets
3 2
255
255   0   0     0 255   0     0   0 255
255 255   0   255 255 255     0   0   0

Happy image processing !

cormullion

#2
I don't think you can do it newLISP-GS.



You can (sort of) do it with HTML5 canvas, although this involves so much intermediate JavaScript as to be depressingly slow. The relevant bits of the code I hacked together are:



(write-buffer page [text]
<script type="text/javascript" language="javascript" charset="utf-8">
    var a_canvas = document.getElementById("a");
    var a_context = a_canvas.getContext("2d");
    var input = a_context.getImageData(0, 0, a_canvas.width, a_canvas.height);
    var output = a_context.createImageData(a_canvas.width, a_canvas.height);
    var w = input.width, h = input.height;
    var inputData = input.data;
    var oD = output.data;
[/text])

; set pixel c to colour (where colour is RGB list eg  (0 0 0)):
(write-buffer page
   (string
        "oD[" c "] = "         (first colour) ";n"
        "oD[" (+ c 1) "] = " (colour 1) ";n"
        "oD[" (+ c 2) "] = " (colour 2) ";n"
        "oD[" (+ c 3) "] = " 200 ";n")

; and to output the array
(write-buffer page {
   a_context.putImageData(output, 0, 0);
  })


Have you seen onographic - here's my Mandelbrot attempt http://www.dmemos.de/onographic/contributions.htm">//http://www.dmemos.de/onographic/contributions.htm with a version of didi's code. (I used a PPM to PNG converter, since PPM files aren't that useful...)