Getting a single bounding box in image

I am currently trying to obtain the bounding boxes of a bw image. Sometimes I get a single 1-by-4 vector, sometimes too I get multiple 1-by-4 vectors. In the latter case how am I supposed to figure out the real bounding box of the image? My image is a single apple on a white background. First I convert the image to bw using im2bw, I use imcomplement to get a white apple on a black background, and then I use the regionprops function with parameter 'BoundingBox'. The reason I'm doing this is because I would like to create a training set of apples, using a structure having imageFileName as the field of image file names, and BoundingBoxes as the field of the images bounding boxes. However I obtain several bounding boxes for a single image. I think it would be more logical to get only one bounding box per bw image.

3 件のコメント

Walter Roberson
Walter Roberson 2013 年 11 月 27 日
When you use im2bw(), what threshold are you supplying? Are you doing any corrections for illuminations before converting to bw ?
Igor P. Louzolo-Kimbembe
Igor P. Louzolo-Kimbembe 2013 年 11 月 27 日
When using im2bw I use graythresh for automatic thresholding. Here is a code snippet
if true
% code
im = imread('file_path');
im = im2bw(im, graythresh(im));
im = imcomplement(im);
im = imfill(im, 'holes');
bbox = regionprops(im, 'BoundingBox');
bbox % structure of 5 1-by-4 vectors
end
kowshik Thopalli
kowshik Thopalli 2016 年 10 月 24 日
How did you solve your problem?

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

回答 (1 件)

Image Analyst
Image Analyst 2016 年 10 月 24 日

1 投票

You must have multiple blobs in your binary image, not just one. Use bwareafilt() to extract the largest one only.

質問済み:

2013 年 11 月 27 日

回答済み:

2016 年 10 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by