问题:怎么解释

答案:percentile函数是统计学用于计算数据集的特定百分位数

percentile百分位数 与 percentile()函数

# 示原理代码
img = cv.imread('downloads/Signature.jpg')
# create a Pandas Series from the flatten BLUE channel array of the image.
ss = pd.Series(img[:, :, 0].flatten())
# calculating the **index** of quarter from the total number ss.count()
index_of_quarter = round(ss.count()/4)
# calculated MUST equal with ss.describe()["25%"]
sorted(ss) [index_of_quarter] == ss.describe()["25%"]
  • percentile百分位数: 数据集(先升序排序)上某个特定百分比位置(index序号)数据值.

    • 必须先将数据集由小到大顺序排列, 某个特定百分比数据点值.
    • 例如, 第75个百分位数 表示 有75%的数据点** 低于或等于 它(百分位数)的值.
  • percentile()函数: 统计学用于计算数据集的特定百分位数

    • percentile函数的计算方法依赖于选择的算法。常用的有线性插值法最近邻法等。

      线性插值法是最常用的: 在两个已知数值之间进行线性插值, 来估算百分位数的位置。
    • 统计分析时, percentile函数非常有用:

      通过它可以了解数据分布的特征,如数据的中心趋势和离散程度

      此外它在处理异常值时也表现稳健不会受到极值的影响

Pandas Descriptive statistics

Pandas is more powerful than NumPy for Number and Statistics Processing.

https://pandas.pydata.org/pandas-docs/stable/user_guide/basics.html#descriptive-statistics

import cv2 as cv
import numpy as np
import pandas as pd # Load the image first
img_path = 'downloads/Signature.jpg'
img = cv.imread(img_path)
assert img is not None, "file could not be read, check with os.path.exists('%s')" % img_path # Color Channels Splitting and merging
b, g, r =img[:, :, 0], img[:, :, 1], img[:, :, 2]
# img = cv.merge((b, g, r)) # Using Pandas for Number Analysis and Statistics
arr = b
ss, df = pd.Series(arr.flatten()), pd.DataFrame(arr) # Summarizing data: describe
# There is a convenient describe() function which computes a variety of summary statistics about a Series,
# or the columns of a DataFrame (excluding NAs of course).
ss.describe() Out[1]:
count 371712.000000
mean 135.706345
std 24.186046
min 3.000000
25% 140.000000
50% 143.000000
75% 145.000000
max 161.000000
dtype: float64 # Pandas: **select specific percentiles**:
# By default, the median is always included
percentiles = [0.05, 0.25, 0.75, 0.95]
ss.describe(percentiles=percentiles)
Out[1]:
count 371712.000000
mean 135.706345
std 24.186046
min 3.000000
5% 63.000000
25% 140.000000
50% 143.000000
75% 145.000000
95% 149.000000
max 161.000000
dtype: float64 In [2]: sorted(ss) [round(371712/20)]
Out[2]: 63

Here is a quick reference summary table of common functions.

Each also takes an optional level parameter which applies only if the object has a hierarchical index.

Statistics From NumPy Official Docs.

https://numpy.org/doc/stable/reference/routines.statistics.html

  • Order statistics

    numpy.percentile
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, method='linear', keepdims=False, *, weights=None, interpolation=None)
  • Averages and variances
  • Correlating
  • Histograms

Best Ways to Grayscale Images with Python Using OpenCV

March 11, 2024 by Emily Rosemary Collins

  • Problem Formulation

    In image processing, grayscaling is a procedure of converting color images into shades of gray, indicating that each pixel now represents the intensity of light only, not color. Programmers often need to perform this task to simplify or prepare images for further processing, such as edge detection or thresholding. A common input would be a colored image (JPEG, PNG, etc.), and the desired output is its grayscale version.
  1. cv2
# Load the image
image = cv2.imread('path_to_image.jpg')
# Convert the image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Save the grayscale image
cv2.imwrite('gray_image.jpg', gray_image)
  1. cv2
import cv2

# Load the image directly in grayscale
gray_image = cv2.imread('path_to_image.jpg', cv2.IMREAD_GRAYSCALE) # Save the grayscale image
cv2.imwrite('gray_image.jpg', gray_image)
  1. cv2
import cv2
import numpy as np # Load the image
image = cv2.imread('path_to_image.jpg') # Manually convert to grayscale using channel mixing
weights = [0.1140, 0.5870, 0.2989] # BGR weights
gray_image = np.dot(image[...,:3], weights).astype(np.uint8) # Save the grayscale image
cv2.imwrite('gray_image.jpg', gray_image)
  1. cv2
import cv2

# Load the image
image = cv2.imread('path_to_image.jpg') # Split the image into its individual color channels
b, g, r = cv2.split(image) # Use the red channel for grayscale effect
gray_image = cv2.merge([r, r, r]) # Save the grayscale image
cv2.imwrite('red_channel_gray_image.jpg', gray_image)
  1. cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg # Load the image
