MATLAB Answers

Info

This question is closed. Reopen it to edit or answer.

How can I convert this image in binary image such that region inside red curve is filled with white while rest with black?

1 view (last 30 days)
Anurag Tripathi
Anurag Tripathi on 9 Sep 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
How can I convert this image in binary image such that region inside red curve is filled with white while rest with black? I have around 900 images like this so free hand drawing will be very lengthy. So is there any other way of doing it...maybe by setting some threshold?

Answers (1)

Adam Wyatt
Adam Wyatt on 9 Sep 2020
Your question is quite vague and the methodology and results depend very much on how the images vary.
Remember that the computer will have no concept of how you decide where to draw that boundary, so you need to come up with some criterion on how to do that. If you have the image processing toolbox, that has many functions that can help you to create a mask from an image.
Assuming that using a threshold will suffice - i.e. all points within the enclosed region are above threshold and outside are below, you can create a mask in 1 line:
mask = (ImgArray>threshold_value);
However, you are likely going to be required to pre-process the data. The most likely is to perform smoothing using e.g. imfilter or filter2 You may then also need to refine the mask - for example by only taking connected points (image processing toolbox will be your friend). A little trick you can use is to smooth the mask and then threshold that - this can help get rid of any holes and create a little extra padding.
If you don't have the toolbox, it is still possible to find the continous region, but it will be slow (I do have a function to do that).

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!