Tuberculosis X-Ray Image Processing

Published

Introduction: Tuberculosis X-Ray Image Processing

Our group designed a code to diagnose Tuberculosis inside patient’s chest by seeking and locating the cavities in a pulmonary X-ray image. Based on what we have researched on tuberculosis, the presence of cavities is a common sign of mycobacteria infection, which also implies the Tuberculosis infection. In order to increase precision of diagnosis, our program is set to apply several layers of filtrations on the original image to help eliminate undesired regions of the chest. Our code is also able to detect the number of cavities found in the image by using threshold range to detect the areas of filtered regions. The cavity portions will be outlined and eventually outputted separately for further medical inspections.

Step 1: Loading Image & Histogram of BW Intensity Values

  • Loading image: Import the original X-Ray image with 'imread' function. In this case, the image file was saved as 'cav1.jpg'

>> a = imread('cav1.jpg');

  • Turn the image into black & white binary image with 'colormap(gray)' ---> (see figure 1)

>> colormap(gray)

  • Using 'imhist' function to help recognize the threshold range of the black & white intensity value --->(see figure 2)

Step 2: Adding Filters

  • The threshold is set with a range between 100 to 256, which works best to display the image with better intensity difference.

>> a_thresh = a >= 100 & a <= 256;

  • Use the 'not' function to invert the black and white areas. --->(see figure 3)

>> imagesc(not(a_thresh));

1st Filtration: --->(see figure 4)

Use the 'imopen' function with 'dimentionality: 3' and 'cube shaped' structuring elements to fill small regions(white spots)

>> SE=strel('cube',3)

>> a_thresh85_open=imopen(not(a_thresh),SE);

2nd Filtration: --->(see figure 5)

Use the 'imclose' function with 'dimentionality: 3' and 'sphere shaped' structuring elements to remove small gaps(small white areas

>> TE=strel('sphere',3)

>> a_thresh85_open2=imclose(a_thresh85_open,TE);

3rd Filtration: --->(see figure 6)

Use the 'imfill' function to fill small holes with more precision, and connect the black shade region.

>> C=imfill(a_thresh85_open2,'holes');

Step 3: Locating TB Cavity Using Area

Filter out non-cavity white regions

  • Use the 'regionprops' function to calculate areas for all the white regions from the filtered image

>> s = regionprops(C, 'Area');

>> area_value=[s.Area]

  • Set up a 'find' function to look for the white regions which will probably fit within the area range of a cavity.(After several tests, the range 100 to 905 seemed to work best) --->(see figure 7)

>> idx = find(area_value>100 & area_value<905);

  • Display the amount of cavities that are found in the image in the command window --->(see figure 8)

>> num_blobs=length(idx);

>> fprintf('Number of cavity: %d \n',num_blobs)

  • Use the 'bwlabel' function to return a label matrix that contains the objects found in the black and white image for further use. (see next step)

>> label=bwlabel(C);

>> max(max(label));

>> im1=(label==idx);

Boundary Box:

  • Use 'BoundingBox' function to figure out the exact location of the targets we want on the image, and use a red box to point them out.

>> s=regionprops(im1,'BoundingBox');

>> rectangle('Position', [s.BoundingBox(1), s.BoundingBox(2), s.BoundingBox(3), s.BoundingBox(4)], 'EdgeColor','r','LineWidth',2)

  • Subplot original image and image with red box for further examination. ---> (see figure 9)

Step 4: Output Cavity Image

The outer For loop calculates row and column values for each cavity image that are labeled.

  • Create a target matrix with uint8, which has the same size as the image of a specific cavity in length and width. Then assigns all values to zero.
  • The sx and sy value are used to calculated the number of iteration in x-direction and y-direction.

The inner for loop is used to calculate iteration. As the iteration starts, it will assign x, y values to the target components. Therefore, it will output the segments of cavity images out one by one in separate images. --->(see figure 10)

Share

    Recommendations

    • Water Contest

      Water Contest
    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest

    Discussions