5
$\begingroup$

I have a medical brain image from which I'm trying to isolate the brain (the gray pixels) from the rest (black and white parts).

I'm looking for some functions that are best suited for this.

Thanks

enter image description here

$\endgroup$
  • $\begingroup$ Something like DeleteSmallComponents@Dilation[Binarize[img, {0.4, 0.6}], 1] perhaps. $\endgroup$ – C. E. Oct 19 '18 at 17:38
7
$\begingroup$

This can actually be done quite gracefully. Since it seems like there's no full white within the brain itself, we replace all the White with Black, then use ImageCrop.

ImageCrop[DeleteSmallComponents@ColorReplace[i, {White -> Black}]]

You can use RemoveBackground as well if you don't want black in the background.

working example

older attempt

We use RemoveBackground with a marker in the centre of the image, then crop, delete small leftovers of the borders, crop again, and finally replace transparency with black.

RemoveAlphaChannel[
 ImageCrop[
  ColorNegate[
   DeleteSmallComponents[
    ColorNegate[
     ImageCrop[
      RemoveBackground[i, {"Foreground", ImageDimensions[i]/2}]]]]]], 
 RGBColor[0.`, 0.`, 0.`]]

working example

Or, since it seems like the image is relatively standard, you can just set given borders for the brain and crop to that every time.

$\endgroup$
  • $\begingroup$ Thank you very much, that was easier than I thought :) $\endgroup$ – holistic Oct 19 '18 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.