标签: threshold

直方图中的垂直线与pyplot

我已经为kinect深度图像计算了Otsu的阈值,现在我想指出直方图上的最佳阈值,例如在opencv2中使用带有pyplot的axvline.我是python和编程的初学者,这是我的代码的特定部分:

fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5))
ax1.imshow(img)
ax1.set_title('Original')
ax1.axis('off')

ax2.hist(img)
ax2.set_title('Histogram')
plt.axvline(x=thresh, color='r', linestyle='dashed', linewidth=2)

ax3.imshow(binary, cmap=plt.cm.gray)
ax3.set_title('Thresholded')
ax3.axis('off')

plt.show()
Run Code Online (Sandbox Code Playgroud)

但我不知道为什么,我在阈值图上获得了垂直线

我究竟做错了什么??谢谢

matplotlib histogram python-2.7 threshold

5
推荐指数
1
解决办法
6017
查看次数

获取白色像素的坐标(OpenCV)

在OpenCV(C++)中,我有一个黑白图像,其中一些形状显示为白色(255).知道这一点,我怎样才能获得这些对象所在的图像中的坐标点?我对获取所有白色像素坐标感兴趣.

有比这更清洁的方式吗?

std::vector<int> coordinates_white; // will temporaly store the coordinates where "white" is found 
for (int i = 0; i<img_size.height; i++) {
    for (int j = 0; j<img_size.width; j++) {
        if (img_tmp.at<int>(i,j)>250) {
            coordinates_white.push_back(i);
            coordinates_white.push_back(j);
        }
    }
}
// copy the coordinates into a matrix where each row represents a *(x,y)* pair
cv::Mat coordinates = cv::Mat(coordinates_white.size()/2,2,CV_32S,&coordinates_white.front());
Run Code Online (Sandbox Code Playgroud)

c++ opencv matrix threshold

5
推荐指数
1
解决办法
1万
查看次数

Pandas - 按ID分组并删除重复阈值

我有以下数据:

userid itemid
  1       1
  1       1
  1       3
  1       4
  2       1
  2       2
  2       3
Run Code Online (Sandbox Code Playgroud)

我想删除已查看相同itemID大于或等于两次的userID.例如,userid = 1已经两次查看itemid = 1,因此我想删除userid = 1的整个记录​​.但是,由于userid = 2没有两次查看同一项,我将保留userid = 2.

所以我希望我的数据如下:

userid itemid
  2       1
  2       2
  2       3
Run Code Online (Sandbox Code Playgroud)

有人能帮我吗?

import pandas as pd    
df = pd.DataFrame({'userid':[1,1,1,1, 2,2,2],
                   'itemid':[1,1,3,4, 1,2,3] })
Run Code Online (Sandbox Code Playgroud)

python group-by duplicates threshold pandas

5
推荐指数
2
解决办法
5590
查看次数

Damerau - Levenshtein距离,增加一个门槛

我有以下实现,但我想添加一个阈值,所以如果结果将大于它,只需停止计算并返回.

我该怎么办呢?