image = mpimg.imread('path_to_image.jpg') # Display the image in grayscale
plt.imshow(image, cmap='gray')
plt.axis('off') # Hide axis
plt.show()

SciTech-Mathmatics-Statistics-Descriptive Statistics-"Pandas + NumPy" + "Best Ways to Grayscale/"Color Channels Split" Images with Python Using OpenCV+Pandas+NumPy的更多相关文章

  1. perl 计算方差中值平均数 Statistics::Descriptive;

    http://search.cpan.org/~shlomif/Statistics-Descriptive-3.0612/lib/Statistics/Descriptive.pm use Stat ...

  2. 统计学基础知识(一)---描述统计学(Descriptive Statistics)

    描述统计学(Descriptive Statistics):将数据的信息以表格, 图形或数值的形式进行汇总. 数据类型:分为定量数据(数值型数据)和定性数据(类别型数据).数值型数据又可以分为连续型和 ...

  3. descriptive statistics|inferential statistics|Observational Studies| Designed Experiments

    descriptive statistics:组织和总结信息,为自身(可以是population也可以是sample)审视和探索, inferential statistics.从sample中推论p ...

  4. Python入门之安装numpy和pandas

    最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装numpy和pandas因为linux环境没有外网遇到了很多问题就记下来了. 首要条件,python版本必 ...

  5. python安装pip、numpy、scipy、statsmodels、pandas、matplotlib等

    1.安装python 2.安装numpy(开源的数值计算扩展,可用来存储和处理大型矩阵,比Python自身的嵌套列表(nested list structure)结构要高效的多. 很多库都是以此库为依 ...

  6. linux离线搭建Python环境及安装numpy、pandas

    1.安装python2.7.3 Cent OS 6.5默认装的有python2.6.6,需要重新安装python2.7.3下载地址:https://www.python.org/downloads/s ...

  7. 【Python实战】Pandas:让你像写SQL一样做数据分析(一)

    1. 引言 Pandas是一个开源的Python数据分析库.Pandas把结构化数据分为了三类: Series,1维序列,可视作为没有column名的.只有一个column的DataFrame: Da ...

  8. Python数据分析之pandas学习

    Python中的pandas模块进行数据分析. 接下来pandas介绍中将学习到如下8块内容:1.数据结构简介:DataFrame和Series2.数据索引index3.利用pandas查询数据4.利 ...

  9. 利用Python进行数据分析——pandas入门

    利用Python进行数据分析--pandas入门 基于NumPy建立的 from pandas importSeries,DataFrame,import pandas as pd 一.两种数据结构 ...

  10. python(5):scipy之numpy介绍

    python 的scipy 下面的三大库: numpy, matplotlib, pandas scipy 下面还有linalg 等 scipy 中的数据结构主要有三种: ndarray(n维数组), ...

随机推荐

  1. python 处理word 分页符、分节符

    import docx doc1 =docx.Document(r"C:\Users\Administrator\Desktop\test.docx") doc1.paragrap ...

  2. 最新版LangChain4j发布!终于修复了这个恶心的问题

    LangChain4j 1.0.0-beta4 上周刚刚发布,并且计划这个月中旬发布 RC1,我觉得这次升级还是非常实用的,除了修复了一些关键的 BUG 之外,还有一个被我经常吐槽的功能也被更正了,具 ...

  3. 移动端H5页面在不同Android和iOS设备上的兼容适配

    @charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...

  4. bat文件备份数据库

    @echo off/*获取当前日期*/ set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%" /*数据库自带的备份脚本的存放地址 --opt -u ...

  5. TVM: 编译流程

    深度学习编译器介绍 每一种硬件对应一门特定的编程语言,再通过特定的编译器去进行编译产生机器码,那随着硬件和语言的增多,编译器的维护难度会有很大困难.现代编译器已经解决了这个问题. 为了解决这个问题,科 ...

  6. python存储MongoDB数据

    MongoDB是由C++语言编写的非关系型数据库,是一个基于分布式文件存储的开源数据库系统,其内容存储形式类似JSON对象,它的字段值可以包含其他文档.数组及文档数组,非常灵活(总体来看,python ...

  7. C# 基础问题汇集

    (1)new List并不是null,可以正常的被遍历和AddRange class Program { public static void Main() { //var t = new test( ...

  8. numpy.tile用法

    先说下在numpy中,个人对array的维度的比较形象的理解: array的维度就是从最外边的[]出发(可理解为array的声明),一直找到具体数值而经过的[]的数量(含最后的数值,它是最后一维) 比 ...

  9. [Redis] Redis (7) 连接与会话管理

    序:文由 因今日排查问题,发现微服务因 ERR max number of clients reached (已达到客户端的最大数量) redis异常,而导致服务在健康检测时未通过,进而导致高频宕机. ...

  10. VirtualBox 导入/注册 虚拟机文件 .vbox 失败

    VirtualBox 导入/注册 虚拟机文件 .vbox 失败 问题情景 Error: Failed to open virtual machine located in <.vbox所在目录& ...