FUNCTION ROIMask, $ image, $ ; A 2D image. Indices=indices, $ ; Outputs the indices inside the ROI ReverseMask=reversemask ; Set this keyword to mask the image instead of the ROI IF N_Elements(image) EQ 0 THEN BEGIN ; Get an image, if needed. filename = Filepath(Subdir=['examples','data'], 'mr_knee.dcm') image = Read_DICOM(filename) ENDIF ; Draw ROI's on image. (Use the freehand PENCIL tool, for example.) XROI, image, Regions_Out=rois, /Block ; Create an image mask from the ROIs you just created. dim = Size(image, /Dimensions) IF Keyword_Set(reversemask) THEN $ mask = BytArr(dim[0], dim[1]) ELSE $ mask = BytArr(dim[0], dim[1]) + 1B ; Cycle through the ROIs. FOR j=0, N_Elements(rois)-1 DO BEGIN thisROI = rois[j] IF Obj_Valid(thisROI) THEN BEGIN thisROI -> GetProperty, Data=polygon indices = PolyFillV(polygon[0,*], polygon[1,*], dim[0], dim[1]) IF indices[0] NE -1 THEN BEGIN IF Keyword_Set(reversemask) THEN $ mask[indices] = 1 ELSE $ mask[indices] = 0 ENDIF Obj_Destroy, thisROI ENDIF ENDFOR ; Apply the mask to the image and return it. RETURN, image * mask END