# calculate Dynamic range of an Image

How to calculate Dynamic range of an Image using Opencv? What is the value of good dynamic range?

edit retag close merge delete

Sort by » oldest newest most voted You can compute dynamic range by below code.

void bhCalcHist(const IplImage* srcImage,CvMat* hist,const IplImage* maskImage)
{
float* pHist = hist->data.fl;
for (int i=0; i < 256;i++)
pHist[i] = 0;

{
for (int i=0; i < srcImage->height;i++)
{
byte* srcP = (byte*) srcImage->imageData + srcImage->widthStep * i;
for (int j=0; j < srcImage->width;j++)
{
pHist[srcP[j]]++;
}

}
}
else
{
for (int i=0; i < srcImage->height;i++)
{
byte* srcP = (byte*) srcImage->imageData + srcImage->widthStep * i;
for (int j=0; j < srcImage->width;j++)
{
pHist[srcP[j]]++;
}

}
}
}

CvMat* bhGetHist(const IplImage* srcImage,const IplImage* maskImage)
{
CvMat* resultHist = cvCreateMat(1,256,CV_32FC1);
return resultHist;
}

void  bhGetDynamicRange2(const IplImage* srcImage,const IplImage* maskImage, float lowPercent,float highPercent,unsigned char& minRange,unsigned char& maxRange )
{

float* pHist = hist->data.fl;
int totalCount;
else totalCount = srcImage->width * srcImage->height;

int lowPercentCount = cvRound( totalCount * lowPercent /100);
int highPercentCount = cvRound( totalCount * highPercent /100);

int minRng = 0;
float curCount = 0;
int size = 256;

while ((minRng < size) && (curCount < lowPercentCount))
{
curCount += (pHist[minRng]<0)?0:pHist[minRng];
minRng++;
}

int maxRng = size-1;

curCount = 0;
while ((maxRng >= 0) && (curCount < highPercentCount))
{
curCount += (pHist[maxRng]<0)?0:pHist[maxRng];
maxRng--;
}
if (minRng > maxRng)
{
minRng = maxRng;
}

minRange = minRng;
maxRange = maxRng;

cvReleaseMat(&hist);

}

int main ()
{
unsigned char minRng ;
unsigned char maxRng ;

return 0;
}

more more

Official site

GitHub

Wiki

Documentation