Skip to content

Instantly share code, notes, and snippets.

@dpshelio
Created March 7, 2014 14:17
Show Gist options
  • Save dpshelio/9412262 to your computer and use it in GitHub Desktop.
Save dpshelio/9412262 to your computer and use it in GitHub Desktop.
This IDL function generates the standard deviation of a 2D array when it's compressed by an integer factor.
function rebin_stddev, image, new_xsize, new_ysize, image_small = image_small
;+
; rebin_stddev
; It just works for making the image smaller by a integer factor (as rebin)
;
;-
dimensions = size(image, /dimensions)
number_of_pixels_combined = total(dimensions / float([new_xsize, new_ysize]))
; Rebin image to a smaller dimenssion
image_small = rebin(image, new_xsize, new_ysize)
; Make a new image with the original size with the average values
image_average = rebin(image_small, dimensions[0], dimensions[1], sample = 1)
; Difference between average and real value - Square
difference = (image - image_average)^2
; Rebin the difference and multiply by a factor to get Bessel's correction ( 1/n-1)
image_stddev = sqrt(rebin(difference, new_xsize, new_ysize)) * $
sqrt(number_of_pixels_combined/(number_of_pixels_combined-1))
return, image_stddev
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment