#pragma once #include "afx.h" namespace OTSIMGPROC { enum GrayPeakType { leftBias = 1, peakInMiddle=2, rightBias=3, normalPeak=4, smallPeak=5 }; class MyGreyPeak { public: int start; int end; int peakPos; int peakValue; int valleyValue; int allNoneZeroGreyLevelNum;//valid grey level number int maxPeakvalue;//max peak of all the peak long area; MyGreyPeak* nextRng; MyGreyPeak* preRng; int GetSpan() { return end - start; } int GetDvalue() { return peakValue - valleyValue; } GrayPeakType GetPeakType() { GrayPeakType peakType;//1:left bias 2:peak in middle 3:right bias.4:big peak,5:small peak double leftBias = peakPos - start; double rightBias = end - peakPos; double proportion = leftBias / rightBias; double dvalue = (double)GetDvalue(); double span = (double)GetSpan(); double spanProportion = span / allNoneZeroGreyLevelNum; double dpeak = peakValue; double peakProportion = dpeak / maxPeakvalue; double dvalueProportion = dvalue / maxPeakvalue; if (nextRng == NULL) { peakType=GrayPeakType::normalPeak; } if (peakProportion < 0.1 && spanProportion < 0.05) { peakType = GrayPeakType::smallPeak; } if (proportion > 0.66 && rightBias <= 1) { peakType =GrayPeakType::rightBias; } else if (proportion < 0.33 && leftBias <= 1) { peakType = GrayPeakType::leftBias; } else { peakType = GrayPeakType::peakInMiddle; } if (dvalueProportion >= 0.1 && peakType == 2) { peakType=GrayPeakType::normalPeak; } if (spanProportion >= 0.1 && peakType == 2) { peakType=GrayPeakType::normalPeak; } return peakType; } void MergePeak(MyGreyPeak* curRange)//merge the invalid range into adjacent range. { area += curRange->area; if (curRange->peakValue > peakValue) { peakValue = curRange->peakValue; peakPos = curRange->peakPos; } if (curRange->valleyValue < valleyValue) { valleyValue = curRange->valleyValue; } if (curRange->end > end)//curRange is on the right of this range. { end = curRange->end; nextRng = curRange->nextRng; if (nextRng != NULL) { nextRng->preRng = this; } delete curRange; } else//curRange is on the left of this range. { start = curRange->start; preRng = curRange->preRng; if (preRng != NULL) { preRng->nextRng = curRange->nextRng; } delete curRange; } } static BOOL MergeGreyPeaks(MyGreyPeak* firstRng, MyGreyPeak*& resultFirstRng); }; }