Hi,
I am using Cimage library to do a Sobel algorithm. Here is the code
CImage * image1;
image1->Load(".\\tempSnapShot1.bmp");
CImage* returnImage = new CImage();
Sobel(image1,returnImage);
The Sobel function is
void CI90ControllerDlg::Sobel(CImage* image,CImage *returnImage)
{
returnImage->Create(image->GetWidth(),image->GetHeight(), image->GetBPP(),0);
double GX[3][3],GY[3][3];
int sumX = 0;
int sumY = 0;
int SUM = 0;
// Masks //////////////////////////////////////
//X//
GX[0][0] = -1; GX[0][1] = 0; GX[0][2] = 1;
GX[1][0] = -2; GX[1][1] = 0; GX[1][2] = 2;
GX[2][0] = -1; GX[2][1] = 0; GX[2][2] = 1;
//Y//
GY[0][0] = 1; GY[0][1] = 2; GY[0][2] = 1;
GY[1][0] = 0; GY[1][1] = 0; GY[1][2] = 0;
GY[2][0] = -1; GY[2][1] = -2; GY[2][2] = -1;
//int r=image->GetHeight();
for(int Ypix=0; Ypix < image->GetHeight(); Ypix++)
{
for(int X=0; X < image->GetWidth(); X++)
{
sumX = 0;
sumY = 0;
if(Ypix==0 || Ypix == image->GetHeight()-1)
SUM = 0;
else if(X==0 || X == image->GetWidth()-1)
SUM = 0;
else
{
for(int I=-1; I<=1; I++)
{
for(int J=-1; J<=1; J++)
{
int piX = J + X;
int piY = I + Ypix;
COLORREF pixVal = image->GetPixel(piX,piY);
int R = GetRValue(pixVal);
int G = GetGValue(pixVal);
int B = GetBValue(pixVal);
int NC = (R+G+B)/3;
sumX = sumX + (NC) * GX[J+1][I+1];
sumY = sumY + (NC) * GY[J+1][I+1];
}
}
SUM = abs(sumX) + abs(sumY);
}
if(SUM>255) SUM=255;
if(SUM<0) SUM=0;
int newPixel = (255 - (unsigned char)(SUM));
COLORREF newPixCol = RGB(newPixel,newPixel,newPixel);
returnImage->SetPixel(X,Ypix,newPixCol) ;
}
}
}
The image is loaded ok, but in the Sobel function it cracks and gives me this error
Debug assertion failed Expression: (x> = 0) & & (x <m_nWidth)
I also saw that when it goes to the sobel function I have
for(int Ypix=0; Ypix < image->GetHeight(); Ypix++)
{
and when I put a breakpoint at this for Ypix is a big number -8741824 or something like that...and that is where is cracks.
Can anyone help me? i tried to find answers on the internet but nothing came up.
Thank you,