It is currently Tue Nov 03, 2026 1:34 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Script fails on images over 250x200 pixels as array maxes out at 49998
PostPosted: Thu Aug 27, 2015 6:59 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 205
A script I’ve written sets an array equal to the number of pixels in an image, on images less than 250 x 200 pixels the script works but on larger images it fails. It seems in Scheme the maximum size of an array is 49998 cells, trying to set more and the script hangs. While 49998 is not a big number in computing I assume Scheme may be reserving hundreds or thousands of bytes for each cell, whereas I only need each cell to equal 1 byte to store values up to 255. I wonder if there a way round this or another way of storing data for manipulation in a script

Thanks for looking

Steve


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Thu Aug 27, 2015 7:47 am  (#2) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
You can use a vector of vectors.

(define array (make-vector height (make-vector width 0)))



However, you should double-check your general approach. Is it possible to process the data a bit at a time, leaving the actual data "stored" in the original drawable or a copy? A channel is an extremely efficient means of storing the data, though accessing is rather slow.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Thu Aug 27, 2015 9:53 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 205
saulgoode wrote:
You can use a vector of vectors.

(define array (make-vector height (make-vector width 0)))

Thank you, that might do the job, will try it out

saulgoode wrote:
However, you should double-check your general approach. Is it possible to process the data a bit at a time, leaving the actual data "stored" in the original drawable or a copy? A channel is an extremely efficient means of storing the data, though accessing is rather slow.

To give an idea what I’m doing, for each pixel in a B&W image (excepting the edge pixels), the surrounding 8 pixels values are added then divided by 8 to get the average, this average is then compared against the value of the centre pixel which is manipulated as desired, a sort of de-noise script.

I did try processing the data in (blocks of nine pixels) but as every pixel has to have the data from each bounding pixel brought from the PB it was 4 times slower than getting each value from the PB once and setting it into a large array, then using the data in the array to perform the maths before storing the result in a second drawable.

Thanks again, will look into vector of vectors, new territory for me

Steve


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Thu Aug 27, 2015 11:43 am  (#4) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Steve wrote:
To give an idea what I’m doing, for each pixel in a B&W image (excepting the edge pixels), the surrounding 8 pixels values are added then divided by 8 to get the average, this average is then compared against the value of the centre pixel which is manipulated as desired, a sort of de-noise script.
Wouldn't that be do-able by applying a fixed convolution ("Filters->Generic->Convolution Matrix")?

(plug-in-convmatrix
  RUN-NONINTERACTIVE
  image
  layer
  25 ; always 5x5 matrix
  #(0  0  0  0  0
    0  1  1  1  0
    0  1 -1  1  0
    0  1  1  1  0
    0  0  0  0  0)
  0 ; no alpha weighting
  8 ; divisor
  0 ; no offset
  5 ; always five (gray red green blue alpha)
  #(0 1 1 1 0) ; RGB (for grayscale image would be 1 0 0 0 0)
  0 ; "EXTEND" edge mode
  )

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Thu Aug 27, 2015 1:57 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 205
saulgoode wrote:
Steve wrote:
To give an idea what I’m doing, for each pixel in a B&W image (excepting the edge pixels), the surrounding 8 pixels values are added then divided by 8 to get the average, this average is then compared against the value of the centre pixel which is manipulated as desired, a sort of de-noise script.
Wouldn't that be do-able by applying a fixed convolution ("Filters->Generic->Convolution Matrix")?

(plug-in-convmatrix
  RUN-NONINTERACTIVE
  image
  layer
  25 ; always 5x5 matrix
  #(0  0  0  0  0
    0  1  1  1  0
    0  1 -1  1  0
    0  1  1  1  0
    0  0  0  0  0)
  0 ; no alpha weighting
  8 ; divisor
  0 ; no offset
  5 ; always five (gray red green blue alpha)
  #(0 1 1 1 0) ; RGB (for grayscale image would be 1 0 0 0 0)
  0 ; "EXTEND" edge mode
  )

Thanks, that looks like it might do the trick, its something I will try out and utilise where I can. I’m sure it will trump my script on all bases, and yet I find a certain satisfaction in using scripts that I’ve written myself (no offence meant) which is why I’m plugging away with this one.

I tried the vector of vectors in the SFC and a 320 x 320 worked, this gives me double the number of cells I previously had :)

Thanks again, I appreciate the time taken


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Thu Aug 27, 2015 4:38 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Steve wrote:
saulgoode wrote:
Steve wrote:
To give an idea what I’m doing, for each pixel in a B&W image (excepting the edge pixels), the surrounding 8 pixels values are added then divided by 8 to get the average, this average is then compared against the value of the centre pixel which is manipulated as desired, a sort of de-noise script.
Wouldn't that be do-able by applying a fixed convolution ("Filters->Generic->Convolution Matrix")?

