Viewers icon indicating copy to clipboard operation
Viewers copied to clipboard

How to Create Binary Mask From FreehandRoi Tool

Open mtm12 opened this issue 6 years ago • 2 comments

Is there an easy was to create a binary mask from the region of interest drawn using the FreehandRoi tool? All I need is an 512x512 array with the region of interest set to "one" and the rest of the array set to "zero".

mtm12 avatar Mar 03 '20 21:03 mtm12

I think contour to mask can be fairly straightforward. I recommend taking a look at the Brush's source code, and you'll see how we modify a mask. If you have any specific questions, or if you're hung up on a specific part of the implementation, I can provide more assistance.

dannyrb avatar Mar 04 '20 14:03 dannyrb

The x,y coordinates of the ROI is stored in the points object within the FreehandROI tool in cornerstoneTools.js That object can then be used to draw the ROI on an invisible canvas:

for (i = 0; i < points.length; i += 1) { ctx_canvas_mask.lineTo(points[i].x, points[i].y); }

Then fill the ROI and convert to binary.

Marc

On Wed, Mar 4, 2020 at 9:54 AM Danny Brown [email protected] wrote:

I think contour to mask can be fairly straightforward. I recommend taking a look at the Brush's source code, and you'll see how we modify a mask. If you have any specific questions, or if you're hung up on a specific part of the implementation, I can provide more assistance.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/OHIF/Viewers/issues/1478?email_source=notifications&email_token=AGWQ3UWHM5CLH6Z5AFY5VETRFZTSVA5CNFSM4LATAWMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENYHZCQ#issuecomment-594574474, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGWQ3UXFWA2OVXG4QH7K3J3RFZTSVANCNFSM4LATAWMA .

-- Marc McLean

mtm12 avatar Mar 04 '20 21:03 mtm12