From a0c682dc70da88110588f103858ad0193e45e068 Mon Sep 17 00:00:00 2001 From: Jerzy Kwiatkowski Date: Thu, 6 Jul 2023 15:44:12 +0200 Subject: [PATCH] Zaktualizuj 'examples/example_win32_directx11/main.cpp' --- examples/example_win32_directx11/main.cpp | 64 +++++++++++++---------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index 2acb651..2c48104 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -69,7 +69,7 @@ bool LoadTextureFromFile(unsigned char* image_data, int image_width, int image_h #include #include -// Funkcja dokonuj¹ca dylacji +// Funkcja dokonuj¹ca dylacji void dilation(const unsigned char* image, int width, int height, unsigned char* output) { int structuringElement[3][3] = { {0, 255, 0}, @@ -97,7 +97,7 @@ void dilation(const unsigned char* image, int width, int height, unsigned char* } } -// Funkcja dokonuj¹ca erozji +// Funkcja dokonuj¹ca erozji void erosion(const unsigned char* image, int width, int height, unsigned char* output) { int structuringElement[3][3] = { {0, 255, 0}, @@ -125,7 +125,7 @@ void erosion(const unsigned char* image, int width, int height, unsigned char* o } } -// Funkcja dokonuj¹ca hit-and-miss +// Funkcja dokonuj¹ca hit-and-miss void hitAndMiss(const unsigned char* image, int width, int height, unsigned char* output) { int structuringElement1[3][3] = { {0, 0, 0}, @@ -163,7 +163,7 @@ void hitAndMiss(const unsigned char* image, int width, int height, unsigned char } } -// Funkcja dokonuj¹ca pogrubiania +// Funkcja dokonuj¹ca pogrubiania void thickening(const unsigned char* image, int width, int height, unsigned char* output) { int structuringElement[3][3] = { {0, 255, 0}, @@ -189,7 +189,7 @@ void thickening(const unsigned char* image, int width, int height, unsigned char } } -// Funkcja dokonuj¹ca pocieniania +// Funkcja dokonuj¹ca pocieniania void thinning(const unsigned char* image, int width, int height, unsigned char* output) { int structuringElement[3][3] = { {0, 255, 0}, @@ -563,6 +563,10 @@ int main(int, char**) int* colorG = nullptr; int* colorB = nullptr; + static float sliderValue = 0.5f; + float xMin = 0; + float xMax = 256 * sliderValue; + while (!done) { MSG msg; @@ -612,13 +616,6 @@ int main(int, char**) ImGui::End(); } - if (histogram) - { - ImGui::Begin("Histogram"); - - ImGui::End(); - } - if (image_window) { int my_image_width = 0; @@ -628,22 +625,16 @@ int main(int, char**) unsigned char* grayscaleImage = new unsigned char[my_image_width * my_image_height]; unsigned char* binaryImage = new unsigned char[my_image_width * my_image_height]; if (colorR == NULL && colorB == NULL && colorG == NULL) { - colorR = new int[my_image_width * my_image_height]; - colorG = new int[my_image_width * my_image_height]; - colorB = new int[my_image_width * my_image_height]; + colorR = new int[256]; + colorG = new int[256]; + colorB = new int[256]; int place = 0; - for (int y = 0; y < my_image_height; ++y) - { - for (int x = 0; x < my_image_width; ++x) - { - int index = (y * my_image_width + x) * 4; - - colorR[place] = image_data[index]; - colorG[place] = image_data[index + 1]; - colorB[place++] = image_data[index + 2]; - } + for (int i = 0; i < my_image_width * my_image_height * my_image_channels; i += my_image_channels) { + colorR[image_data[i]]++; + colorG[image_data[i + 1]]++; + colorB[image_data[i + 2]]++; } } @@ -676,6 +667,21 @@ int main(int, char**) { hough_transform(image_data, my_image_width, my_image_height, calculateOtsuThreshold(image_data, my_image_width, my_image_height)); } + if (histogram) + { + ImGui::Begin("Histogram"); + float xMin = 0; + float xMax = 256 * sliderValue; + /*ImPlot::SetNextPlotLimitsX(xMin, xMax, ImGuiCond_Always);*/ + if (ImPlot::BeginPlot("RGB Histogram")) { + ImPlot::PlotHistogram("Red", colorR, 256); + ImPlot::PlotHistogram("Green", colorG, 256); + ImPlot::PlotHistogram("Blue", colorB, 256); + ImPlot::EndPlot(); + } + ImGui::SliderFloat("X-axis Range", &sliderValue, 0.0f, 1.0f); + ImGui::End(); + } if (!image_data) { ImGui::Begin("Error"); @@ -689,8 +695,8 @@ int main(int, char**) ID3D11ShaderResourceView* my_texture = NULL; if (binary == TRUE) { bool ret = LoadTextureFromFile(binaryImage, my_image_width, my_image_height, &my_texture); - stbi_image_free(binaryImage); - stbi_image_free(grayscaleImage); + delete[] binaryImage; + delete[] grayscaleImage; stbi_image_free(image_data); } else { @@ -700,8 +706,10 @@ int main(int, char**) ImGui::Begin("Image window"); ImGui::Image((void*)my_texture, ImVec2(my_image_width, my_image_height)); ImGui::End(); + ImGui::Begin("Histograms"); + ImGui::Checkbox("RGB", &histogram); + ImGui::End(); ImGui::Begin("Filters"); - ImGui::Checkbox("Histogram", &histogram); ImGui::Checkbox("Negative", &negative); ImGui::Checkbox("Sepia", &sepia); ImGui::Checkbox("Saturation", &saturation);