0

I'm trying to apply blur effect, but I'm getting totaly wrong colors I'm using Easy_BMP library to load BMP file into pixel array. I try to implement gaussian blur alghoritm with refference to this topic. What's wrong ?

void blur3x3(int i, int j, RGBApixel** pixelArray, BMP &Image) {

double blurValue = 0.111;
int avgR = 0;
int avgG= 0 ;
int avgB = 0;

int b = 0;
for(int w = i-1 ; w <= i+1 ; w++) {
    for(int z = i-1 ; z<=j+1 ; z++) {
        avgR = avgR + blurValue*( pixelArray[w][z].Red   );
        avgG = avgG + blurValue*( pixelArray[w][z].Green );
        avgB = avgB + blurValue*( pixelArray[w][z].Blue  );
    }
}

Image(i,j)->Red = (BYTE) avgR ;
Image(i,j)->Green = (BYTE) avgG;
Image(i,j)->Blue = (BYTE) avgB;

}


bool blur() {

BMP Image;
Image.ReadFromFile(fullFilePath);

int w = Image.TellWidth();
int h =  Image.TellHeight();

RGBApixel** pixelArray = new RGBApixel*[w];
for(int i = 0; i < w; ++i)
    pixelArray[i] = new RGBApixel[h];

for( int i=0 ; i < Image.TellWidth() ; i++) {
    for( int j=0 ; j < Image.TellHeight() ; j++) {
        pixelArray[i][j] = Image.GetPixel(i,j);
    }
}

for( int i=1 ; i < Image.TellWidth()-1 ; i++) {
    for( int j=1 ; j < Image.TellHeight()-1 ; j++) {
        blur3x3(i,j, pixelArray, Image);
    }
}

Image.SetBitDepth( 32 );
Image.WriteToFile( "/home/kxyz/BMP/gray.bmp" );
}
Community
  • 1
  • 1
kxyz
  • 802
  • 1
  • 9
  • 32

1 Answers1

2

In for(int z = i-1 ; z<=j+1 ; z++) {, try changing

int z = i-1

to

int z = j-1

Also, you are not deleting any of the arrays you allocate in your blur function.

Beta Carotin
  • 1,659
  • 1
  • 10
  • 27