不使用hist()Matlab的灰度标准化直方图 [英] grayscale normalized histogram without using hist() Matlab

查看:410
本文介绍了不使用hist()Matlab的灰度标准化直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入:[0..255]中的灰度img


输出:img直方图归一化 - 数组1X256除以总数像素

Input: a grayscale img in [0..255]
Output: img histogram normalized - an array 1X256 divided by total number of pixels

这是我的解决方案:

function [h] = histImage(img)
    h=zeros(1,256)
    for i=1:size(h,2)
       h(i) = length(find(img==i));
    end
    h = h./sum(h);

有更好的方法吗?

推荐答案

更好总是在旁观者的眼中。无论如何,这是使用 accumarray 进行上述操作的方法:

"Better" is always in the eye of the beholder. Anyway, here's a way to do the above using accumarray:

%# each pixel contributes 1/nPixels to the counts of the histogram
%# to use graylevels as indices, we have to add 1 to make it 1...256

nPix = numel(img);
h = accumarray(img(:)+1,ones(nPix,1)/nPix,[256 1],@sum,0);

这篇关于不使用hist()Matlab的灰度标准化直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