This subject was brought up in the Off-topic section, 6 years ago! (
https://pixinsight.com/forum/index.php?topic=3195.0), not the ideal place for this question as it does not get seen much. Juan replied to this with a great PixelMath expression which works great except it does not work properly using ImageContainer as it creates a file saved to disk which is the wrong size, i.e. the size is not reduced. But it also creates a file on the desktop using default names image01, image02 etc. These are the correct files, but you have to do a save-as for each one.
When I have a batch of these files to process I have to do each one separately then do a save-as. This takes a lot of time and being a human process, I keep making mistakes!
Can this be done by some form of batch process / script ? (Note I can't do scripts or I would have a go)
Thanks,
Mike
PS: Here is Juan's post to make it easier.
Hi,
Yes, Geometry > IntegerResample is what you are looking for. The default parameters (downsample/average) perform a 2x2 binning.
Here are only Average, Median, Maximum or Minimum as operation, but not Add (Sum).
Average and add (sum) are equivalent in terms of SNR increment. The advantage of average is that you can't get out-of-range pixel values.
If you really want to perform a 'pure' 2x2 binning by summing 4-pixel blocks, this is very easy with PixelMath:
- In the 'Symbols' field type the following:
x2, y2
This allows PixelMath to use x2 and y2 as variable names instead of as image identifiers.
- Click the Edit button to the right of the RGB/K expression field and write this PixelMath expression:
x2 = 2*x();
y2 = 2*y();
pixel( $T, x2, y2 ) + pixel( $T, x2+1, y2 ) + pixel( $T, x2, y2+1 ) + pixel( $T, x2+1, y2+1 )
The expression above computes the sum of each contiguous block of 2x2 pixels in the source image.
- Uncheck the 'Rescale result' PixelMath option.
- Open the Destination section and select the following:
* Create new image: checked
* Image id: the identifier you want; for example: binned2x2
* Image width and Image height: the dimensions of your original image halved. If your image is 4096x4096, you should enter 2048 and 2048 here.
* Color space: same as target
* Sample format: 32-bit floating point (recommended)
Execute this PixelMath instance on your unbinned image and you'll get a binned result as a new image window. As I've said above, the result is the same as if you used IntegerResample in average downsampling mode in SNR terms, but the range of values is different. With a pure binning procedure, if a 2x2 block in your original image sums up more than one, the resulting binned pixel will be saturated.