How to compute regions of matrix
Lets take the given matrix as 
$$A=\left[\begin{array}{cccccc}&amp;0 &amp;0 &amp;0 &amp;0 &amp;0 &amp;0 &amp;\\
&amp;0 &amp;\color{red}{1} &amp;0 &amp;0 &amp;0 &amp;0 \\
&amp;\color{red}{1} &amp;\color{red}{1} &amp;0 &amp;0 &amp;0 &amp;0 \\
&amp;\color{red}{1} &amp;\color{red}{1} &amp;0 &amp;0 &amp;0 &amp;0 \\
&amp;0 &amp;0 &amp;0 &amp;0 &amp;0 &amp;0 \\
&amp;0 &amp;0 &amp;0 &amp;\color{blue}{1} &amp;\color{blue}{1} &amp;\color{blue}{1} \\
&amp;0 &amp;0 &amp;0 &amp;0 &amp;\color{blue}{1} &amp;\color{blue}{1} \\
&amp;0 &amp;0 &amp;0 &amp;0 &amp;0 &amp;0\end{array}\right]$$

Then use the MATLAB function bwlabel to find the connected components in the matrix.

cc=bwlabel(A);


when you run this in MATLAB you will get cc as,

$$ cc = \left[\begin{array}{cccccc} 
  &amp;0&amp;      0&amp;      0&amp;      0&amp;      0&amp;      0&amp; \\
     &amp;0&amp;      \color{red}{1}&amp;      0&amp;      0&amp;      0&amp;      0&amp; \\
     &amp;\color{red}{1}&amp;      \color{red}{1}&amp;      0&amp;      0&amp;      0&amp;      0&amp; \\
     &amp;\color{red}{1}&amp;      \color{red}{1}&amp;      0&amp;      0&amp;      0&amp;      0&amp; \\
     &amp;0&amp;      0&amp;      0&amp;      0&amp;      0&amp;      0&amp; \\
     &amp;0&amp;      0&amp;      0&amp;      \color{blue}{2}&amp;      \color{blue}{2}&amp;      \color{blue}{2}&amp; \\
     &amp;0&amp;      0&amp;      0&amp;      0&amp;      \color{blue}{2}&amp;      \color{blue}{2}&amp; \\
     &amp;0&amp;      0&amp;      0&amp;      0&amp;      0&amp;      0&amp; \end{array}\right]$$

1 indicate connected region 1, 2 indicates connected region 2, etc

If you want 2D pixel locations use, find function in cc

i.e.:

[r c]=find(cc==1) gives the row (r) and column (c) locations of the 1st connected region.

[r c]=find(cc==2) gives the row (r) and column (c) locations of the 2nd connected region, and so on.

Now you can get what ever you want..