计算布尔矩阵的密度如何?

huangapple go评论68阅读模式
英文:

How to compute the density of a boolean matrix?

问题

这是我在谈论的一个示例布尔矩阵。在左下角和右上角分别有一个4x4子矩阵,以及左上角和右下角各有两个离群点。我想要圈出左下角和右上角的这两个区域,但不确定应该如何操作。

当前我的想法是,显然左下角和右上角区域的点更密集,如果我可以计算一个“密度矩阵”,那么也许我可以设置一个密度阈值来过滤左上角和右下角的两个离群点,然后可以使用凸包来圈出我想要的区域。

但我对这个想法的可行性有疑虑,首先我不知道是否可以同时圈出两个区域,其次我不知道如何找到这个密度矩阵。如果您有更好的建议,请与我分享,非常感谢!

英文:

This is an example boolean matrix I'm talking about. There is a 4 by 4 sub-matrix in the lower left and upper right corner, and two outliers in the upper left and lower right corners respectively. I want to circle the two areas for the lower left and upper right corners and I'm not sure how I should do it.

[[1,0,0,0,0,0,1,1,1,1],\
 [0,0,0,0,0,0,1,1,1,1],\
 [0,0,0,0,0,0,1,1,1,1],\
 [0,0,0,0,0,0,1,1,1,1],\
 [0,0,0,0,0,0,0,0,0,0],\
 [0,0,0,0,0,0,0,0,0,0],\
 [1,1,1,1,0,0,0,0,0,0],\
 [1,1,1,1,0,0,0,0,0,0],\
 [1,1,1,1,0,0,0,0,1,1],\
 [1,1,1,1,0,0,0,0,0,0]]

My current thinking is that apparently the points in the bottom left and top right regions are more dense, and if I can compute a 'density matrix', then I can perhaps set a density threshold to filter the two outliers in the top left and bottom right corners, and then I can use convex hull to circle the region I want.

But I doubt the feasibility of this idea, firstly I don't know if I can circle both regions, and secondly I don't know how to find this density matrix. If you have a better idea, please share it with me, thanks a lot!

答案1

得分: 1

你可以使用一个2D卷积,使用一个4x4的全1矩阵。如果你绘制密度,它会形成一种近似圆形。

from scipy.signal import convolve2d
import numpy as np
import matplotlib.pyplot as plt

density = convolve2d(matrix, np.ones((4, 4)), mode='same')

plt.figure()
plt.imshow(density)

计算布尔矩阵的密度如何?

英文:

You can use a 2d convolution with a 4x4 matrix of ones. If you plot the densities, it forms a sort-of circle.

from scipy.signal import convolve2d
import numpy as np
import matplotlib.pyplot as plt


density = convolve2d(matrix, np.ones((4, 4)), mode = 'same')

plt.figure()
plt.imshow(density)

计算布尔矩阵的密度如何?

答案2

得分: 0

目前的思路是...计算一个 '密度矩阵',使用泛洪填充来识别连通分量。这样,你将获得每个分量的确切像素计数。按计数排序并保留大分量。

Pypi提供了更多可以选择的实现

侵蚀 "小" 区域可能也会有所帮助。

英文:

> current thinking is ... compute a 'density matrix',

Use flood fill
to identify connected components.
That way you'll have an exact pixel count for each component.
Sort by count and retain just the large components.

Pypi
offers
more
than
one
implementation to choose from.


Erosion
of "small" regions may also prove helpful.

huangapple
  • 本文由 发表于 2023年4月4日 04:50:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75923664.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定