From 21218837b34bbf269832ed43421c982dde95116f Mon Sep 17 00:00:00 2001 From: Jerzy Kwiatkowski Date: Fri, 7 Jul 2023 23:58:43 +0200 Subject: [PATCH] Zaktualizuj 'examples/example_win32_directx11/main.cpp' --- examples/example_win32_directx11/main.cpp | 58 +++++++++++++++++------ 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index dc275ca..f2a080a 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -69,8 +69,7 @@ bool LoadTextureFromFile(unsigned char* image_data, int image_width, int image_h #include #include -// Funkcja dokonuj¹ca dylacji -void dilation(const unsigned char* image, int width, int height, unsigned char* output) { +void dilation(unsigned char* image, int width, int height) { int structuringElement[3][3] = { {0, 255, 0}, {255, 255, 255}, @@ -92,13 +91,13 @@ void dilation(const unsigned char* image, int width, int height, unsigned char* } } } - output[y * width + x] = static_cast(maxPixelValue > 255 ? 255 : maxPixelValue); + image[y * width + x] = static_cast(maxPixelValue > 255 ? 255 : maxPixelValue); } } } -// Funkcja dokonuj¹ca erozji -void erosion(const unsigned char* image, int width, int height, unsigned char* output) { + +void erosion(unsigned char* image, int width, int height) { int structuringElement[3][3] = { {0, 255, 0}, {255, 255, 255}, @@ -120,13 +119,12 @@ void erosion(const unsigned char* image, int width, int height, unsigned char* o } } } - output[y * width + x] = static_cast(minPixelValue < 0 ? 0 : minPixelValue); + image[y * width + x] = static_cast(minPixelValue < 0 ? 0 : minPixelValue); } } } -// Funkcja dokonuj¹ca hit-and-miss -void hitAndMiss(const unsigned char* image, int width, int height, unsigned char* output) { +void hitAndMiss(unsigned char* image, int width, int height) { int structuringElement1[3][3] = { {0, 0, 0}, {255, 255, 0}, @@ -158,13 +156,12 @@ void hitAndMiss(const unsigned char* image, int width, int height, unsigned char } } } - output[y * width + x] = (match1 && match2) ? 255 : 0; + image[y * width + x] = (match1 && match2) ? 255 : 0; } } } -// Funkcja dokonuj¹ca pogrubiania -void thickening(const unsigned char* image, int width, int height, unsigned char* output) { +void thickening(unsigned char* image, int width, int height) { int structuringElement[3][3] = { {0, 255, 0}, {255, 255, 255}, @@ -179,7 +176,7 @@ void thickening(const unsigned char* image, int width, int height, unsigned char if (x + i >= 0 && x + i < width && y + j >= 0 && y + j < height) { int structuringElementValue = structuringElement[j + 1][i + 1]; if (structuringElementValue == 255) { - output[(y + j) * width + (x + i)] = 255; + image[(y + j) * width + (x + i)] = 255; } } } @@ -189,8 +186,7 @@ void thickening(const unsigned char* image, int width, int height, unsigned char } } -// Funkcja dokonuj¹ca pocieniania -void thinning(const unsigned char* image, int width, int height, unsigned char* output) { +void thinning(unsigned char* image, int width, int height) { int structuringElement[3][3] = { {0, 255, 0}, {255, 255, 255}, @@ -216,7 +212,7 @@ void thinning(const unsigned char* image, int width, int height, unsigned char* break; } } - output[y * width + x] = match ? 255 : 0; + image[y * width + x] = match ? 255 : 0; } } } @@ -571,6 +567,11 @@ int main(int, char**) float sigma = 2.0f; bool binary = false; bool hough = false; + bool thining = false; + bool thick = false; + bool hitmiss = false; + bool erosi = false; + bool dil = false; bool done = false; @@ -683,6 +684,26 @@ int main(int, char**) { hough_transform(image_data, my_image_width, my_image_height, 125, hough_image, my_image_channels); } + if (thining) + { + thinning(image_data, my_image_width, my_image_height); + } + if (thick) + { + thickening(image_data, my_image_width, my_image_height); + } + if (hitmiss) + { + hitAndMiss(image_data, my_image_width, my_image_height); + } + if (erosi) + { + erosion(image_data, my_image_width, my_image_height); + } + if (dil) + { + dilation(image_data, my_image_width, my_image_height); + } if (histogram) { ImGui::Begin("Histogram"); @@ -730,6 +751,13 @@ int main(int, char**) ImGui::Begin("Histograms"); ImGui::Checkbox("RGB", &histogram); ImGui::End(); + ImGui::Begin("Operatory"); + ImGui::Checkbox("Dylacja", &dil); + ImGui::Checkbox("Erozja", &erosi); + ImGui::Checkbox("Hit and Miss", &hitmiss); + ImGui::Checkbox("Pogrubianie", &thick); + ImGui::Checkbox("Thining", &thining); + ImGui::End(); ImGui::Begin("Filters"); ImGui::Checkbox("Negative", &negative); ImGui::Checkbox("Sepia", &sepia);