Finally nailed DIPAX's internal histogram^^
Machine-translated from Chinese. · Read original
This article is about the DIPAX image processing framework. For more information about this image processing framework, please refer to: http://www.fubo-tech.com/2-34.htm
I have always wanted to implement the cool histogram function of DIPAX, but I was busy with exams lately, so I had to put it on hold. Last night, I coded for a whole night and finally got the histogram function of DIPAX working :) I hope to get out of the novice state of VC++ soon~~
The specific code will be uploaded later, and 95% of it is basically the content from the “Black Magic Cube” book, so you can just copy it. Here are a few things that need attention:
1. The “Black Magic Cube” book is missing a function!
The evil Chen Bingqi didn’t give us an important function definition:
void CalHistPercent(long hist[256], float hist_radio[256], float &max_percent)
This function is only declared in the BaseList.h header file, but no specific function code is provided. So, if you don’t think carefully and just copy the content from the “Black Magic Cube” book, you will get an error during the linking process.
BTW: By the way, if there is an error during the linking process, it is likely because your function is not defined. Specifically, it is because the function name you wrote does not match the declaration in the
BaseList.hheader file.
However, after careful analysis, I found that this function is not very difficult. So, I wrote a fake version of the CalHistPercent function myself. It may not be very rigorous, but it works ~
2. XXX::OnPaint()
When I was reading the “Black Magic Cube” book, I didn’t understand what the OnPaint function corresponds to. Actually, the answer is very simple: OnPaint is just a button, and that button is called Paint 囧… So, you can change it to OnButton, OnSex, OnFUCK, or whatever you like, haha.
Sorry for my previous ignorance, OnPaint is not a button.
3. Printing errors
There are several printing errors in the “Black Magic Cube” book. For example, short ret is printed as shortret, and some comments are printed in the middle of statements… This caused me to have 31 errors when I built it for the first time… It really tests one’s patience.
But fortunately, I persevered and finally eliminated all the errors. The code that follows is error-free.
4. Where to draw?
You need to create a new static text box, and the ID corresponds to CWnd * pWnd = GetDlgItem(IDC_HIST_STATIC);. I used the ID IDC_HIST_STATIC written above.
5. Can the histogram be displayed as soon as the dialog box is entered?
Yes, you can put the display statement in the initialization function of the dialog box.
Finally, the class name of my histogram is called Czft.
All related code: https://github.com/quake0day/undergraduate-CAU/tree/master/zft
Appendix: Function definition:
void CalHistPercent(long hist[256], float hist_radio[256], float &max_percent)
#include "StdAfx.h"
#include "BaseList.h"
#include <math.h>
float cc(float a, float b)
{
return a / b;
}
void CalHistPercent(long hist[256], float hist_radio[256], float &max_percent)
{
int i, j;
long max_per = hist[0]; // Calculate the maximum value, with the first scanned point as the initial value
long all = 0; // The total number of pixels in the hist array
float a = 0;
for (i = 0; i < 256; i++)
{
all = hist[i] + all; // Calculate the total number of pixels in the hist array
}
for (j = 0; j < 256; j++)
{
if (all > 0) // If the number of pixels is greater than 0
{
hist_radio[j] = cc(hist[j], (float)all) * (float)100; // Calculate the percentage of each pixel point and save it in another array
}
if (max_per < hist[j])
{
max_per = hist[j]; // Calculate the maximum value
}
}
if (all != 0)
{
a = cc(max_per, all); // Calculate the maximum percentage
}
else
a = 0;
max_percent = a * (float)100;
}
还没有人留言,在下面说两句吧。