diff --git a/src/main.cpp b/src/main.cpp index e1f4901..2ecbac0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,8 +7,12 @@ Description: It reads an image file, denoises it using the TV denoising algorithm, and saves the denoised image to a file. You can run it with the following command: - ./TV_Denoising_CUDA - where is the path to the image file you want to denoise. + ./TV_Denoising_CUDA + where: + - is the path to the input image file you want to denoise. + - is the path to the output denoised image file. + - is the regularization parameter for TV denoising (optional, default: 0.02). + - is the number of iterations for TV denoising (optional, default: 10). */ #include #include @@ -16,29 +20,42 @@ Description: int main(int argc, char** argv) { - // Check if an image file path is provided as an argument - if (argc != 2) + // Check if the required arguments are provided + if (argc < 3) { - std::cerr << "Usage: ./denoiser " << std::endl; + std::cerr << "Usage: ./TV_Denoising_CUDA [] []" << std::endl; return 1; } - // Read the image - cv::Mat image = cv::imread(argv[1], cv::IMREAD_GRAYSCALE); + // Read the input arguments + std::string inputImagePath = argv[1]; + std::string outputImagePath = argv[2]; + float lambda = 0.02; + int iterations = 10; + + // Check if optional arguments are provided and update the corresponding variables + if (argc >= 4) + lambda = std::stof(argv[3]); + if (argc >= 5) + iterations = std::stoi(argv[4]); + + // Read the input image + cv::Mat image = cv::imread(inputImagePath, cv::IMREAD_GRAYSCALE); // Check if the image was successfully loaded if (image.empty()) { - std::cerr << "Failed to read the image." << std::endl; + std::cerr << "Failed to read the input image." << std::endl; return 1; } - TVDenoising(image, 0.02, 10); + // Perform TV denoising + TVDenoising(image, lambda, iterations); // Display and save the denoised image cv::imshow("Denoised Image", image); cv::waitKey(0); - cv::imwrite("denoised_image.jpg", image); + cv::imwrite(outputImagePath, image); return 0; }