How to crop/mask image using matlab ?
Show older comments
how to do cropping on an image ?

5 Comments
Armylia Dewi
on 15 Jun 2022
KSSV
on 15 Jun 2022
You want to mask the black pixel region?
Armylia Dewi
on 15 Jun 2022
Armylia Dewi
on 15 Jun 2022
Accepted Answer
More Answers (1)
Image Analyst
on 9 Jul 2022
See my attached lung segmentation demo.

It should be easy for you to adapt even though your images are in a different orientation.
Once you have the mask, you can crop your image to the bounding box of just the lungs like this
[r, c] = find(mask);
row1 = min(r);
row2 = max(r);
col1 = min(c);
col2 = max(c);
croppedImage = maskedImage(row1:row2, col1:col2);
Categories
Find more on Image Segmentation 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!
