I am new to opencv and I am trying to perform unsharp masking ,however there some errors that that the resulting pixels can be <0 or >255 so they need to be scaled down.
src.at<uchar>(y,x) + (k * (float)(src.at<uchar>(y, x) - res.at<uchar>(y, x)))
can be greater than 255 and can be smaller than 0.
please explain some more. what exactly are you doing ? what is the purpose ?
can you try again with the formula ?
also, it’s unclear: do you want a saturated (clipped) result, or not ?
related: Unsharp Masking opencv c++ - Stack Overflow
please be more careful with copy-pasting. your paste here was broken.
Yes,exactly…to have the values in some range.
a) (k * (float)(src.at(y, x) - res.at(y, x))) can be negative,
b) src.at(y,x) + (k * (float)(src.at(y, x) - res.at(y, x))) can be greater than 255 and can be smaller than 0.
Performing a saturated add
I posted here earlier but I wouldnt post the whole code unfortunately,buts its there on stackoverflow