Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
公告
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.

ippiCanny Example/help?

androoy
初学者
3,845 次查看
I am trying to get the canny edge detector to work on an image that I have initialized. I tried running the example code under the documentation for the edge detector, but I my resulting image/array is always completely full of the exact same value, "205".

Here is the code, I believe my problem may be related to the ippMsk, dx, dy, or buffer. I'm not exactly sure what the ippmsk, dx, and dy are doing - any explanation for those would be helpful as well. Again, this code is almost completely from the example in the documentation.


int main(array<:STRING> ^args)
{
int size1;
int size2;
ptr1 = new Ipp16u[1392*1024];
ptr2 = new Ipp8u[1392*1024];
Ipp8u *buffer;
Ipp16s *dx, *dy;
dx = new Ipp16s[1392*1024];
dy = new Ipp16s[1392*1024];
readVals();
testMethod();
sts = ippiFilterSobelHorizGetBufferSize_8u16s_C1R(imgSize, ippMskSize3x3, &size1);
sts = ippiFilterSobelHorizGetBufferSize_8u16s_C1R(imgSize, ippMskSize3x3, &size2);
if(size1
size1 = size2;
}
ippiCannyGetSize(imgSize, &size2);
if(size1 < size2) {
size1=size2;
}
buffer = new Ipp8u[size1];
sts = ippiFilterSobelNegVertBorder_8u16s_C1R (tempPtr, 1, dx, 2, imgSize, ippMskSize3x3, ippBorderRepl, 0, buffer);
sts = ippiFilterSobelHorizBorder_8u16s_C1R(tempPtr, 1, dy, 2, imgSize, ippMskSize3x3, ippBorderRepl, 0, buffer);
sts = ippiCanny_16s8u_C1R(dx, 2, dy, 2, ptr2, 1, imgSize, 10, 100, buffer);
//ippsFree(buffer);
ofstream myfile;
myfile.open("C://Users//Yuja//Documents//MATLAB//outputautoreg.raw", ios::out | ios::binary);
for(int i=0; i< 1024*1392; i++) {
myfile.write((char*)&ptr2, sizeof(char));
}
return 0;
}
int main(array<:STRING> ^args){
int size1; int size2;
ptr1 = new Ipp16u[1392*1024]; ptr2 = new Ipp8u[1392*1024];
Ipp8u *buffer;
Ipp16s *dx, *dy;
dx = new Ipp16s[1392*1024]; dy = new Ipp16s[1392*1024];
readVals(); testMethod(); sts = ippiFilterSobelHorizGetBufferSize_8u16s_C1R(imgSize, ippMskSize3x3, &size1); sts = ippiFilterSobelHorizGetBufferSize_8u16s_C1R(imgSize, ippMskSize3x3, &size2);

if(size1 ippiCannyGetSize(imgSize, &size2);
if(size1 < size2) { size1=size2; }
buffer = new Ipp8u[size1];
sts = ippiFilterSobelNegVertBorder_8u16s_C1R (tempPtr, 1, dx, 2, imgSize, ippMskSize3x3, ippBorderRepl, 0, buffer); sts = ippiFilterSobelHorizBorder_8u16s_C1R(tempPtr, 1, dy, 2, imgSize, ippMskSize3x3, ippBorderRepl, 0, buffer); sts = ippiCanny_16s8u_C1R(dx, 2, dy, 2, ptr2, 1, imgSize, 10, 100, buffer); //ippsFree(buffer);
ofstream myfile; myfile.open("C://Users//Yuja//Documents//MATLAB//outputautoreg.raw", ios::out | ios::binary);
for(int i=0; i< 1024*1392; i++) { myfile.write((char*)&ptr2, sizeof(char)); }


return 0;
}
0 项奖励
1 解答
Ying_H_Intel
主持人
3,845 次查看

Hello androoy,

I guess, the problem is in the original image ptr and image show.
Do you have chance to show the imagein imgCache?

I upload one small sample (cpp code)to show the image, you may try it.

Regards,
Ying

//ippiCanny.cpp

#include
#include
#include
#include "ipp.h"

extern void* ipView_8u_C1R(const Ipp8u* pData, int step, IppiSize roi,
const char* caption, int isModalView); //from ippview.cpp

int main()
{

int width=1024;
int height=1392;
IppiSize roi = {1024, 1392};
int size, size1;
int imgStep16, imgStep8;
Ipp16s *dx = ippiMalloc_16s_C1(1024, 1392, &imgStep16);
Ipp16s *dy = ippiMalloc_16s_C1(1024, 1392, &imgStep16);
Ipp8u *imgCache = ippiMalloc_8u_C1(1024, 1392,&imgStep8);
Ipp8u *edges = ippiMalloc_8u_C1(1024, 1392, &imgStep8);
//ippiImageJaehne_8u_C1R(imgCache, imgStep8, roi);
IppiSize sqrSize={400, 400};
ippiSet_8u_C1R(255, imgCache+800*imgStep8+200, imgStep8, sqrSize);
/*for(int i=0; i < (width*height); i++) {
imgCache = (i/16);
}*/
ipView_8u_C1R( imgCache, imgStep8, roi, "imgCache", 0 );
ippiFilterSobelVertGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size);
ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size1);
if(sizeippiCannyGetSize(roi, &size1);
if(sizeIpp8u * buffer = ippsMalloc_8u(size);
ippiFilterSobelVertBorder_8u16s_C1R(imgCache, 1024*sizeof(Ipp8u), dx, 1024*sizeof(Ipp16s), roi, ippMskSize3x3, ippBorderRepl, 0, buffer);
ippiFilterSobelHorizBorder_8u16s_C1R(imgCache, 1024*sizeof(Ipp8u), dy, 1024*sizeof(Ipp16s), roi, ippMskSize3x3, ippBorderRepl, 0, buffer);
ippiCanny_16s8u_C1R(dx, 1024*sizeof(Ipp16s), dy, 1024*sizeof(Ipp16s), edges, 1024*sizeof(Ipp8u), roi, 100, 1000, buffer);

ipView_8u_C1R( edges, imgStep8, roi, "edges", 1 );
return 0;
}


在原帖中查看解决方案

0 项奖励
6 回复数
Ying_H_Intel
主持人
3,845 次查看
Hello Androoy,

The problem looks be the parameter: widthSteps.
widthStep: Stride or step in bytes through theimage.it isthe width ofimagerow, but in bytes.

So you may change all of 1 or 2 inabove code to imgSize.width*sizeof(Ipp8u) or dy.width*sizeof(Ipp16s).
or other strides,depends on your array memory layout and datatype.

Best Wishes,
Ying H.
0 项奖励
androoy
初学者
3,845 次查看
Hi Ying,
Thanks you for the help! That was exactly what the problem was. I thought the "step" size was per cell bytes.
I'm running into a new problem now - the edges on my image are not detected properly.
My image ends up skewed and broken up into recognizable parts. Here is the code (basically just following the demo procedure as shown in the documentation under Canny) :
Ipp8u * doCanny(Ipp16u* ptr) {
int width=1024;
int height=1392;
IppiSize roi = {1024, 1392};
int size, size1;
Ipp16s *dx = ippiMalloc_16s_C1(1024, 1392, &imgStep16);
Ipp16s *dy = ippiMalloc_16s_C1(1024, 1392, &imgStep16);
Ipp8u *imgCache = ippiMalloc_8u_C1(1024, 1392,&imgStep8);
Ipp8u *edges = ippiMalloc_8u_C1(1024, 1392, &imgStep8);
for(int i=0; i < (width*height); i++) {
imgCache = (ptr/16);
}
ippiFilterSobelVertGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size);
ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size1);
if(size
ippiCannyGetSize(roi, &size1);
if(size
Ipp8u * buffer = ippsMalloc_8u(size);
ippiFilterSobelVertBorder_8u16s_C1R(imgCache, 1024*sizeof(Ipp8u), dx, 1024*sizeof(Ipp16s), roi, ippMskSize3x3, ippBorderRepl, 0, buffer);
ippiFilterSobelHorizBorder_8u16s_C1R(imgCache, 1024*sizeof(Ipp8u), dy, 1024*sizeof(Ipp16s), roi, ippMskSize3x3, ippBorderRepl, 0, buffer);
ippiCanny_16s8u_C1R(dx, 1024*sizeof(Ipp16s), dy, 1024*sizeof(Ipp16s), edges, 1024*sizeof(Ipp8u), roi, 100, 1000, buffer);
return edges;
}
Ipp8u * doCanny(Ipp16u* ptr) {


int width=1024; int height=1392; IppiSize roi = {1024, 1392};
int size, size1; Ipp16s *dx = ippiMalloc_16s_C1(1024, 1392, &imgStep16); Ipp16s *dy = ippiMalloc_16s_C1(1024, 1392, &imgStep16);
Ipp8u *imgCache = ippiMalloc_8u_C1(1024, 1392,&imgStep8); Ipp8u *edges = ippiMalloc_8u_C1(1024, 1392, &imgStep8);
for(int i=0; i < (width*height); i++) { imgCache = (ptr/16); }
ippiFilterSobelVertGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size); ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size1);
if(size Ipp8u * buffer = ippsMalloc_8u(size);

ippiFilterSobelVertBorder_8u16s_C1R(imgCache, 1024*sizeof(Ipp8u), dx, 1024*sizeof(Ipp16s), roi, ippMskSize3x3, ippBorderRepl, 0, buffer);
ippiFilterSobelHorizBorder_8u16s_C1R(imgCache, 1024*sizeof(Ipp8u), dy, 1024*sizeof(Ipp16s), roi, ippMskSize3x3, ippBorderRepl, 0, buffer);

ippiCanny_16s8u_C1R(dx, 1024*sizeof(Ipp16s), dy, 1024*sizeof(Ipp16s), edges, 1024*sizeof(Ipp8u), roi, 100, 1000, buffer);
return edges;}
Source image (just a square):
edges image:
0 项奖励
Ying_H_Intel
主持人
3,845 次查看
Hi androoy,

