title: Lung segmentation in Matlab
body: <p>Trying to segment out the lung region, I am having a lot of trouble. Incoming image is like this: (This is essentially a jpg conversion, and each pixel is 8 bits.)
  <a href="https://i.stack.imgur.com/zFrkx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zFrkx.jpg" alt="enter image description here"></a></p>
  
  <pre><code>I = dicomread('000019.dcm');
  I8 = uint8(I / 256);
  B = im2bw(I8, 0.007);
  segmented = imclearborder(B);
  </code></pre>
  
  <p>Above script generates: 
  <a href="https://i.stack.imgur.com/3mHTV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3mHTV.jpg" alt="enter image description here"></a></p>
  
  <h2>Q-1</h2>
  
  <p>I am interested in entire inner black part with <em>white matter as well</em>. I have started <code>matlab</code> couple of days ago, so not quite getting how can I do it. If it is not clear to you what kind of output I want, let me know-I will upload an image. But I think there is no need.</p>
  
  <h1>Q-2</h1>
  
  <p>in <code>B = im2bw(I8, 0.007);</code> why I need to give a threshold so low? with higher thresholds everything is white or black. I have read the documentation and as I understand it, the pixels with value less than 0.007 are marked black and everything above is white. Is it because of my 16-to-8 bit conversion?</p>