![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/276732/image.jpeg)
how to crop white regions alone in a binary image without user interface.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ashwini
el 2 de Feb. de 2016
Comentada: shan shan
el 12 de Mzo. de 2020
I have a binary image with background in black color and foreground in white color. how to crop only the foreground region without using tools like roipoly or imfreehand..
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153809/image.jpeg)
to
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153810/image.jpeg)
1 comentario
shan shan
el 12 de Mzo. de 2020
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/276732/image.jpeg)
Respuesta aceptada
Image Analyst
el 2 de Feb. de 2016
You can use regionprops() to get the bounding box. Then use indexing to extract (crop) it.
Alternatively, if you don't have the Image Processing Toolbox, use
[rows, columns] = find(binaryImage);
row1 = min(rows);
row2 = max(rows);
col1 = min(columns);
col2 = max(columns);
croppedImage = binaryImage(row1:row2, col1:col2);
2 comentarios
Image Analyst
el 12 de Feb. de 2016
There is nothing to crop. You want the whole image. regionprops gives box coordinates "outside" the pixels because the pixels are at the integers for example if a pixel at 3 was zero and the pixel at 4 was 1, then the bounding box would go in between them at a location of 3.5.
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!