FUNCTION wedge_content, image, p_box, b_box=b_box, exclude_p_box=exclude_p_box, $ center=center, prorate=prorate, degrees=degrees, $ zval=zval, centroid=centroid, p_centroid=p_centroid, wedge=wedge @compile_opt.pro ; On error, return to caller InitVar, center , [0.0,0.0] InitVar, prorate, [0,0] prorate_set = prorate[0]*prorate[1] gt 0 CASE IsType(b_box, /defined) OF 0: BEGIN b_box = wedge_bounding_box(p_box, center=center, wedge=wedge, degrees=degrees, dim=size(image,/dim)) img_box = image[b_box[0]:b_box[2],b_box[1]:b_box[3]] END 1: img_box = image ENDCASE cntr = center-b_box[0:1] ; Center relative to lower-left corner of b_box nx = b_box[2]-b_box[0]+1 ny = b_box[3]-b_box[1]+1 ; Rectangular pixel coordinates relative to cntr r_img = gridgen([nx,ny],origin=cntr) ; Convert the pixel centers to polar coordinates ; (phi is returned between -!pi and !pi) inside_centers = Inside_Wedge(p_box, cv_coord(from_rect=r_img, /to_polar, degrees=degrees), exclude_p_box=exclude_p_box) CASE nx EQ 1 AND ny EQ 1 OF 0: inside_centers = reform(inside_centers, nx, ny, /overwrite) 1: inside_centers = [inside_centers] ENDCASE ; Convert the pixel corners to polar coordinates r = gridgen([nx,ny]+1,origin=cntr+0.5) inside = Inside_Wedge(p_box, cv_coord(from_rect=r, /to_polar, degrees=degrees), exclude_p_box=exclude_p_box) inside = reform([inside],nx+1,ny+1,/overwrite) ; Zero entries in 'clear_inside' identify pixels that bridge the wedge boundary ; These pixels need to be prorated clear_inside = inside_centers EQ inside[0:nx-1,0:ny-1] AND $ inside_centers EQ inside[1:nx ,0:ny-1] AND $ inside_centers EQ inside[0:nx-1,1:ny ] AND $ inside_centers EQ inside[1:nx ,1:ny ] ; Determine all pixels that lie completely inside the wedge clear_across = where(clear_inside EQ 0B, n_across) clear_inside = where(clear_inside EQ 1B AND inside_centers EQ 1B, n_inside) n_across = prorate_set*n_across frac = fltarr(nx, ny) IF n_inside GT 0 THEN frac[clear_inside] = 1. IF n_across GT 0 THEN BEGIN ; The prorating is done by dividing each pixel on the boundary ; in a group of 10x10 subpixels mx = prorate[0] my = prorate[1] ; x,y coordinates of subpixels between -0.5,+0.5 r = [mx,my] r_small = gridgen( r, range=(0.5*[-1,1])#((r-1.0)/r) ) ; x,y coordinate relative to origin of pixels to be prorated r = r_img[*,clear_across] ; Set up an mx x my x n_across array for all subpixels in all pixels to be prorated r = SuperArray(r, mx*my, after=1)+SuperArray(r_small,n_across,/trail) r = reform(r,2,mx*my*n_across, /overwrite) ; Convert the subpixel centers to polar coordinates ; Determine which subpixels lie inside the wedge r = Inside_Wedge(p_box, cv_coord(from_rect=r, /to_polar, degrees=degrees), exclude_p_box=exclude_p_box) r = reform(r, mx*my, n_across, /overwrite) r = total(r,1)/(mx*my) ; Fraction of subpixels lying inside the wedge frac[clear_across] = r ENDIF zpix = total(frac) IF zpix GT 0 THEN BEGIN r = where(frac NE 0, nr) zmin = min(img_box[r], max=zmax, /nan) IF nr GT 1 THEN zstd = stddev(img_box[r], /nan) ELSE zstd = 0. frac = frac/total(frac) zval = frac*img_box zavg = total(zval, /nan) centroid = CenterOfMass(zval) ; Center of mass relative to lowerleft corner of bounding box ; Center of mass in polar coordinates p_centroid = cv_coord(from_rect=centroid-cntr, /to_polar, degrees=degrees) centroid = b_box[0:1]+centroid ; Center of mass relative to lowerleft corner of full image zval = [zmin, zmax, zavg, zstd] ENDIF ELSE BEGIN bad = BadValue(0.0) zval = replicate(bad, 4) centroid = replicate(bad, 2) p_centroid = replicate(bad, 2) ENDELSE RETURN, zpix & END