function bin_image_xy,x,y,im,zero=zero, bin=bin,crop=crop if n_params(0) eq 0 then begin print,'im = bin_image_xy(x, y [, im], zero=zero, bin=bin, crop=crop, fits=fits) print,'Bin x,y vectors into an image print,'If im is supplied, bin image into im rather than creating new array print,'If /crop, crop image (in this case the x,y zero points are returned in zero print,'If bin is supplied, image is binned by bin, with x,y assumed in fits print,' convension (i.e., bottem-left of first pixel is 0.5, 0.5)' print,'Note that this routine is not appropriate if x,y are not integers' retall endif if not keyword_set(bin) then bin=1.0 xr = minmax(x) yr = minmax(y) if not keyword_set(crop) then begin xr(0) = 1 & yr(0) = 1 endif xs = round((xr(1)-xr(0))/bin)+1 ys = round((yr(1)-yr(0))/bin)+1 ; xr = xr - 1 ; yr = yr - 1 if n_elements(im) eq 0 then im = intarr(xs, ys) newx = round((x-xr(0) + 0.5)/bin + 0.5) - 1 newy = round((y-yr(0) + 0.5)/bin + 0.5) - 1 for i=0l,n_elements(x)-1 do im(newx(i), newy(i)) = $ im(newx(i), newy(i)) + 1 zero = [xr(0), yr(0)] return,im end