The code looks no problem. but from the result image,it looksstill some errors in data access.

1)For example, if your prc imageis aRGB 3 channal image with 8u data type, thenthe assignmentmay not correct.

for(int i=0; i < (width*height); i++) {
imgCache = (ptr/16);
}.
what data format isin ptr?

2)The edge image is 8u 1 channale image with width=1024, hight=1392, but the shown edges image have about width 500, is there any problem in showing the image?

Additionally,it is recommended to use imgStep8, imgStep16 other thanthe width*sizeof(Ipp8u) as widthStep. Luckily, you have 1024 as width, they are same.If other value like 1000, then imgStep8!=1000*sizeof(Ipp8u).

Best Regards,
Ying
0 项奖励
androoy
初学者
3,845 次查看
Thanks for the help Ying,
1) I am reading in data into ptr this way:
Ipp16u * ptr;
ptr = ippiMalloc_16u_C1(imgSize.width, imgSize.height, &imgStep16);
FILE * fp=fopen("C://Users//Yuja//Documents//MATLAB//test.raw", "rb");
fread(ptr, sizeof(short), 1024*1392, fp);
The file test.raw is full of image data which is only 12 bits large, but uses a 16bit container (which is why I read it in as a short). In this case, it is just a square for my test image. There is only 1 channel. I then convert the data in ptr to an Ipp8u by dividing it by 16 and storing it in imgCache.
2) You are right, I messed up displaying the image. I was displaying it at 16s instead of 8u. Here is the correct resulting image:
Also, here is how I am outputting the data.
Ipp8u *edges1;
//Ipp8u *edges2;
edges1 = ippiMalloc_8u_C1(imgSize.width, imgSize.height, &imgStep8);
edges2 = ippiMalloc_8u_C1(imgSize.width, imgSize.height, &imgStep8);
edges1 = doCanny(ptr);
//edges2 = doCanny(ptr2);
ofstream myfile;
myfile.open("C://Users//Yuja//Documents//MATLAB//edge1.raw", ios::out | ios::binary);
for(int i=0; i< 1024*1392; i++) {
myfile.write((char*)&edges1, sizeof(char));
}
myfile.close();
Perhaps the problem is in how I output the data?
Some additional info:
int size, size1;
Ipp16s *dx = ippiMalloc_16s_C1(1024, 1392, &imgStep16);
Ipp16s *dy = ippiMalloc_16s_C1(1024, 1392, &imgStep16);
Ipp8u *imgCache = ippiMalloc_8u_C1(1024, 1392,&imgStep8);
Ipp8u *edges = ippiMalloc_8u_C1(1024, 1392, &imgStep8);
0 项奖励
Ying_H_Intel
主持人
3,846 次查看

