Cropping a Z-stack in X and Y only, is there a simpler solution?

Hi there,

I am using gmic as a quick pipeline tools for scientific image analysis. It is very efficient for pre-processing.

Cropping is a great example of that, however manual cropping in XY can be cumbersome in Z stack, because one has to scroll up and down the stack to get to 0% and 100% in Z.

Using a “-s z -a c -crop -s c - a z” trick is not a solution, because my data is multichannel.

Hence if I want to crop a Z-stack using a rectangle defined on a maximum projection of the stack , I do :

gmic 200,200,50,2 -noise 0.3,2 -blur 5  --l -s z -max -select 2 -endl -crop[0] \{i[#1,0]\},\{i[#1,1]},0%,\{i[#1,3]\},\{i[#1,4]\},100% -rm[-1]

However, I found it pretty cumbersome, and it took me a while to write/debug. Is there a more straightforward way to do this?

Maybe something a bit simpler, to be used on the command line:

$ gmic 200,200,50,2 noise 0.3,2 b 5 +l s z max select 2 c="{@0,1,3,4}" rm endl crop \$c

But for this kind of stuffs, I strongly suggest you write this as a user-defined command, in your $HOME/.gmic file. This avoids having to deal with bash escaping:

# My .gmic file

crop_zmax : 
  +l s z max select 2 c={@0,1,3,4} rm endl
  crop $c

Then :

$ gmic 200,200,50,2 noise 0.3,2 b 5 crop_zmax

Thanks a lot :). Indeed I got my version in my .gmic.

I never understood the @subset variable upon reading the doc. Pretty clear now, thanks!

Is it fair to say that “{@0,1,3,4}” is an exact equivalent to “{i[0]},{i[1]},{i[3]},{i[4]}” ?

Yes it is.
There is also another alternate ways of getting it, by using the “vector” type in the math parser:

{[i[0],i[1],i[3],i[4]]}

Very cool! Thanks so much for your fast reply and your incredible work on Gmic!

Thanks. You make me realize that the doc indeed needs some care :slight_smile:
If you have any idea to make it more clear, I’m interested! (definitely not a good doc writer here :wink: ).

I’ll think about it!

Yes, it wasn’t obvious. Are there other uses for @ or is that all there is? One way to improve the documentation would be to show lots and lots of examples. A lot of the documentation is implied and not explicit. That might require some work though.

Personally, I don’t use it that much except is these rare case where it turn out to be it very useful.

This should be done maybe more in a wiki page ?
Technical documentation is intended to be quite formal but shortest as possible (it’s already quite long actually). But having a page with snippets for common uses of G’MIC would be really interesting.

I prefer when the examples are all in the same doc. Here, the doc is already too long to be consulted without querying keywords. So, it would not hurt my workflow at all to add examples. Of course, I am only talking for myself here.