Author Topic: Software binning in PI  (Read 2592 times)

Offline MikeOates

  • PixInsight Addict
  • ***
  • Posts: 278
Software binning in PI
« on: 2017 November 09 01:51:49 »
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.

Quote
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:

Code: [Select]
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:

Code: [Select]
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.
« Last Edit: 2017 November 09 07:37:37 by MikeOates »

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: Software binning in PI
« Reply #1 on: 2017 November 09 09:44:14 »
i figure that setting pixelmath to replace target image might make it work with ImageContainer? not totally sure but i think this is what you have to do with ABE to make it work with IC.

rob

Offline MikeOates

  • PixInsight Addict
  • ***
  • Posts: 278
Re: Software binning in PI
« Reply #2 on: 2017 November 09 15:18:39 »
Thanks Rob, unfortunately it needs to create a new file or it just reduces the image size to half but keeps it at full resolution, i.e. the image just occupies the top left corner of the frame. See image below.

But as I was writing this reply I had a light bulb moment, what if I could then crop that frame so it just retained the image and saved that.

What I did was put the bin conversion PixelMath expression (without the create new image selected) and a Crop process both in a ProcessContainer. I then put the image to be converted in an ImageContainer where I have set a save path. All I had to do was drag the ImageContainer triangle to the ProcessContainer and it worked!

Problem sorted  :D

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: Software binning in PI
« Reply #3 on: 2017 November 09 16:45:36 »
interesting - probably i would have known that if i had read the thread.

at any rate yeah that's a perfect application of ProcessContainer and ImageContainer! nice.

rob

Offline MikeOates

  • PixInsight Addict
  • ***
  • Posts: 278
Re: Software binning in PI
« Reply #4 on: 2017 November 15 11:59:15 »
An update, should anyone want to use this method. There is a problem with the crop tool.

When used in this manner for each image it crops, it pops up a message that you have to confirm saying:

Quote
The image contains an astrometric solution that will be deleted by the geometric transformation.
This side effect could be irreversible. Proceed?

This is rather annoying meaning I have click 'Yes' for each image in the Image Container.

Is there a way of disabling this?

Or is there a way of removing the WCS data from the image before the crop?

Thanks,

Mike

Offline pfile

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 4729
Re: Software binning in PI
« Reply #5 on: 2017 November 15 14:20:20 »
i think that has been reported before and i thought juan acknowledged it, but i might have imagined that. have never tried to strip WCS from a fits file... there's gotta be a way to do it.

rob