フィルターのクリア

how to crop white regions alone in a binary image without user interface.

1 回表示 (過去 30 日間)
Ashwini
Ashwini 2016 年 2 月 2 日
コメント済み: shan shan 2020 年 3 月 12 日
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..
to
  1 件のコメント
shan shan
shan shan 2020 年 3 月 12 日
This is my binary image from this i have to crop the white regions into three images separately can you please help me to do this?,thanks in advance.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2016 年 2 月 2 日
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 件のコメント
Ashwini
Ashwini 2016 年 2 月 12 日
Thank a lot.I executed the above code and it works.. But how to get this with regionprops() ?? when i use regionprops(img,'Boundingbox'), boundingbox gives fraction values. i tried with a binary matrix z=
1 0 0 1 1
0 0 0 1 0
1 0 0 1 0
1 0 0 0 0
1 0 1 1 1
st=regionprops(z,'boundingbox'); gives 1x1 struct which has Boundingbox=[0.5000 0.5000 5 5]
how to get index from this.. can u provide me the code...
Image Analyst
Image Analyst 2016 年 2 月 12 日
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.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by