Minimum width across any part of a connected component in matlab

1 view (last 30 days)
In order to label connected components in a matrix composed of double format values (not binary values), I am using a Matlab Central File Exchange program: LABEL
So, let's say I have a double format matrix of the form:
A = [1 3 3 3 3 6 6;
1 3 3 0 6 6 6;
1 3 3 0 4 4 6;
1 2 2 0 4 4 6;
1 2 2 0 5 5 6;
1 1 1 0 5 5 6;
1 1 1 0 5 5 6]
If I run the above mentioned LABEL function with 4-connectivity, I get the results in the form of labels, area of each connected components and number of connected components.
Labels:
1 2 2 2 2 5 5
1 2 2 4 5 5 5
1 2 2 4 6 6 5
1 3 3 4 6 6 5
1 3 3 4 7 7 5
1 1 1 4 7 7 5
1 1 1 4 7 7 5
Area of each connected component:
11 8 8 8 8 10 10
11 8 8 6 10 10 10
11 8 8 6 4 4 10
11 4 4 6 4 4 10
11 4 4 6 6 6 10
11 11 11 6 6 6 10
11 11 11 6 6 6 10
and 7 number of components.
If we look at the A matrix that I have written above, we can see the connected component with value 1 is only 1 cell wide at some places (see first column of A matrix). Similarly for components with elements 0, 6, 3.
Is there any way that I can replace the cells which are only 1 cell wide (in any component) with NaN values. Basically, from all the components, I would like to remove the parts which are only 1 cell wide, and replace those parts (cells) with NaN values.
My attempts: I tried using the ratio of horizontal width to vertical width of a
BoundingBox
and
Eccentricity
from
regionprops
function, but I could not achieve any satisfactory results.
Can anybody please help me out with this? Thanks!
P.S. : The "1" cell wide value can be any threshold that we can decide in our code. If possible, I would like to be able to remove any parts which are only "threshold" cells wide (threshold can be 1 or 2 or any positive integer).
  1 Comment
Ankit Sahay
Ankit Sahay on 1 Sep 2020
So I came across this answer by Image Analyst about Solidity, where he mentions that
"a thin "L" shape (or T or E, etc.) would have a very low solidity. The more bays, nooks, and crannies it has, the lower the solidity."
Maybe this might be of some use. I will give an update if this solves my problem.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 1 Sep 2020
Edited: Cris LaPierre on 1 Sep 2020
Here's a quick and simple way to do it
for c = 0:max(A,[],'all')
tmp = sum(A==c,2);
if any(tmp==1)
A(A==c)=missing;
end
end
A = 7×7
NaN 3 3 3 3 NaN NaN
NaN 3 3 NaN NaN NaN NaN
NaN 3 3 NaN 4 4 NaN
NaN 2 2 NaN 4 4 NaN
NaN 2 2 NaN 5 5 NaN
NaN NaN NaN NaN 5 5 NaN
NaN NaN NaN NaN 5 5 NaN
  7 Comments
Cris LaPierre
Cris LaPierre on 3 Sep 2020
Try removing the semi-colons and then run the code. You could also try splitting the code into parts to see what each bit is doing.
c=1
A==c
tmp = sum(A==c,2)
A(A==c)=missing
A(tmp==1)=missing
A(A==c & tmp==1)=missing
Change the value of c to see how it handles each value.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!