编辑:这是我目前的代码,threshold尚未使用...目标是它被使用

    public static int DamerauLevenshteinDistance(string string1, string string2, int threshold)
    {
        // Return trivial case - where they are equal
        if (string1.Equals(string2))
            return 0;

        // Return trivial case - where one is empty
        if (String.IsNullOrEmpty(string1) || String.IsNullOrEmpty(string2))
            return (string1 ?? "").Length + (string2 ?? "").Length;


        // Ensure string2 (inner cycle) is longer
        if (string1.Length > string2.Length)
        {
            var tmp = string1;
            string1 = string2;
            string2 = tmp;
        }

        // Return trivial case - where string1 is …
Run Code Online (Sandbox Code Playgroud)

c# levenshtein-distance threshold

4
推荐指数
1
解决办法
4779
查看次数

Python中的快速RGB阈值处理(可能是一些智能的OpenCV代码?)

我需要对大量图像进行一些快速阈值处理,每个RGB通道都有一个特定的范围,即去除(使黑色)不在[100; 110]中的所有R值,所有G值都不在[80; 85]和所有B值不在[120; 140]

使用到OpenCV的python绑定为我提供了一个快速阈值处理,但它将所有三个RGP通道阈值设置为单个值:

cv.Threshold(cv_im,cv_im,threshold+5, 100,cv.CV_THRESH_TOZERO_INV)
cv.Threshold(cv_im,cv_im,threshold-5, 100,cv.CV_THRESH_TOZERO)
Run Code Online (Sandbox Code Playgroud)

或者,我尝试通过将图像从PIL转换为numpy来手动完成:

arr=np.array(np.asarray(Image.open(filename).convert('RGB')).astype('float'))
for x in range(img.size[1]):
    for y in range(img.size[0]):
        bla = 0
        for j in range(3):
            if arr[x,y][j] > threshold2[j] - 5 and arr[x,y][j] < threshold2[j] + 5 :
                bla += 1
        if bla == 3:
            arr[x,y][0] = arr[x,y][1] = arr[x,y][2] = 200
        else:
            arr[x,y][0] = arr[x,y][1] = arr[x,y][2] = 0
Run Code Online (Sandbox Code Playgroud)

虽然这是按预期工作的,但速度非常慢!

关于如何快速实现这一点的任何想法?

非常感谢,Bjarke

python rgb opencv threshold

4
推荐指数
2
解决办法
9701
查看次数

文档图像二值化

我正在尝试为文档图像找到有效的二值化技术.我目前已经实现了niblack和sauvola阈值算法,并尝试了基于直方图评估的二值化.有人可以建议其他已证明有效的二值化方法吗?这是我一直在使用的降级图像示例:

在此输入图像描述

http://spie.org/Images/Graphics/Newsroom/Imported/0681/0681_fig1.jpg

任何建议将不胜感激.

matlab image-processing threshold

4
推荐指数
1
解决办法
3036
查看次数

具有 Sigmoid 激活的神经网络是否使用阈值?

我在这里有点困惑。我刚刚开始研究神经网络的主题,我构建的第一个主题使用了对每个神经元设置阈值的 Step-Activation。现在我不想实现 sigmoid 激活,但似乎这种类型的激活不使用阈值,只使用神经元之间的权重。但是在我找到的关于此的信息中有阈值的词,只有我找不到它们应该在激活函数中的位置。

神经网络的 sigmoid 激活函数中是否使用了阈值?

artificial-intelligence neural-network threshold

4
推荐指数
2
解决办法
5910
查看次数

按颜色OpenCV 2.x跟踪多个对象

目前我正在尝试按颜色跟踪多个对象.我基于文档代码.

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while(1):

    # Take each frame
    _, frame = cap.read()

    # Convert BGR to HSV
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    # define range of blue color in HSV
    lower_blue = np.array([110,50,50])
    upper_blue = np.array([130,255,255])

    # Threshold the HSV image to get only blue colors
    mask = cv2.inRange(hsv, lower_blue, upper_blue)

    # Bitwise-AND mask and original image
    res = cv2.bitwise_and(frame,frame, mask= mask)

    cv2.imshow('frame',frame)
    cv2.imshow('mask',mask)
    cv2.imshow('res',res)
    k = cv2.waitKey(5) & 0xFF
    if k == 27: …
Run Code Online (Sandbox Code Playgroud)

python opencv hsv bitwise-and threshold

4
推荐指数
1
解决办法
7279
查看次数

python的负阈值,最低非无穷负数?

python可表示负数的阈值是多少?最低的数字是多少,Python将在其以下将任何其他值称为-负无穷大?

python numbers infinity threshold

4
推荐指数
1
解决办法
2091
查看次数

计算高于阈值的数据帧中的行数作为函数或其他列因子

我希望找到每个主题的行数,其中每个主题的值大于11,并将其输出到数据框中进行分析.数据集很大(5000行),因此需要一个函数.

subject = c(rep("A", 12), rep("B", 12))        
day = c(1,1,1,1,2,2,2,2,3,3,3,3,1,1,1,1,2,2,2,2,3,3,3,3)
value = c(13,14,15,5,12,9,6,14,4,2,1,2,13,14,15,5,12,9,6,14,2,2,2,3)
df = data.frame(subject, day, value)
df

   subject day value
1        A   1    13
2        A   1    14
3        A   1    15
4        A   1     5
5        A   2    12
6        A   2     9
7        A   2     6
8        A   2    14
9        A   3     4
10       A   3     2
11       A   3     1
12       A   3     2
13       B   1    13
14       B   1    14
15       B …
Run Code Online (Sandbox Code Playgroud)

r collapse dataframe threshold

4
推荐指数
1
解决办法
384
查看次数