- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I'm trying to get an image sharpening function with parameters working (apart from the fixed FilterSharpen call). I can't figure out why the code is bombing at the ippiConvFull_32f call below.
1. Could some kind soul please look over the routine below and see if anything is amiss?
2. Does the function look like it is properly constructed to perform sharpening? The end goal is to have a sharpen function with variable strength...
BOOL IppImageConvolutionSharpen_24bit(BYTE *pImageP, UINT32 uWidth, UINT32 uHeight, UINT32 uComponentsPerPixel, UINT32 uInRowStride,
BYTE *pOut, UINT32 uOutRowStride,
double radiusBlur /* 1.0*/
)
{
IppImage32f scratch, input32f;
IppStatus retval;
IppImage32f krnl;
int border=6;
IppiSize dims;
Ipp32f eval[3];
int i, j;
char strDebug[80];
double f1, f2, f3;
dims.height = uHeight;
dims.width = uWidth;
// create temporary 32f version of input data
input32f = MakeIppImage_32f_C3(uWidth, uHeight);
ippiConvert_8u32f_C3R(pImageP, uInRowStride, input32f.pixels, input32f.StepBytes, dims);
// Make sharpen matrix
// This code doesn't work for unsigned data.
krnl = MakeIppImage_32f_C3(3,3);
eval[0] = eval[1] = eval[2] = (-1.0/8.0);
ippiSet_32f_C3R((const Ipp32f *)eval, krnl.pixels, krnl.StepBytes, krnl.dims);
_ippiSetR_32f(krnl, 1, 1, 2.0);
_ippiSetG_32f(krnl, 1, 1, 2.0);
_ippiSetB_32f(krnl, 1, 1, 2.0);
// Add border to image
scratch=MakeIppImage_32f_C3(dims.width + 2 * border, dims.height + 2 * border);
retval=ippiCopyReplicateBorder_32f_C3R((const Ipp32f *)input32f.pixels, input32f.StepBytes, dims,
(Ipp32f *)scratch.pixels, scratch.StepBytes, scratch.dims,
border, border);
if(retval!=ippStsNoErr)
{ MessageBox(GetFocus(), "IppImageConvolutionSharpen_24bit: ippiCopyReplicateBorder_32f_C3R failed", "IppImageConvolutionSharpen_24bit", MB_OK);
return 0;
}
// apply filter
retval = ippiConvFull_32f_C3R(
&scratch.pixels[scratch.StepBytes/sizeof(Ipp32f) * border + border * 3], scratch.StepBytes, dims,//scratch.dims,
krnl.pixels, krnl.StepBytes, krnl.dims,
input32f.pixels, input32f.StepBytes);
if(retval!=ippStsNoErr)
{ MessageBox(GetFocus(), "IppImageConvolutionSharpen_24bit: ippiConvFull_32f_C3R failed", "IppImageConvolutionSharpen_24bit", MB_OK);
return 0;
}
// convert results from 32f back to 8u
ippiConvert_32f8u_C3R(input32f.pixels, input32f.StepBytes, pOut, uOutRowStride, dims, ippRndNear);
// cleanup
DeleteIppImage_32f_C3(scratch);
DeleteIppImage_32f_C3(krnl);
DeleteIppImage_32f_C3(input32f);
return TRUE;
}
Thanks!
1. Could some kind soul please look over the routine below and see if anything is amiss?
2. Does the function look like it is properly constructed to perform sharpening? The end goal is to have a sharpen function with variable strength...
BOOL IppImageConvolutionSharpen_24bit(BYTE *pImageP, UINT32 uWidth, UINT32 uHeight, UINT32 uComponentsPerPixel, UINT32 uInRowStride,
BYTE *pOut, UINT32 uOutRowStride,
double radiusBlur /* 1.0*/
)
{
IppImage32f scratch, input32f;
IppStatus retval;
IppImage32f krnl;
int border=6;
IppiSize dims;
Ipp32f eval[3];
int i, j;
char strDebug[80];
double f1, f2, f3;
dims.height = uHeight;
dims.width = uWidth;
// create temporary 32f version of input data
input32f = MakeIppImage_32f_C3(uWidth, uHeight);
ippiConvert_8u32f_C3R(pImageP, uInRowStride, input32f.pixels, input32f.StepBytes, dims);
// Make sharpen matrix
// This code doesn't work for unsigned data.
krnl = MakeIppImage_32f_C3(3,3);
eval[0] = eval[1] = eval[2] = (-1.0/8.0);
ippiSet_32f_C3R((const Ipp32f *)eval, krnl.pixels, krnl.StepBytes, krnl.dims);
_ippiSetR_32f(krnl, 1, 1, 2.0);
_ippiSetG_32f(krnl, 1, 1, 2.0);
_ippiSetB_32f(krnl, 1, 1, 2.0);
// Add border to image
scratch=MakeIppImage_32f_C3(dims.width + 2 * border, dims.height + 2 * border);
retval=ippiCopyReplicateBorder_32f_C3R((const Ipp32f *)input32f.pixels, input32f.StepBytes, dims,
(Ipp32f *)scratch.pixels, scratch.StepBytes, scratch.dims,
border, border);
if(retval!=ippStsNoErr)
{ MessageBox(GetFocus(), "IppImageConvolutionSharpen_24bit: ippiCopyReplicateBorder_32f_C3R failed", "IppImageConvolutionSharpen_24bit", MB_OK);
return 0;
}
// apply filter
retval = ippiConvFull_32f_C3R(
&scratch.pixels[scratch.StepBytes/sizeof(Ipp32f) * border + border * 3], scratch.StepBytes, dims,//scratch.dims,
krnl.pixels, krnl.StepBytes, krnl.dims,
input32f.pixels, input32f.StepBytes);
if(retval!=ippStsNoErr)
{ MessageBox(GetFocus(), "IppImageConvolutionSharpen_24bit: ippiConvFull_32f_C3R failed", "IppImageConvolutionSharpen_24bit", MB_OK);
return 0;
}
// convert results from 32f back to 8u
ippiConvert_32f8u_C3R(input32f.pixels, input32f.StepBytes, pOut, uOutRowStride, dims, ippRndNear);
// cleanup
DeleteIppImage_32f_C3(scratch);
DeleteIppImage_32f_C3(krnl);
DeleteIppImage_32f_C3(input32f);
return TRUE;
}
Thanks!
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Westminster,
You take care of almost all of things for filter:image size, rowStrides, image border, components.About failedat the function
// apply filter
retval = ippiConvFull_32f_C3R(
&scratch.pixels[scratch.StepBytes/sizeof(Ipp32f) * border + border * 3], scratch.StepBytes, dims,//scratch.dims,
krnl.pixels, krnl.StepBytes, krnl.dims,
input32f.pixels, input32f.StepBytes);
I guess, it is because the size of your filter result image ( input32f) is not expected.
let's assume youroriginalimage pImageP is 100x20, thus the input32f is 100x20 32f image.
your kernal image is 3x3 32f image
Srcath image is your temp image with border (6), it is 100+2x6, 20+2x6 112x32 32f image.
according to your input, (here enter dim is right than scratch.dims) and the ConvFull Result should be
Mh = Mf + Mg - 1 and Nh = Nf + Ng - 1, youwillget adim (100x20)+ kernal(3x3)-1 = 102x22 image.
But the image input32 is only 100x20. So the memory access will invalid.
If you want to the result is100x20, then you may considerchange the parameter dim,setroiDim=98x18.
But why youperfer touse ippiConvFulto implement the filter?Besides the functionippiFilterShapen, there are general filter functions such as ippiFilter_32f_C3R()/ippiFilter32f_8u_C3R () and so on. The functions allow youto set anykernal and kernal size, dst size.You may check them in ipp manual ippiman.pdf and see if they can meet your request.
Here is KB talking about ippiFilter for your reference
http://software.intel.com/en-us/articles/intel-integrated-performance-primitives-intel-ipp-processing-an-image-from-edge-to-edge/
Regards,
Ying
![](/skins/images/B7BA37F9CE4B52FF7CAE1FB0388839C8/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page