;+ ; NAME: crop_badpix ; ; PURPOSE: ; Given an image and a mask, crop the image to the minimum size which contains ; the mask. ; ; USAGE: ; PRO crop_badmask,data,badmask,cropped_data,cropped_badmask ; ; Given an image and a bad pixel mask (which may well make up ; a large portion of the image), crop the image to the minimum ; size which contains all good pixels. That is, throw away any ; border rows/columns which are all bad pixels. ; ; INPUTS: ; data an image or an image cube ; badpix a bad pixel mask; 0=bad, 1=good. ; the bad mask must be 2D; for image cubes the whole thing ; gets cropped the same way. ; KEYWORDS: ; RETURNS: ; cropped_image a cropped version of the image ; cropped_badmask a cropped version of the badmask ; ; HISTORY: ; Began 2002-09-03 16:21:49 by Marshall Perrin ;- PRO crop_badmask,data,badmask,cropped_data,cropped_badmask,$ firstcol=firstcol,lastcol=lastcol,$ firstrow=firstrow,lastrow=lastrow,$ inplace=inplace rowtotals = total(badmask,1) wgoodrow = where(rowtotals ne 0) firstrow = min(wgoodrow) lastrow = max(wgoodrow) coltotals = total(badmask,2) wgoodcol = where(coltotals ne 0) firstcol = min(wgoodcol) lastcol = max(wgoodcol) if keyword_set(inplace) then $ data = data[firstcol:lastcol,firstrow:lastrow,*] if arg_present(cropped_data) then $ cropped_data = data[firstcol:lastcol,firstrow:lastrow,*] if arg_present(cropped_badmask) then $ cropped_badmask = badmask[firstcol:lastcol,firstrow:lastrow] end