问题是:我有一个元组列表(如果需要,也可以设置)。例如:
a = [(1, 5), (4, 2), (4, 3), (5, 4), (6, 3), (7, 6)]
Run Code Online (Sandbox Code Playgroud)
我想找到的是一个列表
r = [(1, 5, 4, 2, 3, 6, 7)]
Run Code Online (Sandbox Code Playgroud)
因为一旦所有集合放在一起,交集就不是空的。
例如
a = [(1, 5), (4, 2), (4, 3), (5, 4), (6, 3), (7, 6), (8, 9)]
Run Code Online (Sandbox Code Playgroud)
结果应该是
r = [(1, 5, 4, 2, 3, 6, 7), (8, 9)]
Run Code Online (Sandbox Code Playgroud)
希望问题很清楚。那么在python中最优雅的方法是什么,如果有的话?
干杯
所以我有一个单通道图像,它主要是 0(背景),以及一些前景像素的值,如 20、21、22。非零前景像素大多与具有相同值的其他前景像素聚集在一起。但是,图像中有一些噪点。为了消除噪音,我想使用连通分量分析,并且对于每个值(在本例中为 20、21、22),将除最大连通分量之外的所有内容归零。所以最后,我将有 3 个大的连接组件并且没有噪音。我将如何使用 cv2.connectedComponentsWithStats 来完成此操作?它似乎没有很好的记录,甚至在看过这篇文章之后,我不完全明白如何解析函数的返回值。有没有办法指定我只想要连接组件匹配特定灰度值的函数?
python opencv image-processing noise-reduction connected-components
在C#中,我有
class Pair{
int val1;
int val2;
}
Run Code Online (Sandbox Code Playgroud)
我有一个来自一个来源的对的列表: -
List<Pair> sList = new List<Pair>();
1 | 2
2 | 3
1 | 4
4 | 6
Run Code Online (Sandbox Code Playgroud)
我需要将其转换为以下类型的结构: -
[1, [2, 3, 4, 6]]
[2, [3]]
[3, [2]]
[4, [1,6]]
[6, [4]]
Run Code Online (Sandbox Code Playgroud)
什么是最好的方法(没有LINQ)?
我有以下代码,它只是一个简单的测试程序,用于学习如何在openCV 3.0中使用连接组件功能
int main(int argc, char** argv) {
char* line = argv[1];
Mat image;
image = imread(line,CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat label=Mat(image.size(),CV_16U);
int la=connectedComponents(image,label, 8,CV_16U);
//tried also: label.convertTo(label,CV_8U,255);
// and label.convertTo(label,CV_16U,255);
namedWindow( "input", CV_WINDOW_AUTOSIZE );
imshow( "input", image);
namedWindow( "ouput", CV_WINDOW_AUTOSIZE );
imshow("output", label);
cout<<la<<"\n";
imwrite("output.png", label);
waitKey(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输入图像是在白色背景上具有两个红色正方形的彩色图像.图像被正确加载并显示为灰度图像.

无论我做什么,输出总是一个空白图像,黑色或白色,取决于convertTo参数.
但是,返回的值connectedComponents是2.
我尝试了Miki提出的完整代码,我得到了这个:
我认为问题可能是连接的组件无法正常工作.
尝试了我在桌面上的图片,最后得到了一些东西:
然而,这次源图像是人,建筑物,汽车的常规图像......并且大部分输出仍然是空白的.有人知道为什么吗?
添加后 image = image < 200;
使用时applyColorMap(seeMyLabels, seeMyLabels, COLORMAP_JET);,标签图像从几乎黑色的灰度变为蓝色
我在大numpy数组中有许多不同的形式,我想使用numpy和计算它们之间的边到边欧几里德距离scipy。
Note: I did a search and this is different from previous other questions here on stack as I want to obtain the smallest distance between labeled patches within an array and not between points or seperate arrays as other questions have asked.
My current approach works using a KDTree, but is horribly inefficient for large arrays. Essentially I am looking up the coordinates of each labeled component and calculate the distance between …
numpy image-processing scipy euclidean-distance connected-components
我想将此图像中的白色像素数量减少到输出图像中的某些候选点或代表点(目标是模拟不同类型的形状)
如果您只是将输出图像中的灰点连接在一起,则路径相同但白色像素较少.此路径应该只有一个起点和一个终点,并涵盖从开始到结束的所有路径.
我可以使用CCA(连通分量分析)和一些其他规则来解决它!但似乎很慢.
我需要这个算法来减少描述形状所需的像素数量.
这里最快,最准确的算法是什么?
我也欢迎那些可以通过增加候选点来提高形状建模精度的方法.
大家好,我在处理 3D 数组中的连接组件时遇到问题。实际上,我正在研究用于神经影像研究的 3D CT 扫描数据。为了简单解释,有一个 3D 数组的例子:
filled = np.array([
[[0, 0, 1],[1, 0, 1],[1, 0, 1],[0, 0, 1],[0, 0, 1],[0, 0, 1]],
[[1, 0, 0],[1, 0, 0],[1, 0, 0],[0, 0, 0],[0, 0, 0],[0, 0, 0]],
[[1, 0, 0],[1, 0, 0],[1, 0, 0],[0, 0, 0],[0, 0, 0],[0, 0, 0]],
[[0, 0, 0],[0, 0, 0],[0, 0, 0],[0, 1, 0],[0, 1, 0],[0, 1, 0]],
[[0, 0, 0],[0, 0, 0],[0, 0, 0],[0, 1, 0],[0, 1, 0],[0, 1, 0]],
[[0, 0, 0],[0, 0, …Run Code Online (Sandbox Code Playgroud) 我正在研究行人检测算法并陷入使用ConnectedComponentsWithStats()方法。我无法获取统计数据的值。这是我到目前为止所写的:
var labels = new Mat();
var stats = new Mat();
var centroids = new Mat();
var nLabels = CvInvoke.ConnectedComponentsWithStats(greyImage, labels, stats, centroids);
var centroidPoints = new MCvPoint2D64f[nLabels];
centroids.CopyTo(centroidPoints);
foreach (MCvPoint2D64f point in centroidPoints)
{
var x = point.X;
var y = point.Y;
}
Run Code Online (Sandbox Code Playgroud) 在 OpenCV 3.0 中有一个名为connectedComponent的函数。
我知道它将二进制图像作为输入并返回标签和连接组件的数量,但是内部使用什么算法?
c++ opencv image-processing computer-vision connected-components
我正在使用petgraph,我想提取连接组件.
我想要一个HashMap<u32, Vec<&petgraph::graph::NodeIndex>>
带有a u32作为连接组件的标识符,以及一个Vec带有对连接组件中所有节点的引用的容器.
如果这是一个糟糕的设计,请毫不犹豫地指出一个更好的设计; 我是一个Rust初学者.
我试过这样的事情:
extern crate fnv;
extern crate petgraph;
use petgraph::visit::Dfs;
use fnv::FnvHashMap; // a faster hash for small key
use fnv::FnvHashSet;
// structure definition
pub struct NodeAttr {
pub name_real: String,
}
impl Default for NodeAttr {
fn default() -> Self {
NodeAttr {
name_real: "default_name_for_testing".to_string(),
}
}
}
pub struct EdgesAttr {
pub eval: f64,
pub pid: f32,
pub cov: f32, // minimum coverage
}
impl Default for EdgesAttr …Run Code Online (Sandbox Code Playgroud) 我在OpenCV(python)中遇到以下错误并且已经google了很多但是无法解决.
如果有人能给我提供一些线索,我将不胜感激.
OpenCV错误:断言失败(L.channels()== 1 && I.channels()== 1)在connectedComponents_sub1,file/home/snoopy/opencv- 3.1.0/modules/imgproc/src/connectedcomponents.cpp,line 341 Traceback(最近一次调用最后一次):文件"test.py",第30行,在plant = analyzeplant.analyzeSideView(plant)文件"/ home/snoopy/Desktop/Leaf-201612/my-work- editing/ripps/src /analyzePlant.py",第229行,在analyzeSideView中.plant_img = self .__ extractPlantArea(plant_img)文件"/ home/snoopy/Desktop/Leaf-201612/my-work- editing/ripps/src/analyzePlant.py",第16行, in __extractPlantArea output = cv2.connectedComponentsWithStats(plant,4,cv2.CV_32S)cv2.error:/ home/snoopy/opencv- 3.1.0/modules/imgproc/src/connectedcomponents.cpp:341:error:(215)>函数connectedComponents_sub1中的L.channels()== 1 && I.channels()== 1
opencv ×5
python ×4
c# ×2
c++ ×2
algorithm ×1
arrays ×1
dictionary ×1
emgucv ×1
graph ×1
graph-theory ×1
intersection ×1
numpy ×1
opencv3.1 ×1
python-2.7 ×1
rust ×1
scipy ×1
set ×1