bool ImageFilterTest::Execute() { m_timer.Start(); FilterKernel kernel2D, kernel1D; FilterKernel::CreateTriangleFilter2D(&kernel2D, 11); FilterKernel::CreateTriangleFilter1D(&kernel1D, 11); Image* image = ApolloTestFramework::LoadImage("Lighthouse.png", ApolloTestFramework::DATA_IMAGE); VALIDATE_NOT_NULL(image); m_allocator.Add(image); Image* blurred2D = image->Convolve(&kernel2D, Apollo::Image::IMAGE_FILTER_EDGE_IGNORE); VALIDATE_NOT_NULL(blurred2D); m_allocator.Add(blurred2D); Image* blurred1D = image->ConvolveSeperated(&kernel1D, Apollo::Image::IMAGE_FILTER_EDGE_IGNORE); VALIDATE_NOT_NULL(blurred1D); m_allocator.Add(blurred1D); Image* mipMapped = image->GenerateMipMap(); VALIDATE_NOT_NULL(mipMapped); m_allocator.Add(mipMapped); image->ToGrayscale(image); m_timer.Stop(); bool passed = true; passed &= ApolloTestFramework::Instance()->ProcessResult(this, blurred2D, "LightHouseBlurred2D.png"); passed &= ApolloTestFramework::Instance()->ProcessResult(this, blurred1D, "LightHouseBlurred1D.png"); passed &= ApolloTestFramework::Instance()->ProcessResult(this, mipMapped, "LightHouseMipmapped.png"); passed &= ApolloTestFramework::Instance()->ProcessResult(this, image, "LightHouseGrayscale.png"); return passed; }
void Image::EdgeDetect(int threshold) { int* filtH = new int[9]; int* filtV = new int[9]; filtH[0] = -1; filtH[1] = 0; filtH[2] = 1; filtH[3] = -2; filtH[4] = 0; filtH[5] = 2; filtH[6] = -1; filtH[7] = 0; filtH[8] = 1; filtV[0] = 1; filtV[1] = 2; filtV[2] = 1; filtV[3] = 0; filtV[4] = 0; filtV[5] = 0; filtV[6] = -1; filtV[7] = -2; filtV[8] = -1; Image gx = Image(*this); Image gy = Image(*this); int n = 3; int norm = 1; gx.Convolve(filtH, n, norm, true); gy.Convolve(filtV, n, norm, true); for (int i = 0; i < num_pixels; i++) { int gxmag = gx.pixels[i].Luminance(); int gymag = gy.pixels[i].Luminance(); double gmag = sqrt((double) gxmag*gxmag + gymag*gymag); if (gmag > threshold) gmag = 255; else gmag = 0; pixels[i].SetClamp(gmag, gmag, gmag); } }