Segmentation of Lungs from Chest X-Ray Images

34 views (last 30 days)
I need to segment the lungs from some Chest X-Ray images. I need the best code for this purpose if someone can provide that. Threshold or region based segmentation is much preferable.

Answers (2)

KALYAN ACHARJYA
KALYAN ACHARJYA on 22 Jan 2020
Edited: KALYAN ACHARJYA on 22 Jan 2020
There is no best code for Segmentation of Lungs from Chest X-Ray Images. The code depends on datasets or simmilar data types. The objectice of the code have to write the code, which may sutable for universal all images having simmilar types, though quite challenging, hence write the code which is best suitable for some wll verified public images multiple databases.
The segmentation approach is depends on test images, it would be better to comment more, if you can share a sample image. If the the ROI is distinctly differ from the rest part of the image, do threshold (recommended too, if it helps), otherwise with go with region growing or other segmentation methods and see theresults, you will be know which methods works for those images. There are so many approaches, request to follow the Gonzalez image processing using MATLAB book (Image Segmentation) for basic foundation.
Good Wishes!
  1 Comment
Rida Memon
Rida Memon on 22 Jan 2020
I've used the chest xray images from the JSRT dataset. I am unable to attach the image of that type over here. Could you provide me any universally accepted code for lung segmentation?

Sign in to comment.


Image Analyst
Image Analyst on 22 Jan 2020
  2 Comments
Rida Memon
Rida Memon on 24 Jan 2020
Kindly help me remove this error from my code. Where do i need to set the dimensions? Kindly explain
CODE:
fid = fopen('JPCLN001.img','r','b'); %image from JSRT dataset
oneSlice = fread(fid, [2048 2048], '*uint16','b');
img = mat2gray(oneSlice, [0,4096]);
img1 = imrotate(img,-90);
figure(101);
imshow(img1);
fclose(fid);
colormap(gray);
title('Grayscale X-Ray');
I=wiener2(img1, [5 5]);
figure(102);
subplot(2,1,1);
imshow(I);
subplot(2,1,2);
imhist(I, 256);
a_thresh = I >= 172; % set this threshold
[labelImage, numberOfBlobs] = bwlabel(a_thresh);
props = regionprops(a_thresh,'all');
sortedSolidity = sort([props.Solidity], 'descend');
SB = sortedSolidity(1);
if SB == 1 % SB only accept solidity == 1 filter out bones
binaryImage = imbinarize(I); figure(103);
imshow(binaryImage); colormap(gray);
SE = strel('square',3);
morphologicalGradient = imsubtract(imdilate(binaryImage, SE),imerode(binaryImage, SE));
mask = imbinarize(morphologicalGradient,0.03);
SE = strel('square',2);
mask = imclose(mask, SE);
mask = imfill(mask,'holes');
mask = bwareafilt(mask,2); % control number of area show
notMask = ~mask;
mask = mask | bwpropfilt(notMask,'Area',[-Inf, 5000 - eps(5000)]);
showMaskAsOverlay(0.5,mask,'r'); % you have to download app/function showMaskAsOverlay
BW2 = imfill(binaryImage,'holes');
new_image = BW2 ;
new_image(~mask) = 0; % invert background and holes
B=bwboundaries(new_image); % can only accept 2 dimensions
figure(104);
imshow(new_image);
hold on
visboundaries(B);
end
ERROR:
Warning: Image is too big to fit on screen; displaying at 33%
> In images.internal.initSize (line 71)
In imshow (line 309)
In a (line 6)
Index exceeds matrix dimensions.
Error in a (line 21)
SB = sortedSolidity(1);

Sign in to comment.

Categories

Find more on Agriculture in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!