08-03-2023, 04:36 AM
(This post was last modified: 08-03-2023, 04:51 AM by PowerThreads.)
Can you please clarify which chunk stands for UnsharpMask?
Using peace of code below, but it's not the same even close
Other piece of code:
it does something, which is not relevant to what unsharpMask does, maybe I need to set some specific values?
if so, please advise what values I need to set
Using peace of code below, but it's not the same even close
Code:
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <cstring>
cv::Mat not_so_smart_sharpen(
const cv::Mat& bgr,
double sigma,
double amount,
double canny_low_threshold_weight,
double canny_high_threshold_weight,
int edge_weight)
{
cv::Mat enhanced_bgr, lab, enhanced_lab, channel[3], blurred, difference, bw, kernel, edges;
// convert to Lab
cv::cvtColor(bgr, lab, cv::ColorConversionCodes::COLOR_BGR2Lab);
// perform the enhancement on the brightness component
cv::split(lab, channel);
cv::Mat& brightness = channel[0];
// smoothing for unsharp masking
cv::GaussianBlur(brightness, blurred, cv::Size(0, 0), sigma);
difference = brightness - blurred;
// calculate an edge map. I'll use Otsu threshold as the basis
double thresh = cv::threshold(brightness, bw, 0, 255, cv::ThresholdTypes::THRESH_BINARY | cv::ThresholdTypes::THRESH_OTSU);
cv::Canny(brightness, edges, thresh * canny_low_threshold_weight, thresh * canny_high_threshold_weight);
// control edge thickness. use edge_weight=0 to use Canny edges unaltered
cv::dilate(edges, edges, kernel, cv::Point(-1, -1), edge_weight);
// unsharp masking on the edges
cv::add(brightness, difference * amount, brightness, edges);
// use the enhanced brightness channel
cv::merge(channel, 3, enhanced_lab);
// convert to BGR
cv::cvtColor(enhanced_lab, enhanced_bgr, cv::ColorConversionCodes::COLOR_Lab2BGR);
// cv::imshow("edges", edges);
// cv::imshow("difference", difference * amount);
// cv::imshow("original", bgr);
// cv::imshow("enhanced", enhanced_bgr);
// cv::waitKey(0);
return enhanced_bgr;
}
int main(int argc, char *argv[])
{
double sigma = std::stod(argv[1]);
double amount = std::stod(argv[2]);
double low = std::stod(argv[3]);
double high = std::stod(argv[4]);
int w = std::stoi(argv[5]);
cv::Mat bgr = cv::imread("flower.jpg");
cv::Mat enhanced = not_so_smart_sharpen(bgr, sigma, amount, low, high, w);
cv::imshow("original", bgr);
cv::imshow("enhanced", enhanced);
cv::waitKey(0);
return 0;
}
Other piece of code:
Code:
int main()
{
cv::Mat bgr = cv::imread("/home/supernova/Desktop/1tess2.jpg");
cv::Mat image;
cv::GaussianBlur(bgr, image, cv::Size(0, 0), 3);
cv::imshow("GaussianBlur", image);
cv::waitKey(100);
cv::addWeighted(bgr, 1.2, image, 0, 0.2, image);
cv::imshow("enhanced", image);
cv::waitKey(0);
cv::imwrite("/home/supernova/Desktop/1tessNew.jpg", image);
}
it does something, which is not relevant to what unsharpMask does, maybe I need to set some specific values?
if so, please advise what values I need to set