Question: Hello I am working with matlab. I am trying to generate a bounding box around a silhouette. The problem here is that the silhouette is fragmented
as shown here

![enter image description here](https://i.stack.imgur.com/zE5SY.png)

The code i tried is

```
BW=bwconncomp(image);
STATS = regionprops(BW, 'FilledArea','BoundingBox');

```

which gives me a bounding box around a part of the silhouette. I cannot use `dilate` which is the preferred morphological operation in this case as it connects the silhouette with neighboring fragments. 

Thanks in advance for the help.

Answer: 
Here is something to get you going with the image you posted. I used a line structuring element with an angle to dilate the image and amplify the signal from the small white chunks at the left of the silhouette. Then using `regionprops` its easier to identify objects individually and select the object with the largest area (i.e. the silhouette), calculated with the property `FilledArea`, and report back the bounding box on the original image. It might not be perfect but it's a start and it seems to give a pretty decent result. 

Here is the code:

```
clear
clc
close all

BW = im2bw(imread('Silhouette.png'));
BW = imclearborder(BW);

%// Dilate with a line structuring element oriented at about 60 degrees to
%// amplify the elements at an angle that you don't want.
se = strel('line',5,60);        
dilateddBW = imdilate(BW,se);

figure;
imshow(dilateddBW)

```

The dilated image looks like this:

![enter image description here](https://i.stack.imgur.com/Q1whn.jpg)

Calling `regionprops` and displaying the output:

```
%// Get the region properties and select that with the largest area.
S = regionprops(dilateddBW,'BoundingBox','FilledArea','PixelIdxList');

boundingboxes = cat(1, S.BoundingBox);
FilledAreas = cat(1,S.FilledArea);

[~,MaxAreaIndex] = max(FilledAreas);

%// Get linear indices of the corresponding silhouette to display along
%// with its bounding box.
MaxIndices = S(MaxAreaIndex).PixelIdxList;

%// Create empty image to put the silhouette + box
NewIm = false(size(dilateddBW));

NewIm(MaxIndices) = 1;

figure;

imshow(BW)
rectangle('Position',boundingboxes(MaxAreaIndex,:),'EdgeColor','r')

```

Output:

![enter image description here](https://i.stack.imgur.com/vm599.jpg)

Hope that helps somehow!
Since you have an array of vectors containing indice of pixels(bwconncomp() returns a struct which have a member named PixelIdxList), you can create a rectangle by finding pixels with min x, min y, max x, max y.

Here is a good example: [2D Minimal Bounding Box](http://www.mathworks.com/matlabcentral/fileexchange/31126-2d-minimal-bounding-box/content//minBoundingBox.m "2D Minimal Bounding Box")