MATLAB: How to extract the left and right lung regions from a CT Scan image

boundaryct imageedge detection

Hello, I've been trying to extract the left and right lung regions from this image using region labeling and various edge detection methods. The touble is that I am completely new to matlab and programming and have been completely unnsucessful. Any help would be greatly appreciated.
Thank you

Best Answer

There can be several approaches. How about something like this. You can try different values for thresholding, etc and look at the documentation of the functions to see what exactly they are doing.
%%Read image
img = imread('11w3uds.jpg');
%%Crop out unnecessary parts
cropped = img(90:400,40:460);
%%Threshold to isolate lung tissue
thresholded = cropped < 86;
%%Remove artifacts attached to border
clearThresh = imclearborder(thresholded);
%%Remove objects less than 40 pixels in size
imgBigTissue = bwareaopen(clearThresh,100);
imshow(imgBigTissue)