Optimising Performance - GreycLab/gmic-community GitHub Wiki
This page is a stub, more information to follow
As with most other languages there are many ways in G'MIC script to reduce calculation time. There is no written-in-stone method that works for all situations and as always the algorithm used is most important. On this page are some known "tricks" that may prove useful, if you have any comments or ideas please feel free to add to the list.
##Reduce image dimensions where possible A quick speedup where resolution/detail is not important is to temporarily re-size an image to be smaller prior to processing, then re-size back afterwards. Depending on the subsequent commands this can give significant gains with very little effort. Example of use:
ow={w} oh={h}
-if {max(w,h)>700} -rr2d[-1] 700,700,0,1 -endif
-median[-1] 7 -segment_watershed 1,1 #commands here
-r[-1] $ow,$oh
###Preserving details
You can preserve details lost during resizing by creating a duplicate, resizing it to a smaller image, and then create a duplicate of the smaller image, resize back to the original size and subtract the original image from the newly created duplicate. This creates an image with just the details which you can add back to the processed image once it has been resized back to normal.
ow={w} oh={h} # Set variables for original image dimensions
--resize[0] 50%,50%,{d},{s},2 # Create a new half size image
--resize[-1] $ow,$oh,{d},{s},3 # Create a new image of the smaller image resized to original size
-sub[-1] [0] # Subtract the two full sized images to get only the details
-remove[0] # Remove the original image
-median[0] 5 # Apply command to smaller image
-resize[0] $ow,$oh,{d},{s},3 # Resize small image to original size
-add # Add the processed image and the detail image together
Alternatively you can apply some similar processing to the detail image. For example, if you want to do some noise reduction, you can use a less aggressive setting on both the detail image and the smaller image. This will give different, but hopefully faster, results than using an aggressive noise reduction filter on the full size image.
##Using Approximations
Where accuracy is not important, a faster approximation can be used. For example:
-blur 1
Can be approximated by
(0.058,0.13,0.058;0.13,0.25,0.13;0.058,0.13,0.058)
-convolve[0] [1]
-remove[-1]
Removing redundancies
Often redundancies can creep into your filter ... to be continued
Multiply instead of divide
Where possible it is better to multiply instead of dividing. For example, it is better to multiply by 0.5 than to divide by 2.