parent
b122270aa3
commit
a3a73b9332
2 changed files with 32 additions and 29 deletions
|
@ -18,19 +18,14 @@
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
void normalizeKernel(float *kernel, int size){
|
void NormalizeKernel(float *kernel, int size)
|
||||||
float sum = 0.0f;
|
|
||||||
for(int i = 0; i < size; i++)
|
|
||||||
{
|
{
|
||||||
sum += kernel[i];
|
float sum = 0.0f;
|
||||||
}
|
for (int i = 0; i < size; i++) sum += kernel[i];
|
||||||
|
|
||||||
if (sum != 0.0f)
|
if (sum != 0.0f)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++) kernel[i] /= sum;
|
||||||
{
|
|
||||||
kernel[i] /= sum;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,29 +33,31 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
Image image = LoadImage("resources/cat.png"); // Loaded in CPU memory (RAM)
|
|
||||||
|
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image convolution");
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image convolution");
|
||||||
|
|
||||||
float gaussiankernel[] = {1.0, 2.0, 1.0,
|
Image image = LoadImage("resources/cat.png"); // Loaded in CPU memory (RAM)
|
||||||
2.0, 4.0, 2.0,
|
|
||||||
1.0, 2.0, 1.0};
|
|
||||||
|
|
||||||
float sobelkernel[] = {1.0, 0.0, -1.0,
|
float gaussiankernel[] = {
|
||||||
2.0, 0.0, -2.0,
|
1.0f, 2.0f, 1.0f,
|
||||||
1.0, 0.0, -1.0};
|
2.0f, 4.0f, 2.0f,
|
||||||
|
1.0f, 2.0f, 1.0f };
|
||||||
|
|
||||||
float sharpenkernel[] = {0.0, -1.0, 0.0,
|
float sobelkernel[] = {
|
||||||
-1.0, 5.0, -1.0,
|
1.0f, 0.0f, -1.0f,
|
||||||
0.0, -1.0, 0.0};
|
2.0f, 0.0f, -2.0f,
|
||||||
|
1.0f, 0.0f, -1.0f };
|
||||||
|
|
||||||
normalizeKernel(gaussiankernel, 9);
|
float sharpenkernel[] = {
|
||||||
normalizeKernel(sharpenkernel, 9);
|
0.0f, -1.0f, 0.0f,
|
||||||
normalizeKernel(sobelkernel, 9);
|
-1.0f, 5.0f, -1.0f,
|
||||||
|
0.0f, -1.0f, 0.0f };
|
||||||
|
|
||||||
|
NormalizeKernel(gaussiankernel, 9);
|
||||||
|
NormalizeKernel(sharpenkernel, 9);
|
||||||
|
NormalizeKernel(sobelkernel, 9);
|
||||||
|
|
||||||
Image catSharpend = ImageCopy(image);
|
Image catSharpend = ImageCopy(image);
|
||||||
ImageKernelConvolution(&catSharpend, sharpenkernel, 9);
|
ImageKernelConvolution(&catSharpend, sharpenkernel, 9);
|
||||||
|
@ -69,6 +66,7 @@ int main(void)
|
||||||
ImageKernelConvolution(&catSobel, sobelkernel, 9);
|
ImageKernelConvolution(&catSobel, sobelkernel, 9);
|
||||||
|
|
||||||
Image catGaussian = ImageCopy(image);
|
Image catGaussian = ImageCopy(image);
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
ImageKernelConvolution(&catGaussian, gaussiankernel, 9);
|
ImageKernelConvolution(&catGaussian, gaussiankernel, 9);
|
||||||
|
@ -78,11 +76,16 @@ int main(void)
|
||||||
ImageCrop(&catGaussian, (Rectangle){ 0, 0, (float)200, (float)450 });
|
ImageCrop(&catGaussian, (Rectangle){ 0, 0, (float)200, (float)450 });
|
||||||
ImageCrop(&catSobel, (Rectangle){ 0, 0, (float)200, (float)450 });
|
ImageCrop(&catSobel, (Rectangle){ 0, 0, (float)200, (float)450 });
|
||||||
ImageCrop(&catSharpend, (Rectangle){ 0, 0, (float)200, (float)450 });
|
ImageCrop(&catSharpend, (Rectangle){ 0, 0, (float)200, (float)450 });
|
||||||
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
|
|
||||||
|
// Images converted to texture, GPU memory (VRAM)
|
||||||
|
Texture2D texture = LoadTextureFromImage(image);
|
||||||
Texture2D catSharpendTexture = LoadTextureFromImage(catSharpend);
|
Texture2D catSharpendTexture = LoadTextureFromImage(catSharpend);
|
||||||
Texture2D catSobelTexture = LoadTextureFromImage(catSobel);
|
Texture2D catSobelTexture = LoadTextureFromImage(catSobel);
|
||||||
Texture2D catGaussianTexture = LoadTextureFromImage(catGaussian);
|
Texture2D catGaussianTexture = LoadTextureFromImage(catGaussian);
|
||||||
UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
|
||||||
|
// Once images have been converted to texture and uploaded to VRAM,
|
||||||
|
// they can be unloaded from RAM
|
||||||
|
UnloadImage(image);
|
||||||
UnloadImage(catGaussian);
|
UnloadImage(catGaussian);
|
||||||
UnloadImage(catSobel);
|
UnloadImage(catSobel);
|
||||||
UnloadImage(catSharpend);
|
UnloadImage(catSharpend);
|
||||||
|
@ -115,7 +118,7 @@ int main(void)
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadTexture(texture); // Texture unloading
|
UnloadTexture(texture);
|
||||||
UnloadTexture(catGaussianTexture);
|
UnloadTexture(catGaussianTexture);
|
||||||
UnloadTexture(catSobelTexture);
|
UnloadTexture(catSobelTexture);
|
||||||
UnloadTexture(catSharpendTexture);
|
UnloadTexture(catSharpendTexture);
|
||||||
|
|
BIN
examples/textures/textures_image_kernel.png
Normal file
BIN
examples/textures/textures_image_kernel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1 MiB |
Loading…
Add table
Add a link
Reference in a new issue