On Wed, Oct 27, 1999 at 10:23:17AM -0700, [EMAIL PROTECTED] wrote:
> Hi, there,
> I am using Gimp-Perl v1.083 to manipulate the pixel data of an image.
While that version should work, I fixed a great many errors in PDL support
since then, and there were also behavioural changes (like an extra dummy
dimension for greyscale data) that make working with pixels easier, but
breaks backwards compatibility.
It would be a good idea to upgrade to 1.14.
> What I am confusing about is the data structure of the packed pixel
> data. For example, I can run the following perl code:
> $region = $drawable->get->pixel_rgn (0,0, 100,100, 1,0);
> $pixel = $region->get_pixel (5,7); # fetches the pixel from
> print $pixel; # outputs something like
> # [255, 127, 0], i.e. in
> # RGB format ;)
> But how can I modify the components of this $pixel? For example, modify
> it to [255,127,1]?
The pixels look like arrays, but are, in fact, PDL objects (i.e. some kind
of array ;)
> I have tried to treat it as an array or an array reference, but I
> failed. Any help is greatly appreciated.
You can treat it as a vector (or an array of vectors for two-dimensional
$pixel = ($pixel + 100) / 2;
$pixel = 255 * $pixel / max($pixel);
will do the obvious scalar arithmetic to the pixel (or pixels). You can
use "at" and "set" to get or set subvalues, but this is (of course) slow
if you do it often.
I recommend that you check the PDL::Impatient manpage for a quick overview
(just enter "perldoc PDL::Impatient" at the prompt).
If any questions remain then just ask me ;)
----==-- _ |
---==---(_)__ __ ____ __ Marc Lehmann +--
--==---/ / _ \/ // /\ \/ / [EMAIL PROTECTED] |e|
-=====/_/_//_/\_,_/ /_/\_\ XX11-RIPE --+
The choice of a GNU generation |