我有一个具有这种结构的数据集:
In[17]: allIndices
Out[17]:
[{0: 0, 1: 1.4589, 4: 2.4879},
{0: 1.4589, 1: 0, 2: 2.1547},
{1: 2.1547, 2: 0, 3: 4.2114},
{2: 4.2114, 3: 0},
{0: 2.4879, 4: 0}]
Run Code Online (Sandbox Code Playgroud)
我想确定 dict 列表中的最高值。我做如下:
def findMax(data):
possiblemax = []
for i in range(len(data)):
temp = list(data[i].values())
tempmax = max(temp)
possiblemax.append(tempmax)
maxValue = max(possiblemax)
return maxValue
Run Code Online (Sandbox Code Playgroud)
它有效,但我使用了一个非常大的数据集,而且速度有点慢。我想知道一种更好更快的方法来做到这一点。
非常感谢
经过2到3天的搜索,我仍然没有找到解决问题的方法.
我想创建一个没有阴影的鼠标分段.问题是如果我设法移除阴影我也删除尾部和脚部这是一个问题.阴影来自鼠标所在的竞技场墙壁.
我想从灰度图像中删除阴影,但我不知道如何做到这一点.首先,我删除了图像的背景,并获得了以下图片.
edit1:谢谢你的答案,当阴影没有碰到鼠标时效果很好.这就是我得到的结果:
从这张原始图片:
我从tif文件中提取每个帧并为每个帧应用代码.这是我使用的代码:
for k=1:1000
%reads image
I = imread('souris3.tif',k);
%first stage: perform thesholding and fill holes
seg = I >20000;
seg = imfill(seg,'holes');
%fixes the missing tail problem
%extract edges, and add them to the segmentation.
edges = edge(I);
seg = seg | edges;
%fill holes (again)
seg = imfill(seg,'holes');
%find all the connected components
CC = bwconncomp(seg,8);
%keeps only the biggest CC
numPixels = cellfun(@numel,CC.PixelIdxList);
[biggest,idx] = max(numPixels);
seg = zeros(size(edges));
seg(CC.PixelIdxList{idx}) = 1;
imshow(seg); …Run Code Online (Sandbox Code Playgroud)