# Isolate structures from image

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

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

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.

### 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.]]
`

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.

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