Read in more arguments,

This commit is contained in:
2023-06-25 14:29:15 +02:00
parent 35979f6ea3
commit d9192ef9fb

View File

@@ -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 <input_image>
where <input_image> is the path to the image file you want to denoise.
./TV_Denoising_CUDA <input_image> <output_image> <lambda> <iterations>
where:
- <input_image> is the path to the input image file you want to denoise.
- <output_image> is the path to the output denoised image file.
- <lambda> is the regularization parameter for TV denoising (optional, default: 0.02).
- <iterations> is the number of iterations for TV denoising (optional, default: 10).
*/
#include <iostream>
#include <opencv2/opencv.hpp>
@@ -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 <image_file_path>" << std::endl;
std::cerr << "Usage: ./TV_Denoising_CUDA <input_image> <output_image> [<lambda>] [<iterations>]" << 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;
}