Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 .....
Posted
Comments
Resmi Anna 21-Mar-12 8:12am    
are you coding in c++ using Open CV?
PixelIndia 21-Mar-12 9:31am    
@Resmi Anna ....
i am coding in c++; but i am not interested in using OpenCV (no third party libs).. trying to write my own code for Hist(:)

Jochen Arndt 21-Mar-12 9:50am    
Even then open source libs like OpenCV and ImageMagick are good starting points. When asking here, most (if not all) answers will point you to some kind of existing code. If you want to do it yourself without (re-)using existing code, you must know the mathematics of histograms.
merano 21-Mar-12 15:23pm    
The C++ Language does not include Graphics. If you want to code this Functions you have to use System-Calls or a Library that covers this.
When you do not want to use " third party libs" you have to use System-Calls or Librarys that come with the Development Environment. If you use Windows with Visual-Studio you could use GDI for Example, for Unix you have to go other ways.
Maximilien 21-Mar-12 8:23am    
what does that mathlab function do?

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900