SciTech-Mathmatics-Statistics-Descriptive Statistics-"Pandas + NumPy" + "Best Ways to Grayscale/"Color Channels Split" Images with Python Using OpenCV+Pandas+NumPy
问题:怎么解释
答案: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函数非常有用:
通过它可以了解数据分布的特征,如数据的中心趋势和离散程度。
此外它在处理异常值时也表现稳健,不会受到极值的影响。
- 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.
- 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)
- 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)
- 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)
- 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)
- 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的更多相关文章
- perl 计算方差中值平均数 Statistics::Descriptive;
http://search.cpan.org/~shlomif/Statistics-Descriptive-3.0612/lib/Statistics/Descriptive.pm use Stat ...
- 统计学基础知识(一)---描述统计学(Descriptive Statistics)
描述统计学(Descriptive Statistics):将数据的信息以表格, 图形或数值的形式进行汇总. 数据类型:分为定量数据(数值型数据)和定性数据(类别型数据).数值型数据又可以分为连续型和 ...
- descriptive statistics|inferential statistics|Observational Studies| Designed Experiments
descriptive statistics:组织和总结信息,为自身(可以是population也可以是sample)审视和探索, inferential statistics.从sample中推论p ...
- Python入门之安装numpy和pandas
最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装numpy和pandas因为linux环境没有外网遇到了很多问题就记下来了. 首要条件,python版本必 ...
- python安装pip、numpy、scipy、statsmodels、pandas、matplotlib等
1.安装python 2.安装numpy(开源的数值计算扩展,可用来存储和处理大型矩阵,比Python自身的嵌套列表(nested list structure)结构要高效的多. 很多库都是以此库为依 ...
- linux离线搭建Python环境及安装numpy、pandas
1.安装python2.7.3 Cent OS 6.5默认装的有python2.6.6,需要重新安装python2.7.3下载地址:https://www.python.org/downloads/s ...
- 【Python实战】Pandas:让你像写SQL一样做数据分析(一)
1. 引言 Pandas是一个开源的Python数据分析库.Pandas把结构化数据分为了三类: Series,1维序列,可视作为没有column名的.只有一个column的DataFrame: Da ...
- Python数据分析之pandas学习
Python中的pandas模块进行数据分析. 接下来pandas介绍中将学习到如下8块内容:1.数据结构简介:DataFrame和Series2.数据索引index3.利用pandas查询数据4.利 ...
- 利用Python进行数据分析——pandas入门
利用Python进行数据分析--pandas入门 基于NumPy建立的 from pandas importSeries,DataFrame,import pandas as pd 一.两种数据结构 ...
- python(5):scipy之numpy介绍
python 的scipy 下面的三大库: numpy, matplotlib, pandas scipy 下面还有linalg 等 scipy 中的数据结构主要有三种: ndarray(n维数组), ...
随机推荐
- (dify)如何使用dify自定义知识库【dify外部链接知识库】
尝试dify自定义知识库 根据官网教程,可以从知识库的右上角外部知识库进行添加外部知识库 前往 "知识库" 页,点击右上角的 "外部知识库 API",轻点 &q ...
- Java实现minio上传文件加解密操作
一.背景与需求 在云存储场景中,数据安全是核心需求之一.MinIO作为高性能对象存储服务,支持通过客户端加密(CSE)在数据上传前完成加密,确保即使存储服务器被攻破,攻击者也无法获取明文数据.本文将详 ...
- 解决github无法访问的问题,亲测有效--很强
参考:https://segmentfault.com/a/1190000037498373 ubuntu系统:在/etc/hosts文件中增加以下内容: windows系统:C:\Windows\S ...
- 【最新】MySQL 5.6 保姆级安装详细教程
MySQL5.6简介 MySQL 5.6 是 MySQL 数据库管理系统的一个重要版本,以其稳定性.性能优化和功能扩充受到广泛关注与使用.该版本在数据库领域中提供了更加高效的数据处理能力.增强的复制功 ...
- HarmonyNEXT手动申请权限以及使用系统控件获取地址坐标的案例(区别)
一.手动申请位置权限 1.1.申请位置权限 申请ohos.permission.LOCATION.ohos.permission.APPROXIMATELY_LOCATION权限. "req ...
- Java虚拟机之垃圾回收器
上面有7类垃圾回收器,分为两块,上面为新生代(Young generation)回收器,下面是老年代(Tenured generation)回收器.如果两个回收器之间存在连线,就说明它们可以搭配使 ...
- Linux | base64编码与解码命令
1.base64编码 (1)base64 file 功能:从指定的文件file中读取数据,编码为base64的字符串然后输出: (2)echo "string" | base64 ...
- 全球首个无限执行的 AI 出现!给我玩爽了
给 AI 一句话,它就能自主执行任务,生成复杂的大型网站.几十页的 PPT.万字爆款图文.千万字长篇小说? 据说这是世界上第一款无限的 AI 智能体 -- Flowith. 无限这个词听起来有点东西啊 ...
- 基于语义检索的知识问答(RAG范式)
知识驱动型AI应用场景 知识驱动型AI应用场景式企业级AI智能体的常见抓手.该类型的场景能充分利用大语言模型的自然语言处理能力,相对独立的提供全新的用户体验.落地该场景,可以在有限的预算内大幅提升企业 ...
- Linux系统配置windows可访问的共享文件夹
一.简单说明 某些情况下,我们需要配置Linux系统的目录为共享文件夹,windows下可以直接访问.这里可以直接安装samba进行.(samba是一款软件,主要提供cifs协议,基于文件系统传输) ...