Intracranial Hemorrhage Detection

Source: Deep Learning on Medium

Intracranial Hemorrhage Detection

Identify acute intracranial hemorrhage and its subtypes

An intracranial hemorrhage is a type of bleeding that occurs inside the skull (cranium).Bleeding around or within the brain itself is known as a cerebral hemorrhage (or intracerebral hemorrhage). Bleeding caused by a blood vessel in the brain that has leaked or ruptured (torn) is called a hemorrhagic stroke. (All bleeding within the skull is referred to as intracranial hemorrhage.)

Hemorrhages that occur within the skull or brain generally happen suddenly, from either external or internal causes. A hemorrhage can rapidly cause brain damage and can be life-threatening.

Since the brain cannot store oxygen, it relies upon a series of blood vessels to supply oxygen and nutrients. When a hemorrhage occurs, oxygen may no longer be able to reach brain tissue supplied by leaky or broken blood vessels. Pooling of blood from an intracranial hemorrhage or cerebral hemorrhage also puts pressure on the brain and deprives it of oxygen.

When a hemorrhage or stroke interrupts blood flow around or inside the brain, depriving it of oxygen for more than three or four minutes, the brain cells die. The affected nerve cells and the related functions they control are damaged as well.

There are four types of Intracranial hemorrhage:

  • epidural hematoma
  • subdural hematoma
  • subarachnoid hemorrhage
  • intracerebral hemorrhage

Epidural hematoma

A hematoma is a collection of blood, in a clot or ball, outside of a blood vessel. An epidural hematoma occurs when blood accumulates between your skull and the outermost covering of your brain.

It typically follows a head injury, and usually with a skull fracture. High-pressure bleeding is a prominent feature. If you have an epidural hematoma, you may briefly lose consciousness and then regain consciousness.

Subdural hematoma

A subdural hematoma is a collection of blood on the surface of your brain.

It’s typically the result of your head moving rapidly forward and stopping, such as in a car accident. However, it could also suggest abuse in children. This is the same type of movement a child experiences when being shaken.

A subdural hematoma is more common than other ICHs in older people and people with history of heavy alcohol use.

Subarachnoid hemorrhage

A subarachnoid hemorrhage is when there’s bleeding between the brain and the thin tissues that cover the brain. These tissues are called meninges. The most common cause is trauma, but it can also be caused by rupture of a major blood vessel in the brain, such as from an intracerebral aneurysm.

A sudden, sharp headache usually comes before a subarachnoid hemorrhage. Typical symptoms also include loss of consciousness and vomiting.

Intracerebral hemorrhage

Intracerebral hemorrhage is when there’s bleeding inside of your brain. This is the most common type of ICH that occurs with a stroke. It’s not usually the result of injury.

A prominent warning sign is the sudden onset of neurological deficit. This is a problem with your brain’s functioning. The symptoms progress over minutes to hours. They include:

  • headache
  • difficulty speaking
  • nausea
  • vomiting
  • decreased consciousness
  • weakness in one part of the body
  • elevated blood pressure

For this article, we will use the data provided by RSNA Intracranial Hemorrhage Detection Competition from Kaggle .In this competition, our challenge is to build an algorithm to detect acute intracranial hemorrhage and its subtypes.

We will develop a solution using a rich image dataset provided by the Radiological Society of North America (RSNA®) in collaboration with members of the American Society of Neuroradiology and

If successful, We will help the medical community identify the presence, location and type of hemorrhage in order to quickly and effectively treat affected patients.

We have to make several predictions for one image id:

  • epidural
  • subdural
  • subarachnoid
  • intraparenchymal
  • intraventricular
  • any — this one indicates that at least one subtype is present, hence it tells us if the patient has IH or not.

Images are stored in a special format known as DICOM files (*.dcm). They contain a combination of header metadata as well as underlying raw image arrays for pixel data. In Python, one popular library to access and manipulate DICOM files is the pydicom module. To use the pydicom library, first find the DICOM file for a given patientId by simply looking for the matching file in the stage_1_train_images/ folder, and the use the pydicom.read_file() method to load the data.

DICOM file for a given patientId

Going into details of each subtype we can see that we have to deal with high class imbalance.Epidural is the worst case. For this type we only have a few (< 1%) of positive occurrences. It will be difficult to train a model that is robust enough and does not tend to overfit.

Target distribution

we’re going to explore the important issue of windowing from a rather different direction to what you’ve probably seen before… and will show you a new way to handle DICOM pixel rescaling that might just give your models a boost!

Brain Windowing

As discussed in the excellent kernel See like a Radiologist with Systematic Windowing (from which I derived the somewhat cheeky title of this current notebook!), radiologists use windowing to increase the contrast of images across particular bands of hounsfield units.

It’s because the human visual system can only see 100 levels of gradation of a single color (in this case, white/grey/black) — and even fewer with the limitations of a computer display — but there are up to 2**16 == 65536 levels in a 16 bit DICOM image. So a human can’t possibly see all those levels at once in a single greyscale image. To see this, let’s look at the same image the See like a radiologist notebook studies, without any windows:

On the other hand, with brain windowing, we can clearly see the details of the brain:

Rescaling floating point data

As shown in detail in Deep Learning from the Foundations, and particularly lesson 10, having well-scaled inputs is really important to getting good results from your neural net training. That means we want to see a good mix of values throughout the range of our data — e.g. something having approximately a normal or uniform distribution. Unfortunately, the pixels in our DICOM above don’t show that at all:

We see a highly bimodal distribution, with lots of background pixels at around -1000, and brain tissue pixels at a bit over 0. But that’s OK, we can normalize this using a simple trick – we can scale our pixel values using a non-linear mapping designed to give us an equal number of pixels in each range. To do that, we first need to split the range of pixel values into groups, such that each group has around the same number of pixels.

Because there’s some pixel values (like 1024) which appear many times, we can’t get a perfectly uniform result, but it’s pretty close. So now we just need a way to scale our pixels evenly using these bins. We can use a simple function which connects these bins with line segments, like this:

fastai.medical.imaging can apply that mapping for you, like so:

Original DICOM
Normalized DICOM