![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/525794/image.png)
How to segment lung from 2D images
7 次查看(过去 30 天)
显示 更早的评论
Good day,
I have multiple 2D images from which I would like to segment the lung field from each. I successfully developed a code to do that, but it does not work for all the images as the contrast slightly vary from one image to the other (Image1 and 2 attached). I try using ‘imhistmatch’ to match the contrast between the images but without success. Please see my code below and the results obtained in fig.1. Could someone please help me modify the code to suit this purpose or suggest a better method to achieve this?
clear;clc;close all
% Ia=imread('image1.jpg');
load image1
II = adapthisteq(Ia,'clipLimit',0.02,'Distribution','rayleigh');
subplot(2,4,2);imshow(II);title('Adjusted contrast')
II(II>35000)=0;
II = bwareaopen(II,50); %remove connected components
mask = bwareafilt(II, 2); %There are small noise blobs. Extract the two largest objects.
z=ImageAnalyst(mask,-1); %Extract the 2nd largest objects.
subplot(2,4,1);imshow(Ia);title('Original image1')
subplot(2,4,3);imshow(z);title('segmented lung')
subplot(2,4,4);imshowpair(z,Ia);title('Image1/lung pair')
%%
% image2
% Ib=imread('image2.jpg');
load image2
I=imhistmatch(Ib, Ia);% adjust the histogram of 2D image to macth histogram of image1 image
I = adapthisteq(Ib,'clipLimit',0.02,'Distribution','rayleigh');
subplot(2,4,6);imshow(I);title('Adjusted contrast')
I(I>35000)=0;
I = bwareaopen(I,50); %remove connected components
mask = bwareafilt(I, 2); %There are small noise blobs. Extract the two largest objects.
z=ImageAnalyst(mask,-1); %Extract the 2nd largest objects ising ImageAnalyst funtion
subplot(2,4,5);imshow(Ib);title('Original image2')
subplot(2,4,7);imshow(z);title('segmented lung')
subplot(2,4,8);imshowpair(z,Ib);title('Image2/lung pair')
3 个评论
回答(1 个)
Keerthana Chiruvolu
2021-2-23
Hi,
Use the Image Segmenter App to segment the lungs from the images and generate binary mask easily. You can import the original image and export the mask directly to MATLAB Workspace.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!