Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
5 Views

Need some help with gauss filter

I am using UIC to load a bitmap to be manipulated and then written out.
Code:
[cpp]using namespace UIC; int loadBMP(const char* inFile, Ipp8u** memBuffer, Image& image, ImageColorSpec& colorSpec, ImageSamplingGeometry& geometry, int& lineStep, int& pixelStep, int& numComponent) { CStdFileInput fin; if(!BaseStream::IsOk(fin.Open(inFile))) return 1; ImageDataPtr dataPtr; ImageDataOrder dataOrder; BMPDecoder decoder; ExcStatus status; status = decoder.Init(); if(ExcStatusOk != status) { return 1; } status = decoder.AttachStream(fin); if(ExcStatusOk != status) { return 1; } status = decoder.ReadHeader(colorSpec, geometry); if(ExcStatusOk != status) { return 1; } numComponent = geometry.NOfComponents(); // set data type = 8 unsigned dataOrder.SetDataType(T8u); // set to interleaved data order dataOrder.ReAlloc(Interleaved, numComponent); // byte steps for pixel alignment i.e. for interleaved = 3 bytes for 1 byte per component RGB pixelStep = numComponent; dataOrder.PixelStep()[0] = numComponent; lineStep = geometry.RefGridRect().Width() * numComponent; // byte steps for img alignment dataOrder.LineStep()[0] = lineStep; image.ColorSpec().ReAlloc(numComponent); image.ColorSpec().SetColorSpecMethod(Enumerated); image.ColorSpec().SetComponentToColorMap(Direct); // not using pallette for(int i = 0; i < numComponent; i++) { image.ColorSpec().DataRange().SetAsRange8u(255); } image.ColorSpec().SetEnumColorSpace(BGR); // alloc memory *memBuffer = (Ipp8u*)ippMalloc(dataOrder.LineStep()[0] * geometry.RefGridRect().Width()); dataPtr.p8u = *memBuffer; image.Buffer().Attach(&dataPtr, dataOrder, geometry); status = decoder.ReadData(image.Buffer().DataPtr(), dataOrder); if(ExcStatusOk != status) { return 1; } //decoder.DetachStream(); return 0; } int writeBMP(const char* outFile, Image& image) { // write out BMPEncoder bmpEncoder; CStdFileOutput fo; ExcStatus status; if(!BaseStream::IsOk(fo.Open(outFile))) return 1; status = bmpEncoder.Init(); if(status != ExcStatusOk) return 1; status = bmpEncoder.AttachStream(fo); if(status != ExcStatusOk) return 1; status = bmpEncoder.AttachImage(image); if(status != ExcStatusOk) return 1; status = bmpEncoder.WriteHeader(); if(status != ExcStatusOk) return 1; status = bmpEncoder.WriteData(); if(status != ExcStatusOk) return 1; /*bmpEncoder.DetachImage(); bmpEncoder.DetachStream();*/ return 0; } IppStatus blur(Image& image, Ipp8u* mem, int lineStep, int width, int height) { IppStatus status; IppiSize roi; roi.width = width; roi.height = height; // copy out the memory from image Ipp8u* work = (Ipp8u*)ippMalloc(width * height * 3); status = ippiCopy_8u_C3R(image.Buffer().DataPtr()->p8u, lineStep, work, lineStep, roi); IppiSize extRoi; extRoi.width = width + 2; extRoi.height = height + 2; int extStep; Ipp8u* extWork = ippiMalloc_8u_C3(width + 2, height + 2, &extStep); Ipp8u* startPt = extWork + extStep + 3; // copy over from work to extWork status = ippiCopy_8u_C3R(work, lineStep, startPt, extStep, roi); status = ippiCopyReplicateBorder_8u_C3IR(startPt, extStep, roi, extRoi, 1, 1); status = ippiFilterGauss_8u_C3R(extWork, extStep, work, lineStep, roi, ippMskSize3x3); // copy work back in status = ippiCopy_8u_C3R(work, lineStep, image.Buffer().DataPtr()->p8u, lineStep, roi); ippiFree(work); ippiFree(extWork); return status; } int main() { char* inFileName = "c:\\test.bmp"; char* outFileName = "c:\\test_out.bmp"; Ipp8u* imgMemory = NULL; Image image; ImageSamplingGeometry geometry; ImageColorSpec colorSpec; int lineStep, pixelStep, numComponent; int status = loadBMP(inFileName, &imgMemory, image, colorSpec, geometry, lineStep, pixelStep, numComponent); if(status != 0) { return 1; } int w = geometry.RefGridRect().Width(); int h = geometry.RefGridRect().Height(); IppStatus stat = blur(image, imgMemory, lineStep, w, h); writeBMP(outFileName, image); ippiFree(imgMemory); return 0; } [/cpp]
Problems:
1. Program seems to randomly crash at ippiFilterGauss -Unhandled exception at 0x02cd53b0 in ipptest.exe: 0xC0000005: Access violation reading location 0x0108f6bd. Not sure what is causing this?
2. When the program runs without crashing, the filtered output is slightly shifted diagonally to the lower right. This happens with:
[cpp]Ipp8u* startPt = extWork + extStep + 3;[/cpp] But no shifting problem with this:
[cpp]Ipp8u* startPt = extWork;[/cpp] I was under the impression based on the samples that I need to shift the start pointer by 1 pixel down and 1 pixel to the right to work correctly with the extended image: 1 line down (+ extStep), 1 pixel to the right (3 as RGB). Or did I get it wrong?
Edit: IPP v7, Windows7
0 Kudos
1 Reply
Highlighted
Employee
5 Views

Hi,

By quickly checking the code, for 3x3 kernal, shoud it shift 1 column and 1 row? like the following:
Ipp8u* startPt = extWork + extStep + 1

Thanks,
Chao
0 Kudos