Yes, if you can work out what the formula is. I guess you are moving the end-stops inwards a bit beyond the current min and max values, so you get some clipping at both ends.
For example, with ImageMagick:
magick in.tiff -contrast-stretch 2x3% out.tiff
This clips 2% of pixels values at black and 3% at white.
magick in.tiff -level 2x97% out.tiff
This increases contrast so what was 2% becomes 0%, and what was 97% becomes 100%.
magick in.tiff -level %[fx:minima*100+2]x%[fx:maxima*100-3]% out.tiff
This increases contrast so what was 2% above the minimum becomes 0%, and what was 3% below the maximum becomes 100%.
If your formula creates values less the 0% or more then 100%, there are methods to bring them back into range, while keeping some detail at both ends.
Once you have a formula you are happy with, a shell loop can do all the images in a folder.