python 直方图每个bin中的值_Bin中心来自推荐的直方图函数 - Matlab(Bin centers from recommended histogram function - Matlab...

Bin中心来自推荐的直方图函数 - Matlab(Bin centers from recommended histogram function - Matlab)

Matlab现在建议使用直方图代替hist,但是不会像上一个函数那样显示找到bin中心的明显方法。

我当前的代码与hist函数一起正常工作:

数字

[counts171,position171] = hist(image171_reshaped,200);

图(position171,日志(counts171));

我如何能够转换这段代码,以便结合推荐的函数,如'histogram'或'histcounts'代替'hist',同时仍然获得bin中心?

Matlab now recommends to use the histogram in place of hist, however doesn't display an obvious way of finding the bin centers like the previous function.

My current code that works fine with the hist function:

figure

[counts171,position171] = hist(image171_reshaped,200);

plot(position171,log(counts171));

How would I be able to transform this piece of code in order to incorporate a recommended function such as 'histogram' or 'histcounts' in place of 'hist', while still obtaining the bin centers?

原文:https://stackoverflow.com/questions/40319993

更新时间:2019-10-21 14:10

最满意答案

histcounts返回边而不是bin中心,bin中心是边的连续元素之间的中点。 因此可以使用diff函数bin中心:

[counts171,edges171] = histcounts(image171_reshaped,200);

position171 = edges171(1:end-1) + diff(edges171) / 2;

histcounts returns edges instead of bin centers and bin centers are midpoints between consecutive elements of the edges. So using diff function bin centers can be obtained:

[counts171,edges171] = histcounts(image171_reshaped,200);

position171 = edges171(1:end-1) + diff(edges171) / 2;

2016-10-29

相关问答

注意:直方图L初始化括号不匹配。 删除代码中的第二个[括号。 此外, 0:255向量的创建不正确。 执行0:255'转换单个常量255,这意味着它仍将创建0:255的水平向量,这将使代码失败。 你应该用parantheses包围这个向量的创建,然后转置那个结果。 因此: L = [ (0:255)' zeros(256,1) ];

现在谈谈你的实际问题。 通过直方图的初始化来判断,有256个可能的值,因此您的输入最有可能是uint8类型,这意味着数据中的值将仅以[0-255]为步骤1.回想一下直

...

如果你查看histeq的文档,你会看到它接受一个可选的第二个参数,它是所需的直方图: J = histeq(I, hgram)变换强度图像I,使得具有length(hgram)区间的输出强度图像J的直方图大致匹配hgram 。 矢量hgram应包含等间隔二进制数的整数计数,其强度值在适当的范围内:对于类double的图像为[0,1],对于类uint8的图像为[0,255],对于图像为[0,65535] uint16 。 histeq自动缩放hgram使sum(hgram) = prod(size(

...

您感兴趣的操作称为线性对比拉伸 。 基本上,您想要将每个强度乘以某个增益,然后将强度移动一些数字,以便操纵直方图的动态范围。 这与histeq或者使用图像的概率密度函数(直方图均衡的先驱)来增强图像。 直方图均衡寻求将图像直方图变平,以便在图像中遇到的强度或多或少是等概率的。 如果你想对这个主题有更权威的解释,请看我关于直方图均衡化如何工作的答案: MATLAB中直方图均衡化功能的说明 无论如何,选择a和b的值是高度依赖于图像的。 然而,我可以建议,如果你想这是适应性的一件事是使用最小最大规范化

...

在计算直方图方面,每个强度的频率计算是正确的,尽管稍后会出现一些小错误。 另外,我会亲自避免在这里使用循环。 在这篇文章末尾看到我的小记。 不过,你的代码有三个问题: 问题#1 - 柱状图未正确初始化 histogram_values应该包含您的直方图,但您正在通过0:255的矢量初始化直方图。 每个强度值应以0开始计数 ,因此您实际上需要这样做: histogram_values = zeros(256,1);

问题#2 - for循环中的轻微错误 你的强度范围从0到255,但是MATLAB开

...

你可以使用另一个'新'功能: [y, x]=histcounts (x);

x=x(1:end-1)+diff(x/2)

那么你可以按照你的意愿对y进行标准化。 该函数也具有与直方图相同的标准化参数。 You may use another 'new' function: [y, x]=histcounts (x);

x=x(1:end-1)+diff(x/2)

Then you may normalize y as you wish. This function also has same

...

它有两个原因不起作用: 你应该通过你的门槛来获得一个整数 threshold = ceil(128/n);

i中的值是整数,这意味着除法在执行floor操作之前会自行舍入。 因此,您需要将其转换为double : im_level = floor( double(i(:)) / threshold);

There are 2 reasons it doesn't work: You should ceil your threshold to have a round number thresh

...

函数scatterhist创建三个轴。 将其称为h = scatterhist(...)给出1×3向量h其中包含这些轴的句柄。 您只需要删除第二个: h = scatterhist(...);

delete(h(2))

The function scatterhist creates three axes. Calling it as h = scatterhist(...) gives a 1×3 vector h with handles to those axes. You only ne

...

通过自我实现的功能回答我自己的问题: function h = fixedSizeBinnedHist(grayImg, numBins)

binSize = 256 / numBins;

binnedImg = floor(double(grayImg) / binSize);

maxVal = max(binnedImg(:));

numLeadingZeros = min(binnedImg(:));

numTrailingZeros

...

cumtrapz http://www.mathworks.com/help/techdoc/ref/cumtrapz.html 例: x = linspace(0, pi, 30);

y = cos(x);

yint = cumtrapz(x, y);

plot(x, yint, 'x');

hold on;

% exact integral

plot(x, sin(x), '-');

cumtrapz http://www.mathworks.com/help/techdoc/ref/cum

...

histcounts返回边而不是bin中心,bin中心是边的连续元素之间的中点。 因此可以使用diff函数bin中心: [counts171,edges171] = histcounts(image171_reshaped,200);

position171 = edges171(1:end-1) + diff(edges171) / 2;

histcounts returns edges instead of bin centers and bin centers are midpoints

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值