Minimum width across any part of a connected component in matlab

조회 수: 1 (최근 30일)
Ankit Sahay
Ankit Sahay 2020년 9월 1일
댓글: Ankit Sahay 2020년 9월 4일
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
Ankit Sahay
Ankit Sahay 2020년 9월 1일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 9월 1일
편집: Cris LaPierre 2020년 9월 1일
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
Cris LaPierre
Cris LaPierre 2020년 9월 3일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by