Hello androoy,

I guess, the problem is in the original image ptr and image show.
Do you have chance to show the imagein imgCache?

I upload one small sample (cpp code)to show the image, you may try it.

Regards,
Ying

//ippiCanny.cpp

#include
#include
#include
#include "ipp.h"

extern void* ipView_8u_C1R(const Ipp8u* pData, int step, IppiSize roi,
const char* caption, int isModalView); //from ippview.cpp

int main()
{

int width=1024;
int height=1392;
IppiSize roi = {1024, 1392};
int size, size1;
int imgStep16, imgStep8;
Ipp16s *dx = ippiMalloc_16s_C1(1024, 1392, &imgStep16);
Ipp16s *dy = ippiMalloc_16s_C1(1024, 1392, &imgStep16);
Ipp8u *imgCache = ippiMalloc_8u_C1(1024, 1392,&imgStep8);
Ipp8u *edges = ippiMalloc_8u_C1(1024, 1392, &imgStep8);
//ippiImageJaehne_8u_C1R(imgCache, imgStep8, roi);
IppiSize sqrSize={400, 400};
ippiSet_8u_C1R(255, imgCache+800*imgStep8+200, imgStep8, sqrSize);
/*for(int i=0; i < (width*height); i++) {
imgCache = (i/16);
}*/
ipView_8u_C1R( imgCache, imgStep8, roi, "imgCache", 0 );
ippiFilterSobelVertGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size);
ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size1);
if(sizeippiCannyGetSize(roi, &size1);
if(sizeIpp8u * buffer = ippsMalloc_8u(size);
ippiFilterSobelVertBorder_8u16s_C1R(imgCache, 1024*sizeof(Ipp8u), dx, 1024*sizeof(Ipp16s), roi, ippMskSize3x3, ippBorderRepl, 0, buffer);
ippiFilterSobelHorizBorder_8u16s_C1R(imgCache, 1024*sizeof(Ipp8u), dy, 1024*sizeof(Ipp16s), roi, ippMskSize3x3, ippBorderRepl, 0, buffer);
ippiCanny_16s8u_C1R(dx, 1024*sizeof(Ipp16s), dy, 1024*sizeof(Ipp16s), edges, 1024*sizeof(Ipp8u), roi, 100, 1000, buffer);

ipView_8u_C1R( edges, imgStep8, roi, "edges", 1 );
return 0;
}


0 项奖励
androoy
初学者
3,845 次查看
Thank you Ying. I managed to get it working thanks to you. Your example should really replace the one in the documentation.
0 项奖励
回复