什么是Histogramming

Histogramming是一种从大的数据集中提取典型特征和模式的方式.

在统计学中,直方图(英语:Histogram)是一种对数据分布情况的图形表示,是一种二维统计图表,它的两个坐标分别是统计样本和该样本对应的某个属性的度量。

图像直方图(英语:Image Histogram)是用以表示数字图像中亮度分布的直方图,标绘了图像中每个亮度值的像素数。可以借助观察该直方图了解需要如何调整亮度分布。这种直方图中,横坐标的左侧为纯黑、较暗的区域,而右侧为较亮、纯白的区域。因此,一张较暗图片的图像直方图中的数据多集中于左侧和中间部分;而整体明亮、只有少量阴影的图像则相反。

很多数码相机提供图像直方图功能,拍摄者可以通过观察图像直方图了解到当前图像是否过分曝光或者曝光不足。

计算机视觉领域常借助图像直方图来实现图像的二值化。

颜色直方图

在图像处理和摄影领域中,颜色直方图(英语:Color Histogram)指图像中颜色分布的图形表示。数字图像的颜色直方图覆盖该图像的整个色彩空间,标绘各个颜色区间中的像素数。

颜色直方图本身可以针对任意色彩空间使用,但这一术语通常只用在诸如 RGB 和 HSV 的三维色彩空间,而针对灰度图像时常使用亮度直方图(英语:Intensity Histogram)这一术语。

直方图例子

比如一个句子"Programming Massively Parallel Processors",我们构建一个字母出现频率的直方图.

A(4次), C(1), E(1), G(1), ...

Host端我们做统计的话,就会构建26大小的数组来表示a-z,然后遍历这个句子,碰到不同的case进行累加操作.

Device端并行化: 把这个sentense 划分成多个block,每个block统计自己的情况,同意保存到一个数组里面.

但是当两个thread同事在对A做+1的动作后,最后的结果是1,而正确的结果是2才对,这时候需要使用原子加操作:
unsigned int atomicAdd(unsigned int* address, unsigned int val);

其实在CUDA的device中执行计数的功能都需要使用原子操作才行.

优化histor kernel代码:

不使用shared memory的情况下,执行原子操作,无论有多少个thread,在这个例子中最多同时执行的只有256,其他的都因为原子操作需要等待, 所以这里每个thread block使用一个 shared memory,  统计每个thread block,然后最后一起copy 给 histo

__global__ void histo_kernel(unsigned char *buffer, long size, unsigned int *histo)
{
__shared__ unsigned int histo_private[];
if(threadId.x < ) //初始化shared histo
histo_private[threadIdx.x] = ;
__syncthread(); int i = threadIdx.x + blockIdx.x * blockDim.x;
// 步长是所有threads的数目
int stride = blockDim.x * gridDim.x;
while(i < size) {
atomicAdd(&(private_histo[buffer[i]]), );
i + = stride;
} //等待所有线程执行完
__syncthreads(); if(threadIdx.x < ){
atomicAdd(&(histo[threadIdx.x]), private_histo[threadIdx.x]);
}
}

5.2 CUDA Histogram直方图的更多相关文章

  1. [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  2. LeetCode: Largest Rectangle in Histogram(直方图最大面积)

    http://blog.csdn.net/abcbc/article/details/8943485 具体的题目描述为: Given n non-negative integers represent ...

  3. Elasticsearch聚合 之 Histogram 直方图聚合

    Elasticsearch支持最直方图聚合,它在数字字段自动创建桶,并会扫描全部文档,把文档放入相应的桶中.这个数字字段既可以是文档中的某个字段,也可以通过脚本创建得出的. 桶的筛选规则 举个例子,有 ...

  4. [leetcode]84. Largest Rectangle in Histogram直方图中的最大矩形

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  5. [LeetCode] 84. Largest Rectangle in Histogram 直方图中最大的矩形

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  6. LeetCode 84. Largest Rectangle in Histogram 直方图里的最大长方形

    原题 Given n non-negative integers representing the histogram's bar height where the width of each bar ...

  7. 【LeetCode】84. Largest Rectangle in Histogram——直方图最大面积

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  8. CUDA 进阶学习

    CUDA基本概念 CUDA网格限制 1.2CPU和GPU的设计区别 2.1CUDA-Thread 2.2CUDA-Memory(存储)和bank-conflict 2.3CUDA矩阵乘法 3.1 全局 ...

  9. matplotlib 直方图

    一.特点 数据必须是原始数据不能经过处理,数据连续型,显示一组或多组分布数据 histogram 直方图 normed 定额 二.核心 hist(x, bins=None, normed=None) ...

随机推荐

  1. uva 348

    dp还是比较容易  关键是输出路径 .... #include <cstdlib> #include <cstdio> #include <cstring> #de ...

  2. cf 320B

    数据量小  dfs水过 #include <iostream> #include <cstdio> #include <cstring> using namespa ...

  3. 安装ADT Cannot complete the install because one or more required items could not be found.

    点击进行安装,将会弹出 错误提示是: Cannot complete the install because one or more required items could not be found ...

  4. linux下使用yum安装mysql、tomcat、httpd

    一.linux下使用yum安装mysql   1.安装 查看有没有安装过:           yum list installed mysql*           rpm -qa | grep m ...

  5. Qt xcode wrapper Qios OpenFly

    https://github.com/richardmg/QtWrapper https://github.com/richardmg/qios https://github.com/richardm ...

  6. adb开启不了解决方案

    原文地址: adb开启不了解决方案 - vaecer - 博客频道 - CSDN.NET http://blog.csdn.net/vaecer/article/details/45894643   ...

  7. How to change data dir of mysql?

    # 1 copy orgin data dir of mysql to new one cp -R /var/lib/mysql /mysqldata chown mysql:mysql -R /my ...

  8. Java之Comparable接口和Comparator接口

    Comparable & Comparator 都是用来实现集合中元素的比较.排序的: Comparable 是在集合内部定义的方法实现的排序: Comparator 是在集合外部实现的排序: ...

  9. 大四实习准备5_android广播机制

    2015-5-1 android 广播机制 5.1简介 分为标准广播(Normal broadcasts)(无先后顺序,几乎同时接收,不可截断)和有序广播(Ordered broadcasts)(有先 ...

  10. [swustoj 1094] 中位数

    中位数(1094) 问题描述 中位数(又称中值,英语:Median),统计学中的专有名词,代表一个样本.种群或概率分布中的一个数值,其可将数值集合划分为相等的上下两部分.对于有限的数集,可以通过把所有 ...