Hist(),将Matlab代码转换为C ++吗? [英] Hist() , conversion of Matlab code to C++ ?
本文介绍了Hist(),将Matlab代码转换为C ++吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
到底如何我们可以为Matlab函数编写C ++代码
(hist(IpImage),NumberofBins);
例如:hist(IPImage(),100);
请帮帮我;或清楚地向我解释如何在C ++中实现?
从哪里开始,基本上是灰度图像..
建议.....
Hi people,
How exactly; can we write c++ code for the Matlab function
( hist(IpImage), NumberofBins) ;
Ex: hist(IPImage(),100);
Please help me out; or explain me clearly how to implement in C++?
where to start, basically its a gray scale image..
Suggestions pls .....
推荐答案
对于简单的灰度图像,相对容易生成直方图.当然,确切的代码取决于图像的内存结构.假设您将其保存在一个宽x高字节的缓冲区中,其名称为pf pBuffer.有时,图像线的末尾会被填充;因此变量lineWidth应该包含每个图像行的填充大小.
代码如下所示:
For a simple gray scale image it is relatively easy to produce the histogram. The exact code of course depends on the in-memory structure of your image. Let''s assume you have it in a buffer of width x height bytes by the name pf pBuffer. Sometimes image lines are padded at the end; therefore the variable lineWidth should contain the padded size of each image line.
The code would look like:
unsigned int histo [256];
memset (histo, 0, sizeof histo);
for (int y = 0; y < height; ++y)
{
BYTE* p = pBuffer + y * lineWidth;
for (int x = 0; x < width; ++x)
histo[*p++] += 1;
}
// now the array hist will contain the histogram of the image.
各种不同的图像格式带来了更多的复杂性.但是主体保持不变.
More complexity comes in with the variety of different image formats. But the principal stays the same.
这篇关于Hist(),将Matlab代码转换为C ++吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文