margol
margol

Reputation: 259

How to extract region of interest with binary mask

I have an original Chest X-Ray image (orig.jpg). I did manual segmentation with ITK-SNAP yielding this binary mask image (bmask.jpg):

enter image description here

To extract the lung region from 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');

The result image:

enter image description here

I figured out since some pixels of binary mask inside the lung regions near the lung boundary has "1" value, the resulting image has some black dots near the lung boundary inside the lung regions. Also, in the resulting image, lung boundary has a zigzag pattern, not a smooth pattern as the binary mask. How can I fix these problems? Can anyone kindly help me?

Thanks.

Upvotes: 3

Views: 5106

Answers (2)

Deepika S
Deepika S

Reputation: 1

clear all;
clc;
IR=imread('orig.jpg');
im=imread('bmask.jpg'); %binary image
ROI = IR;
ROI(im == 0) = 0;
figure;
imshow(ROI);

Upvotes: -1

Marcin
Marcin

Reputation: 238747

I guess that the problem you have is because your jpg mask is NOT real binary image. Using jpg to store binary images is not very good idea, since due to compressive nature of jpegs, your mask will slightly deviate from binary image, especially at the edges.

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

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

If this not help, when you generate your mask, do not use jpeg. Instead, use uncompressed (or with loss-less compression) tiff in gray-scale, or just stor it as binary matlab matrix in a file.

Hope this helps.

Upvotes: 5

Related Questions