Skip to content

Add basic support for generating test images #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ include_directories(${OpenCV_INCLUDE_DIRS})

add_subdirectory(lib)
add_subdirectory(benchmarks)
add_subdirectory(Tests)
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ $ ninja image-processing-benchmark
$ cd bin && ./image-processing-benchmark
```

Run image processing tests:

```
$ cd buddy-benchmark
$ mkdir build && cd build
$ cmake -G Ninja .. -DIMAGE_PROCESSING_TESTS=ON
$ ninja Tests
$ cd bin && mkdir TestImages && ./Tests 7 7 TestImages
```

Note : The convolution implementation in buddy mlir is not feature complete at the moment and it may produce output which differs to some extent from the frameworks used in comparison.
3 changes: 3 additions & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if(IMAGE_PROCESSING_TESTS)
add_subdirectory(ImageProcessing)
endif()
5 changes: 5 additions & 0 deletions Tests/ImageProcessing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(Tests TestImageGenerator.cpp)

target_link_libraries(Tests
${OpenCV_LIBS}
)
79 changes: 79 additions & 0 deletions Tests/ImageProcessing/TestImageGenerator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>

void FillImage(cv::Mat img) {
for (std::ptrdiff_t row = 0; row < img.rows; ++row)
for (std::ptrdiff_t col = 0; col < img.cols; ++col)
img.at<uchar>(col, row) = row * img.rows + col;
}

enum class boundaryOption {
BORDER_CONSTANT,
BORDER_REPLICATE,
BORDER_REFLECT,
BORDER_REFLECT101
};

void generateExpectedImage(cv::Mat img, cv::Mat expectedImg, int ddepth,
cv::Mat kernel, cv::Point anchor, double delta,
boundaryOption option, std::string name) {
if (option == boundaryOption::BORDER_CONSTANT)
cv::filter2D(img, expectedImg, ddepth, kernel, anchor, delta,
cv::BORDER_CONSTANT);
else if (option == boundaryOption::BORDER_REPLICATE)
cv::filter2D(img, expectedImg, ddepth, kernel, anchor, delta,
cv::BORDER_REPLICATE);
else if (option == boundaryOption::BORDER_REFLECT)
cv::filter2D(img, expectedImg, ddepth, kernel, anchor, delta,
cv::BORDER_REFLECT);
else if (option == boundaryOption::BORDER_REFLECT101)
cv::filter2D(img, expectedImg, ddepth, kernel, anchor, delta,
cv::BORDER_REFLECT101);

cv::imwrite(name, expectedImg);
}

int main(int argc, char **argv) {
if (argc != 4) {
std::cout << "Invalid CLI arguments\nUsage : ImageHeight ImageWidth "
"DestinationFolder\n";
}

cv::Mat origImg, expImg;
origImg.create(atoi(argv[1]), atoi(argv[2]), CV_8UC1);
expImg.create(atoi(argv[1]), atoi(argv[2]), CV_8UC1);

FillImage(origImg);

double delta = 0;
int ddepth = -1;
cv::Point anchor;
cv::Mat kernel = cv::Mat::ones(3, 3, CV_32F);

for (std::ptrdiff_t i = 0; i < kernel.rows; ++i) {
for (std::ptrdiff_t j = 0; j < kernel.cols; ++j) {
// Put all expected images inside a folder and then test them from there.
std::string partialName;
partialName = std::string(argv[3]) + "/ExpectedImage_" +
std::to_string(i) + "_" + std::to_string(j) + "_";
anchor = cv::Point(i, j);

generateExpectedImage(origImg, expImg, ddepth, kernel, anchor, delta,
boundaryOption::BORDER_CONSTANT,
partialName + "BORDER_CONSTANT.png");

generateExpectedImage(origImg, expImg, ddepth, kernel, anchor, delta,
boundaryOption::BORDER_REPLICATE,
partialName + "BORDER_RELPICATE.png");

generateExpectedImage(origImg, expImg, ddepth, kernel, anchor, delta,
boundaryOption::BORDER_REFLECT,
partialName + "BORDER_REFLECT.png");

generateExpectedImage(origImg, expImg, ddepth, kernel, anchor, delta,
boundaryOption::BORDER_REFLECT101,
partialName + "BORDER_REFLECT101.png");
}
}
}