- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Kadir,
find a histogram and take the central value of it (median = histogram[histogram.length /2])
sorry:
find a histogram, sort histogram index by value and take level with mean histogram index, example in c#:
*****
IppiSize roi_size = new IppiSize(Width, Height);
byte tmp_max = 0;
byte tmp_min = 0;
ippiMinMax_8u_C1R((byte*)data, Stride, roi_size, &tmp_min, &tmp_max);
min = tmp_min;
max = tmp_max;
int[] hist = new int[tmp_max - tmp_min + 1];
int[] levels = new int[hist.Length + 1];
fixed (int* phist = &hist[0], plevels = &levels[0])
{
ippiHistogramEven_8u_C1R((byte*)data, Stride, roi_size, phist, plevels, levels.Length, tmp_min, tmp_max + 1);
}
int[] tmp = Array.Sort(levels);
int median = tmp[tmp.Length / 2];
Array.Sort(levels, hist);
int median = levels[levels.Length / 2];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ipp32f *pSrcSort = ippsMalloc_32f(len);
ippsCopy_32f(pSrc, pSrcSort, len);
ippsAbs_32f_I(pSrcSort, len);
ippsSortAscend_32f_I(pSrcSort);
Ipp32f medVal = pSrcSort[len/2];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
and another problem may be happened, if image has the aligned allocation in the memory, then it will be wrong result...
for small images like width * height < 256 your code ispreferable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the last two line of code is not correct, as i thought
Array.Sort(levels, hist);
int median = levels[levels.Length / 2];
It should be found the first index of integral amplitude which has intersection with Width*Height/2 value:
int a = 0;
int center = Width * Height / 2;
for(int i = 0; i < hist.Length; i++)
{
a += hist;
if (a >= center)
{
median = level;
break;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ipp32f *pSrcSort = ippsMalloc_32f(len);
ippsCopy_32f(pSrc, pSrcSort, len);
ippsAbs_32f_I(pSrcSort, len);
ippsSortAscend_32f_I(pSrcSort);
Ipp32f medVal = pSrcSort[len/2];
yes, that is what i did mean, the IPP use a 32-bytes boundary, but if you change the function ippsCopy_<> to ippiCopy_<> it will be OK. Is the pixel of image the float value? Why you use the ippsAbs_32f_I(pSrcSort, len)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ipp32f *pSrcSort = ippsMalloc_32f(len);
ippsCopy_32f(pSrc, pSrcSort, len);
ippsAbs_32f_I(pSrcSort, len);
ippsSortAscend_32f_I(pSrcSort);
Ipp32f medVal = pSrcSort[len/2];
yes, that is what i did mean, the IPP use a 32-bytes boundary, but if you change the function ippsCopy_<> to ippiCopy_<> it will be OK. Is the pixel of image the float value? Why you use the ippsAbs_32f_I(pSrcSort, len)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
to make the negative signed values positive, I use the ippsAbs function ..
I don't know the background of the task, but in this case the result can be wrong. If you need to get a real median value, you shouldn't use the ippsAbs function.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page