Community
cancel
Showing results for 
Search instead for 
Did you mean: 
royvm101
Beginner
88 Views

Is there an IPP bilateral filter for RGB image ? (3 channels)

It seems that the only bilateral filter available is the single channel (gray image) version, using
ippiFilterBilateral_8u_C1R
But the 3 channel version (color RGB image) is missing ?
( ippiFilterBilateral_8u_C3R seems to be missing )
How can I apply bilateral image on color image using Intel IPP ?
0 Kudos
4 Replies
igorastakhov
New Contributor II
88 Views

Just allocate P3 image, then copy your C3 image to P3 and apply bilateral filter to each plane - then you can copy back P3 to C3. Also, if you are limited in memory and, probably it will be faster approach (just because of the memory buffer reusing) - you can allocate C1 image and then perform 3 times copying C3C1->ippiFilterBilateral_8u_C1R -> copying C1C3:
1)
IPPAPI( Ipp8u*, ippiMalloc_8u_C1, ( int widthPixels, int heightPixels, int* pStepBytes ) ) - use 3*height here and calculate 3 pointers to P planes: P[0] == initilalpointer after allocation, P[1] = P[0] + height * stepBytes, P[2] = P[1] + height * step Bytes

then do the same for Dst
IPPAPI ( IppStatus, ippiCopy_8u_C3P3R, ( const Ipp8u* pSrc, int srcStep, Ipp8u* const pDst[3], int dstStep, IppiSize roiSize ))
then 3 times for each P[]:
IPPAPI(IppStatus,ippiFilterBilateral_8u_C1R,( const Ipp8u *pSrc, int srcStep, Ipp8u *pDst, int dstStep, IppiSize dstRoiSize, IppiSize kernelSize, IppiFilterBilateralSpec *pSpec))
and finally
IPPAPI ( IppStatus, ippiCopy_8u_P3C3R, (const Ipp8u* const pSrc[3], int srcStep, Ipp8u* pDst, int dstStep, IppiSize roiSize ))
2) think better from the performance point of view:
IPPAPI( Ipp8u*, ippiMalloc_8u_C1, ( int widthPixels, int heightPixels, int* pStepBytes ) ) - 2 times - for src & dst, or better 1 time but 2x height and use the same formula as for p[1] for temporal dst buffer pointer

then 3 times (for pSrc, pSrc+1 and pSrc+2, and for pDst, pDst+1 and pDst+2 for final copy):
IPPAPI( IppStatus, ippiCopy_8u_C3C1R,( const Ipp8u* pSrc, int srcStep,Ipp8u* pDst, int dstStep, IppiSize roiSize ))
IPPAPI(IppStatus,ippiFilterBilateral_8u_C1R,( const Ipp8u *pSrc, int srcStep, Ipp8u *pDst, int dstStep, IppiSize dstRoiSize, IppiSize kernelSize, IppiFilterBilateralSpec *pSpec))

IPPAPI( IppStatus, ippiCopy_8u_C1C3R, ( const Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep, IppiSize roiSize ))
and this approach should be faster than C3 Bilateral filtering of C3 image

Regards,
Igor

royvm101
Beginner
88 Views

Dear Igor,

Thank you very much for the detailed reply. I will try to implement the method you suggested.

I have one major concern, which relates to the fact that applying bilateral filter to each plane separately is ALGORITHMICALLY different than applying the filter to all planes simultaneously.
This is because each pixel value is averaged with its neighbors such that the averaging weight of the pixel with a neighbor depends on the color difference between the pixel color and the neighbor color, wherein the difference is measured in all 3 color bands simultaneously.

Lets examine the case of averaging the green component of a pixel with a neighbor which have a similar green level but very different red level.
1) If we filter each plane separately, then the neighbor will get high weight during the averaging because the green levels of the pixel and the neighbor are close.
2) If we filter all planes simultaneously, then the neighbor will get a lower weight during the averaging because even though the green channels of the pixel and the neighbor are close in value, the red levels are very different, and therefore the total RGB color (or LAB color) will have a large difference.

I assume from your response that an IPP function which calculates bilateral filter for 3 bands color image is not available, so I will try your method of averaging each plane separately, and hopefully results will not differ too much.

Thanks,
Roy
igorastakhov
New Contributor II
88 Views

Hi Roy,

this is the way all filters in ippIP are implemented - for C3/C4/AC4 images all channels are filtered independently

Regards,
Igor
royvm101
Beginner
88 Views

Hi Igor,

I implemented both the IPP version which filters each channel independently, and the OpenCV 3.2.1 bilateral filter which measures color distances on all 3 bands (RGB) simultaneously.

1) Color conversion from RGB to LAB seems much faster with IPP than with OpenCV.

2) IPP bilateral filter is faster with IPP than with OpenCV. but, the result of OpenCV seems better (my subjective opinion). This is probably because OpenCV uses 3-band color distances, and not separate distance for each band. Also, it seems that OpenCV implements the distance by taking abs(R1-R2)+abs(G1-G2)+abs(B1-B2) which might give more moderate decrease in averaging weight as the color distance increases , when compared to using the square distance.

Hope Intel will develop someday a multi-channel color distance based IPP bilateral filter !

B.R.
Roy

Reply