Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB - Filling in the empty region of an ellipse/skull shape?

I have been attempting to fill in a binary image in Matlab so that I am left with the entirety of this oval-like image like this.

--> VISUALIZATION OF MY ISSUE <--

However, I have been running into an issue in actually being able to define the red region. I have tried the following:

  1. Using the bwconvhull function to fill the shape accurately, but then I do not know how to get rid of the inner shape to isolate just the red region.
  2. I have also attempted to trace the boundary of the binary region but to no avail. I am not entirely sure what to do after tracing the boundary. I have attempted to trace just the inner boundary, but the bwtraceboundary function simply follows the entirety of the borders (on the inside and outside of the skull).

Are there any similar functions to bwconvhull where I am able to expand a region from the center outward? My major difficulties have been in isolating either (a) the inner boundary of the skull or (b) the inner "black" region where the brain should be. My coding attempts can be found below:

Issue (a) - Tracing boundaries

hole=imread('Copy CT.jpg');
BW=im2bw(hole,.9); 
dim=size(BW);
col=round(dim(2)/2);        
row=min(find(BW(:,col)));
boundary = bwtraceboundary(BW,[row,col],'S');
x=boundary(:,2);
y=boundary(:,1);

Issue (b) - Isolating only the center

hole=imread('Copy CT.jpg');
BW=im2bw(hole,.9);   
CH=bwconvhull(BW);
KH=CH-BW;
KH2=bwareaopen(KH,200);

Are there any particular functions that would be worth trying, or would there be another way to isolate the center of the circle so I can only highlight the red region? Any insight would be greatly appreciated!

like image 848
User1234 Avatar asked Nov 08 '22 10:11

User1234


1 Answers

I would approach this with these steps:

  1. apply an edge detection filter so you end up with two ellipse-ish shaped parts: an inner and outer ellipse.
  2. apply an algorithmic ellipse-fit to the inner ellipse. There are some good examples out there, but I don't have one on me.
  3. subtract the bwconvhull boundary with the inner ellipse.
  4. subtract all parts of your new oval that overlap with the white portions of the original image.

I am sorry I don't have actual code to back up this approach, but this will get you pretty close. You may need more steps to clean up the final result.

like image 62
Micahstuh Avatar answered Nov 17 '22 10:11

Micahstuh