Remove Black Background from segmented binary image
Show older comments
how can i remove the black background after i segmented the lung ct image i need to save only lungs in another directory 

Accepted Answer
More Answers (1)
Image Analyst
on 19 May 2021
Images must remain rectangular so you can't "remove" the black pixels and still have an image. There has to be something there. If you want, you could crop the image, but I don't see any use in that, other than saving an insignificant amount of disk space. You can replace the 0's with nans if you want
binaryImage = double(binaryImage); % Change from logical to floating point.
binaryImage(binaryImage == 0) = nan;
Not sure what use there is for that either. What do you really want to do? Why do you think you want to do this? So let's say you could remove 0's -- what would you do with the remaining output of all 1's?
2 Comments
Allie Nokhostin
on 20 May 2021
Image Analyst
on 22 May 2021
I don't think that is necessary. All you need is the mask saying what is lungs and what is not. Why do you think you need to erase/blacken part of the original image? You don't really need to unless you just want to see it for curiosity.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



