This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > PainShop Pro Scripting > October 2007 > Accessing pixel data





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Accessing pixel data
Big Bad Dave

2007-10-28, 4:17 am

Hi fellow scripters
Do any of you clever people know whether it's possible for a script to
access the pixel data of an open image directly?
I'm trying to think of a way of performing an image processing operation
without having to get into the complications of creating a plugin.
I did try using the EyeDropper command, but it took about ten seconds just
to read a single line of the image, so that's out.
Thanks
DaveP


Big Bad Dave

2007-10-28, 4:17 am

Big Bad Dave wrote:
> Hi fellow scripters
> Do any of you clever people know whether it's possible for a script to
> access the pixel data of an open image directly?
> I'm trying to think of a way of performing an image processing
> operation without having to get into the complications of creating a
> plugin. I did try using the EyeDropper command, but it took about ten
> seconds
> just to read a single line of the image, so that's out.
> Thanks
> DaveP


I've just had another thought. Is it possible for a script to access the
windows clipboard data? If so, I can copy the image to the clipboard,
process it, then paste it back as a new layer.
DaveP


Spandex Rutabaga

2007-10-28, 7:20 pm

Big Bad Dave wrote:
>
> Hi fellow scripters
> Do any of you clever people know whether it's possible for a script to
> access the pixel data of an open image directly?


Use the Eyedropper tool command with a sample size of 1x1 pixel.

> I'm trying to think of a way of performing an image processing operation
> without having to get into the complications of creating a plugin.


As you have discovered, executing as many commands in a script as
there are pixels is an extremely inefficient and silly way to go.
It doesn't help that each script command must be interpreted
instead of being compiled ahead of time.

Why does your pseudo-plug-in need to know the pixel values anyway?
Does it not do point operations (i.e. does the result value of a
pixel depend not just on the original value but also on the values
of surrounding pixels)? If it does point operations you just need
to implement some type of tone curve and so don't need the original
pixel values. Otherwise, however, you do have a problem.

> I did try using the EyeDropper command, but it took about ten seconds just
> to read a single line of the image, so that's out.


Yes quite. There are actually programming kits for creating plug-ins,
which facilitate their creation. However, if you insist on a script
your best bet is probably to dump the image data to a temporary
file, such as Graphics (not camera) RAW (binary) or Portable Bitmap,
PBM (Ascii). Then your script can loop over the file contents to
create new values according to your recipe. Finally, you read a
modified file back into PSP. In this way you will have cut down
potentially millions of PSP commands to two commands: file write
and file read. For maximum speed the file transformations can be
done with a compiled (not interpreted) program under script control.
A script that does these things will, of course, have to be a
trusted script.
Bruce

2007-10-29, 4:17 am

Hi DaveP

Python has a very rich set of tools that can be used to process your
image pixel-by-pixel outside of Paint Shop Pro.

The only problem is that each PSP version is locked into a specific
version of Python (e.g., PSP 9.01 uses Python 2.3.3), which means that
you can't easily use any of the powerful 3rd party Python image
libraries (like PIL).

I have been experimenting successfully with pixels manipulation by doing
the following steps in a script:
1. Save the image to a file
2. Open the image to a Python canvas
3. Do whatever you need to do to the pixels
4. Save the image from the Python canvas
5. Open for PSP.

Attached is a Python basic canvas that I use.

pure_canvas.py must be copied to the paint shop pro Python libraries folder.

The bw_pixel_play script is an example where I adjust the color of each
pixel in a 400x400 grid according to its x-y position.

A small inconvenience in my script is that item 5 starts the PSP
OpenFile dialog. Maybe one of the experts can tell us how to open a file
without the dialog.

Bruce


Big Bad Dave wrote:
> Big Bad Dave wrote:
>
> I've just had another thought. Is it possible for a script to access the
> windows clipboard data? If so, I can copy the image to the clipboard,
> process it, then paste it back as a new layer.
> DaveP
>
>



Spandex Rutabaga

2007-10-29, 4:17 am

Bruce wrote:
>
> Hi DaveP
>
> Python has a very rich set of tools that can be used to process your
> image pixel-by-pixel outside of Paint Shop Pro.
>
> The only problem is that each PSP version is locked into a specific
> version of Python (e.g., PSP 9.01 uses Python 2.3.3), which means that
> you can't easily use any of the powerful 3rd party Python image
> libraries (like PIL).
>
> I have been experimenting successfully with pixels manipulation by doing
> the following steps in a script:
> 1. Save the image to a file
> 2. Open the image to a Python canvas
> 3. Do whatever you need to do to the pixels
> 4. Save the image from the Python canvas
> 5. Open for PSP.


Can you help me understand why you can't simply write a file of
image values and process an array of these values however you
want? Why do Python canvases need to enter the picture (if you'll
pardon the pun)?

> # calculate perceptive grayscale value


I think you mean perceptual rather than perceptive. Also, to
get the perceptual value you need something like LAB lightness.

> def grayscale(c):
> return int(c[0]*0.3 + c[1]*0.59 + c[2]*0.11)


You can find the recipe for LAB lightness here:
http://www.easyrgb.com/math.php?MATH=M2#text2
http://www.easyrgb.com/math.php?MATH=M7#text7
Bruce

2007-10-29, 4:17 am

My background of image processing is limited so I use a canvas because
it has the build-in ability to save bmp, gif, png...

But, you are probably right. If it is possible to write a file of rgb
values, this would be much more efficient for pixel processing.

How would you save an existing image to a rgb data file?

Bruce


Spandex Rutabaga wrote:
> Bruce wrote:
>
> Can you help me understand why you can't simply write a file of
> image values and process an array of these values however you
> want? Why do Python canvases need to enter the picture (if you'll
> pardon the pun)?
>
>
> I think you mean perceptual rather than perceptive. Also, to
> get the perceptual value you need something like LAB lightness.
>
>
> You can find the recipe for LAB lightness here:
> http://www.easyrgb.com/math.php?MATH=M2#text2
> http://www.easyrgb.com/math.php?MATH=M7#text7

Spandex Rutabaga

2007-10-29, 7:17 am

Bruce wrote:

> How would you save an existing image to a rgb data file?


Binary data as Graphics RAW, Ascii data as Portable bitmap (PBM).
Bruce

2007-10-30, 4:17 am

Thanks,

PBM seems to be black and white only (file of 0 or 1), so I'll drop that
one.

The RAW graphic format seems to be a good option. From what I can tell,
this is a simple list of RGB values (headless RAW).

Bruce

Spandex Rutabaga wrote:
> Bruce wrote:
>
>
> Binary data as Graphics RAW, Ascii data as Portable bitmap (PBM).

Spandex Rutabaga

2007-10-30, 7:20 pm

Bruce wrote:

> PBM seems to be black and white only (file of 0 or 1), so I'll drop that
> one.


Sorry, my mistake. I meant to specify Portable Pixel Map (PPM).
Not to be confused with PBM or PGM or PDF :)

> The RAW graphic format seems to be a good option. From what I can tell,
> this is a simple list of RGB values (headless RAW).


PPM gives you the image pixel dimensions at the start, which can
be more convenient.
[color=darkred]
> Spandex Rutabaga wrote:
Sponsored Links


Copyright 2003 - 2009 forum4designers.com  Software forum  Computer Hardware reviews