Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The adjacency mask set to 1 when Si and Sj share a common boundary. How to check if these two share a common boundary? #5

Open
luciaL opened this issue Mar 30, 2021 · 1 comment

Comments

@luciaL
Copy link

luciaL commented Mar 30, 2021

Thank you so much for your code.
I don't understand this line: sub = self.segments[i:i + 2, j:j + 2]
Could you please explain how to judge if the two superpixels share a common boundary?
`
def get_A(self, sigma: float):
'''
根据 segments 判定邻接矩阵
:return:
'''
A = np.zeros([self.superpixel_count, self.superpixel_count], dtype=np.float32)
(h, w) = self.segments.shape
for i in range(h - 2):
for j in range(w - 2):
sub = self.segments[i:i + 2, j:j + 2]
sub_max = np.max(sub).astype(np.int32)
sub_min = np.min(sub).astype(np.int32)
# if len(sub_set)>1:
if sub_max != sub_min:
idx1 = sub_max
idx2 = sub_min
if A[idx1, idx2] != 0:
continue

                pix1 = self.S[idx1]
                pix2 = self.S[idx2]
                diss = np.exp(-np.sum(np.square(pix1 - pix2)) / sigma ** 2)
                A[idx1, idx2] = A[idx2, idx1] = diss 

`

@qichaoliu
Copy link
Owner

Thanks. In fact, I adopted a very simple suboptimal solution. I used a very small window (2x2 or 3x3)to detect the boundaries, i.e., if the classes of pixels in this window exceed 2, then it must be on the boundary. Just like the edge detector.

Best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants