How to extract a region of interest using a binary mask

I have the original chest x-ray (orig.jpg). I did manual segmentation with ITK-SNAP, yielding to this binary mask image (bmask.jpg):

enter image description here

To extract the area of ​​the lung from the background, I run the following MATLAB code:

clear all;
clc;
IR=imread('orig.jpg');
im=imread('bmask.jpg');
ROI = IR;
ROI(im == 1) = 0;
ROI(im ~= 1) = 1;
SEG = IR.*ROI;
figure;
imshow(SEG);
imwrite(SEG,'SEG.jpg');

      

Result image:

enter image description here

I realized that since some of the pixels of the binary mask inside the lung regions near the lung border are "1", the resulting image has some black dots near the lung border inside the lung regions. In addition, in the resulting image, the border of the lung has a zigzag pattern, and not a smooth pattern like a double mask. How can I fix these problems? Can anyone help me?

Thank.

+3


source to share


1 answer


I assume you have the problem because your jpg mask is NOT a real binary image. Using jpg to store binary images is not a good idea as due to the compressive nature of jpegs your mask will deviate slightly from the binary, especially around the edges.

To get a real binary image from a jpeg mask, you can try this:

Ibw = im2bw(rgb2gray(imread('mask.jpg')));

      



If that doesn't help when you create the mask, don't use jpeg. Instead, use uncompressed (or lossless) greyscale compression, or simply save it as a binary matrix in a file.

Hope it helps.

+5


source







All Articles