Without seeing your image, it is hard to tell how and whether the extraction method fits in your case. Yet basically, I guess bwconncomp
/bwlabel
and ismember
are supposed to work.
One example:
I=imread('mri.jpg');
I=rgb2gray(I);
subplot(1,2,1)
imshow(I)
BW=im2bw(I,graythresh(I));
[L,n]=bwlabel(BW);
mask=ismember(L,2:n);
I1=I.*uint8(mask);
subplot(1,2,2)
imshow(I1)
Result (left is the original image, and right is the one after skull removal):