MATLAB: How to find the boundaries of a value in a matrix

indexingMATLABmatrix

Hi, I have a matrix as follows:
I =
1 1 1 1 8 1 2
1 1 8 8 8 2 1
1 8 8 1 2 1 1
1 1 8 2 1 1 1
2 2 2 1 1 1 1
2 2 2 1 1 1 1
I want a matrix which will be output of boundary value of 8 i.e. (1,5),(2,3),(2,4),(2.5),(3,2),(3.3),(4.3)
Is there any way to he find these location easily?

Best Answer

[r c] = find(bwperim(I==8));