title: How to use bwareafilt matlab function with 3d matrix?
body: <p>I need to use bwareafilt function for 3d matrix "image" in matlab but that have an issue as it returns with an error saying that its input should be 2d matrix, how can I overcome that ??</p>
  
  <p>I am working on CT lung images, In 2d version I used bwareafilt with no problems, but in 3d volume of CT I can't</p>
  
  <pre><code>y = ~bwareafilt(out &gt; 1,1); % out is the segmented lung image, I need to remain the largest area in the image, which will be the lungs
  z = imfill(~y,'holes');
  mask = y.*z;
  se2=strel('disk',10);
  mask=imopen(mask,se2);
  mask=imclose(mask,se2);
  </code></pre>