RSS/Atom feed Twitter
Site is read-only, email is disabled

Script-fu primitive wishlist: islands, integrals/sums, and data files

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

7 of 7 messages available
Toggle history

Please log in to manage your subscriptions.

Script-fu primitive wishlist: islands, integrals/sums, and data files Adam C Powell IV 31 Oct 12:21
  Script-fu primitive wishlist: islands, integrals/sums, and data files David Gowers 31 Oct 15:32
   Script-fu primitive wishlist: islands, integrals/sums, and data files Adam C Powell IV 31 Oct 21:33
   Script-fu primitive wishlist: islands, integrals/sums, and data files Kevin Cozens 01 Nov 00:27
    Script-fu primitive wishlist: islands, integrals/sums, and data files saulgoode@flashingtwelve.brickfilms.com 01 Nov 02:20
    Script-fu primitive wishlist: islands, integrals/sums, and data files Adam C Powell IV 01 Nov 13:47
     Script-fu primitive wishlist: islands, integrals/sums, and data files saulgoode@flashingtwelve.brickfilms.com 01 Nov 19:02
Adam C Powell IV
2008-10-31 12:21:12 UTC (over 15 years ago)

Script-fu primitive wishlist: islands, integrals/sums, and data files

Greetings,

I am working on an image processing plug-in (which I'll offer for upstream contribution BSD-licensed), and would really like to have a couple of primitives that I can't find.

One is finding "islands" in an image: take a channel and create new layers each with one contiguous region in the channel. So if the channel has ten islands, create ten new layers, each with one of the islands. Since this could be unwieldy (too many new layers), one new layer with one island would suffice; one could then process that island layer, subtract it from the original, and move on.

Another is integrals: zero, first and second moments, or alternatively, integrals/sums of channel intensity, x- and y-weighted intensity, and x^2, y^2 and xy-weighted intensity. This lets me fit an ellipse to an island, and then display major and minor axes.

Finally, opening and storing data files. I'd like to be able to create a CSV file with statistics of the islands: size, centroid, aspect ratio (major/minor axis ratio), major axis orientation. One could then further process these statistics in a spreadsheet or other program.

I can do the first two in scheme, though it would be slow, but tolerable for my needs. I don't see a script-fu primitive which would let me do the last.

If there are other packages which can do this, that would be helpful. But having it in the same program/UI as GIMP, with all of its other image manipulation tools, and with its presence across platforms, would be even better. I'd love to have your ideas.

Cheers, -Adam

David Gowers
2008-10-31 15:32:14 UTC (over 15 years ago)

Script-fu primitive wishlist: islands, integrals/sums, and data files

Hi Adam,

On Fri, Oct 31, 2008 at 9:51 PM, Adam C Powell IV wrote:

Greetings,

I am working on an image processing plug-in (which I'll offer for upstream contribution BSD-licensed), and would really like to have a couple of primitives that I can't find.

One is finding "islands" in an image: take a channel and create new layers each with one contiguous region in the channel. So if the channel has ten islands, create ten new layers, each with one of the islands. Since this could be unwieldy (too many new layers), one new layer with one island would suffice; one could then process that island layer, subtract it from the original, and move on.

Another is integrals: zero, first and second moments, or alternatively, integrals/sums of channel intensity, x- and y-weighted intensity, and x^2, y^2 and xy-weighted intensity. This lets me fit an ellipse to an island, and then display major and minor axes.

Finally, opening and storing data files. I'd like to be able to create a CSV file with statistics of the islands: size, centroid, aspect ratio (major/minor axis ratio), major axis orientation. One could then further process these statistics in a spreadsheet or other program.

I can do the first two in scheme, though it would be slow, but tolerable for my needs. I don't see a script-fu primitive which would let me do the last.

If there are other packages which can do this, that would be helpful. But having it in the same program/UI as GIMP, with all of its other image manipulation tools, and with its presence across platforms, would be even better. I'd love to have your ideas.

It sounds like you might find working with the combination of Gimp-Python, NumPy and SciPy more effective. integration,definitely. Islands, possibly (a browse through http://scipy.org/scipy/scipy/browser/trunk might help you to find out. And Python has a CSV module as standard.

I had the impression that writing external files was not supported by Script-Fu; I'm sure Kevin Cozens could tell you.

Hope that helps, David

Adam C Powell IV
2008-10-31 21:33:31 UTC (over 15 years ago)

Script-fu primitive wishlist: islands, integrals/sums, and data files

On Sat, 2008-11-01 at 01:02 +1030, David Gowers wrote:

Hi Adam,

On Fri, Oct 31, 2008 at 9:51 PM, Adam C Powell IV wrote:

Greetings,

I am working on an image processing plug-in (which I'll offer for upstream contribution BSD-licensed), and would really like to have a couple of primitives that I can't find.

One is finding "islands" in an image: take a channel and create new layers each with one contiguous region in the channel. So if the channel has ten islands, create ten new layers, each with one of the islands. Since this could be unwieldy (too many new layers), one new layer with one island would suffice; one could then process that island layer, subtract it from the original, and move on.

Another is integrals: zero, first and second moments, or alternatively, integrals/sums of channel intensity, x- and y-weighted intensity, and x^2, y^2 and xy-weighted intensity. This lets me fit an ellipse to an island, and then display major and minor axes.

Finally, opening and storing data files. I'd like to be able to create a CSV file with statistics of the islands: size, centroid, aspect ratio (major/minor axis ratio), major axis orientation. One could then further process these statistics in a spreadsheet or other program.

I can do the first two in scheme, though it would be slow, but tolerable for my needs. I don't see a script-fu primitive which would let me do the last.

If there are other packages which can do this, that would be helpful. But having it in the same program/UI as GIMP, with all of its other image manipulation tools, and with its presence across platforms, would be even better. I'd love to have your ideas.

It sounds like you might find working with the combination of Gimp-Python, NumPy and SciPy more effective. integration,definitely. Islands, possibly (a browse through http://scipy.org/scipy/scipy/browser/trunk might help you to find out. And Python has a CSV module as standard.

Okay, thanks for the suggestion. The downsides seem to be: I and others need to install these as well as GIMP to use it, I need to learn Python (yes, I'm one of the tiny handful remaining who know scheme but not python :-), and converting from a GIMP image to something which NumPy/SciPy can quickly sum might not be straightforward.

I had the impression that writing external files was not supported by Script-Fu; I'm sure Kevin Cozens could tell you.

Okay, I look forward to hearing from him. Hmm, I suppose if the output is small enough, this could return it as a list, and one could run it in the script-fu console then copy-and-paste the return value...

Hope that helps,

Yes, thanks much.

-Adam

Kevin Cozens
2008-11-01 00:27:33 UTC (over 15 years ago)

Script-fu primitive wishlist: islands, integrals/sums, and data files

David Gowers wrote:

One is finding "islands" in an image

[snip]

Another is integrals: zero, first and second moments, or alternatively, integrals/sums of channel intensity, x- and y-weighted intensity, and x^2, y^2 and xy-weighted intensity.

As you stated, the above two features could be implemented in Scheme but they would probably be too slow in actual use.

Finally, opening and storing data files.

See section 6.6 of the R5RS. Working with external files is handled via the use of pipes.

If there are other packages which can do this, that would be helpful.

A C based plug-in or a Python based script are probably better bets for the first two items.

saulgoode@flashingtwelve.brickfilms.com
2008-11-01 02:20:08 UTC (over 15 years ago)

Script-fu primitive wishlist: islands, integrals/sums, and data files

Quoting Kevin Cozens :

Finally, opening and storing data files.

See section 6.6 of the R5RS. Working with external files is handled via the use of pipes.

A problem which I encountered with TinyScheme's character I/O is that the 'read-char' and 'write-char' functions perform UNICODE conversions, making it impossible to read and write "binary" data files. The R5RS specification doesn't seem to address this but the TinyScheme implementation does seem to cripple the ability to read and write non-text files.

I had added a 'read-byte' command to my personal GIMP-2-4 [1] (I never got around to implementing 'write-byte') and would be happy to contribute patches to add such capability, if deemed appropriate/useful.

[1] http://flashingtwelve.brickfilms.com/GIMP/Temp/read-byte.diff.gz

Adam C Powell IV
2008-11-01 13:47:08 UTC (over 15 years ago)

Script-fu primitive wishlist: islands, integrals/sums, and data files

On Fri, 2008-10-31 at 19:27 -0400, Kevin Cozens wrote:

David Gowers wrote:

One is finding "islands" in an image

[snip]

Another is integrals: zero, first and second moments, or alternatively, integrals/sums of channel intensity, x- and y-weighted intensity, and x^2, y^2 and xy-weighted intensity.

As you stated, the above two features could be implemented in Scheme but they would probably be too slow in actual use.

Indeed, just tried, they're quite slow. When I can't bear it any longer, I'll see about a C plugin.

Finally, opening and storing data files.

See section 6.6 of the R5RS. Working with external files is handled via the use of pipes.

Thanks, got it working. And Saul, text is all I need, can't speak for others.

I don't suppose there's a script-fu interface to the file browser for setting the file name...

One more question: I can't seem to access procedures in my scripts from the console. That is, if I define some procedures in files in .gimp-2.4/scripts/foo, the console doesn't know they exist. Is there a way to access those procedures from the console?

Cheers, -Adam

saulgoode@flashingtwelve.brickfilms.com
2008-11-01 19:02:48 UTC (over 15 years ago)

Script-fu primitive wishlist: islands, integrals/sums, and data files

Quoting Adam C Powell IV :

I don't suppose there's a script-fu interface to the file browser for setting the file name...

The registration parameters (SF-FILE) get evaluated when Script-fu is loaded (or scripts are "Refreshed") and dialog boxes for file browsing otherwise use the "last values" with which the function was invoked. (In other words, I don't believe it possible to set the filename.)

Thanks, got it working. And Saul, text is all I need, can't speak for others.

I don't think that Script-fu needs the functionality to access binary files (nor that 'read-byte' and 'write-byte' would be the best approach); however, it does seem that the TinyScheme interpreter should provide such support.

One more question: I can't seem to access procedures in my scripts from the console. That is, if I define some procedures in files in .gimp-2.4/scripts/foo, the console doesn't know they exist. Is there a way to access those procedures from the console?

Filenames in the 'scripts' folder must have the extension ".scm" or they are ignored by Script-fu. If you rename your file to "foo.scm", all functions defined within it should be available in the console.