-
prefix_sum_query.cpp
Contains code to read an image (as a grayscale image) using OpenCV, calculate the region's pixel sum via both the naive approach and the prefix sum method, and measure the execution time. -
difference_array_update.cpp
Contains code to read an image using OpenCV, update a specified region's pixel values by adding a constant (e.g., +10) using both the naive method and the difference array approach, and measure the execution time.
- C++ compiler supporting C++11 (or later)
- OpenCV (version 3.0 or later recommended)
- CMake (optional, if you prefer building with CMake)
For each file, you can compile using the following commands:
g++ prefix_sum_query.cpp -o prefix_sum_query `pkg-config --cflags --libs opencv4`
g++ difference_array_update.cpp -o diff_update `pkg-config --cflags --libs opencv4`
Alternatively, you can create a CMakeLists.txt
file. Here's an example:
cmake_minimum_required(VERSION 3.0)
project(ImageRegionOperations)
find_package(OpenCV REQUIRED)
add_executable(prefix_sum_query prefix_sum_query.cpp)
target_link_libraries(prefix_sum_query ${OpenCV_LIBS})
add_executable(diff_update difference_array_update.cpp)
target_link_libraries(diff_update ${OpenCV_LIBS})
Then, build with:
mkdir build && cd build
cmake ..
make
Run the executables from the command line, providing the path to an image file (preferably a grayscale image):
./prefix_sum_query path/to/your/image.jpg
./diff_update path/to/your/image.jpg
The programs will output the image dimensions, the region being processed, the computed results, and the time taken for each method.