i am working on a project in C++ WinForms. i have a blur and defocused
Image. i want to make that image more focused and sharpened but smooth and clean as this
Image. this image enhanced in mobile application. and i want the same result as this image.
if anyone can help or guide then it will be must appreciated!!!
What I have tried:
i have made a WinForms C++ project and using open cv i am trying to make image more detailed focused and sharp. i have used filter2D() and bilateralFilter() function and i am getting the result
Image. still this is not the result i want.
here is my source code that i have tried.
void enhanceImage(Mat& inputImage, Mat& outputImage)
{
try {
Mat kernel = (Mat_<float>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
filter2D(inputImage, outputImage, -1, kernel);
}
catch (System::Exception^ex)
{
MessageBox::Show("An error occurred: " + ex->Message);
}
}
void removeNoise(Mat& inputImage, Mat& outputImage)
{
try {
bilateralFilter(inputImage, outputImage, 9, 75, 75);
}
catch (System::Exception^ ex)
{
MessageBox::Show("An error occurred: " + ex->Message);
}
}
private: System::Void EnhanceBn_Click(System::Object^ sender, System::EventArgs^ e)
{
try {
string folderPath = msclr::interop::marshal_as<string>(dialog->SelectedPath);
savedialog->ShowDialog();
int numFiles = std::distance(std::filesystem::directory_iterator(folderPath), std::filesystem::directory_iterator());
progressBar->Minimum = 0;
progressBar->Maximum = numFiles;
progressBar->Value = 0;
int i = 0;
for (const auto& file : filesystem::directory_iterator(folderPath))
{
Mat inputImage = imread(file.path().string());
Mat outputImage;
Mat enhancedImage;
enhanceImage(inputImage, enhancedImage);
removeNoise(enhancedImage, outputImage);
string savefolderPath = msclr::interop::marshal_as<string>(savedialog->SelectedPath);
string outputPath = savefolderPath + "\\" + file.path().filename().string();
imwrite(outputPath, outputImage);
i++;
label->Text = i.ToString();
progressBar->Value = i;
Application::DoEvents();
}
label->Text = "Processing completed!";
MessageBox::Show("images enhanced sucessfully");
progressBar->Value = 0;
}
catch (System::Exception^ ex)
{
MessageBox::Show("An error occurred: " + ex->Message);
}
}