(plug-in-convmatrix
  RUN-NONINTERACTIVE
  image
  layer
  25 ; always 5x5 matrix
  #(0  0  0  0  0
    0  1  1  1  0
    0  1 -1  1  0
    0  1  1  1  0
    0  0  0  0  0)
  0 ; no alpha weighting
  8 ; divisor
  0 ; no offset
  5 ; always five (gray red green blue alpha)
  #(0 1 1 1 0) ; RGB (for grayscale image would be 1 0 0 0 0)
  0 ; "EXTEND" edge mode
  )

Thanks, that looks like it might do the trick, its something I will try out and utilise where I can. I’m sure it will trump my script on all bases, and yet I find a certain satisfaction in using scripts that I’ve written myself (no offence meant) which is why I’m plugging away with this one.

I tried the vector of vectors in the SFC and a 320 x 320 worked, this gives me double the number of cells I previously had :)

Thanks again, I appreciate the time taken

The difference between a script and a program is that that the script strives to have most of the computing done in the commands, and is just some (hopefully clever) glue between these.

If you really want to work pixel by pixel, use C, or at least Python (there is an efficient interface to pixels in the Python API) otherwise you'll never use you script on images bigger than 300x300 anyway.

_________________
Image


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Fri Aug 28, 2015 1:37 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 205
ofnuts wrote:
The difference between a script and a program is that that the script strives to have most of the computing done in the commands, and is just some (hopefully clever) glue between these.

If you really want to work pixel by pixel, use C, or at least Python (there is an efficient interface to pixels in the Python API) otherwise you'll never use you script on images bigger than 300x300 anyway.

I keep trying Python but find it more difficult than Scheme in how it relates or interfaces with gimp. I opened .scm files to see/learn how Scheme related to gimp, opening .py files to see/learn doesn’t seem as straightforward or as intuitive, perhaps it is but I just haven’t grasped it yet.


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Fri Aug 28, 2015 3:30 am  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Steve wrote:
ofnuts wrote:
The difference between a script and a program is that that the script strives to have most of the computing done in the commands, and is just some (hopefully clever) glue between these.

If you really want to work pixel by pixel, use C, or at least Python (there is an efficient interface to pixels in the Python API) otherwise you'll never use you script on images bigger than 300x300 anyway.

I keep trying Python but find it more difficult than Scheme in how it relates or interfaces with gimp. I opened .scm files to see/learn how Scheme related to gimp, opening .py files to see/learn doesn’t seem as straightforward or as intuitive, perhaps it is but I just haven’t grasped it yet.


In Python, either you use just the pdb.* methods that are completely direct equivalents of the Scheme functions, or you use the object methods/attributes that are really shorthand for the same. Speaking of intuitiveness, see this again :)

_________________
Image


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Fri Aug 28, 2015 6:11 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Aug 13, 2015
Posts: 312
Location: Somewhere between lost and found.
HAH! I knew that silly script would be good for something...Examples!

_________________
The answer was 42. The question is long forgotten. The computer that solved it is now destroyed.
The MK-2 has been built. Should this be the next question?
(Solve if you can ... ;) )
Image


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Fri Aug 28, 2015 11:11 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: Dec 26, 2014
Posts: 205
ofnuts wrote:
Steve wrote:
ofnuts wrote:
The difference between a script and a program is that that the script strives to have most of the computing done in the commands, and is just some (hopefully clever) glue between these.

If you really want to work pixel by pixel, use C, or at least Python (there is an efficient interface to pixels in the Python API) otherwise you'll never use you script on images bigger than 300x300 anyway.

I keep trying Python but find it more difficult than Scheme in how it relates or interfaces with gimp. I opened .scm files to see/learn how Scheme related to gimp, opening .py files to see/learn doesn’t seem as straightforward or as intuitive, perhaps it is but I just haven’t grasped it yet.


In Python, either you use just the pdb.* methods that are completely direct equivalents of the Scheme functions, or you use the object methods/attributes that are really shorthand for the same. Speaking of intuitiveness, see this again :)


As i was struggling my attempts were half hearted, i gave up too easily, will try again and hopefully stick with it. The python code in the link does give a good idea of what it does :)


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Fri Aug 28, 2015 2:11 pm  (#11) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Steve wrote:
The python code in the link does give a good idea of what it does :)

And the Script-fu code in the link is a poorly written example of how to write in Scheme (one might suspect it was written by one versed only in the art of imperative programming).

(define (script-fu-hide-all-layers image)
  (map (lambda (x) (gimp-item-set-visible x FALSE))
       (vector->list (cadr (gimp-image-get-layers image)))))

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Script fails on images over 250x200 pixels as array maxes out at 4
PostPosted: Fri Aug 28, 2015 2:25 pm  (#12) 
Offline
GimpChat Member
User avatar

Joined: Aug 13, 2015
Posts: 312
Location: Somewhere between lost and found.
Well, in 30 years of coding of coding I've never heard that term, but it might apply who knows. It was just my very first attempt at scheme. ;)

_________________
The answer was 42. The question is long forgotten. The computer that solved it is now destroyed.
The MK-2 has been built. Should this be the next question?
(Solve if you can ... ;) )
Image


Top
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group